Skip to content

Commit 9c2ff11

Browse files
authored
[Format] Rename .clang_format to .clang-format to enable it (quantum-compiler#136)
* Add .clang-format * Restore some options * Restore some more options * code format * restore template option * adjust penalties * change include order and pack constructor settings * align escaped new lines * allow single-line templates * code format
1 parent 184810c commit 9c2ff11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+132
-137
lines changed

.clang_format .clang-format

+21-22
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@ AlignConsecutiveMacros: None
88
AlignConsecutiveAssignments: None
99
AlignConsecutiveBitFields: None
1010
AlignConsecutiveDeclarations: None
11-
AlignEscapedNewlines: Left
11+
AlignEscapedNewlines: Right
1212
AlignOperands: Align
1313
AlignTrailingComments: true
1414
AllowAllArgumentsOnNextLine: true
15+
AllowAllConstructorInitializersOnNextLine: true
1516
AllowAllParametersOfDeclarationOnNextLine: true
1617
AllowShortEnumsOnASingleLine: true
1718
AllowShortBlocksOnASingleLine: Never
1819
AllowShortCaseLabelsOnASingleLine: false
1920
AllowShortFunctionsOnASingleLine: All
2021
AllowShortLambdasOnASingleLine: All
21-
AllowShortIfStatementsOnASingleLine: WithoutElse
22-
AllowShortLoopsOnASingleLine: true
22+
AllowShortIfStatementsOnASingleLine: false
23+
AllowShortLoopsOnASingleLine: false
2324
AlwaysBreakAfterDefinitionReturnType: None
2425
AlwaysBreakAfterReturnType: None
25-
AlwaysBreakBeforeMultilineStrings: true
26-
AlwaysBreakTemplateDeclarations: Yes
26+
AlwaysBreakBeforeMultilineStrings: false
27+
AlwaysBreakTemplateDeclarations: MultiLine
2728
AttributeMacros:
2829
- __capability
2930
BinPackArguments: true
@@ -61,6 +62,7 @@ ColumnLimit: 80
6162
CommentPragmas: '^ IWYU pragma:'
6263
QualifierAlignment: Leave
6364
CompactNamespaces: false
65+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
6466
ConstructorInitializerIndentWidth: 4
6567
ContinuationIndentWidth: 4
6668
Cpp11BracedListStyle: true
@@ -70,44 +72,41 @@ DisableFormat: false
7072
EmptyLineAfterAccessModifier: Never
7173
EmptyLineBeforeAccessModifier: LogicalBlock
7274
ExperimentalAutoDetectBinPacking: false
73-
PackConstructorInitializers: NextLine
74-
BasedOnStyle: ''
75-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76-
AllowAllConstructorInitializersOnNextLine: true
7775
FixNamespaceComments: true
7876
ForEachMacros:
7977
- foreach
8078
- Q_FOREACH
8179
- BOOST_FOREACH
8280
IfMacros:
8381
- KJ_IF_MAYBE
84-
IncludeBlocks: Regroup
82+
IncludeBlocks: Preserve # Regroup
8583
IncludeCategories:
8684
- Regex: '^<ext/.*\.h>'
8785
Priority: 2
8886
SortPriority: 0
89-
CaseSensitive: false
87+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
88+
Priority: 2
89+
SortPriority: 0
90+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
91+
Priority: 3
92+
SortPriority: 0
9093
- Regex: '^<.*\.h>'
9194
Priority: 1
9295
SortPriority: 0
93-
CaseSensitive: false
9496
- Regex: '^<.*'
9597
Priority: 2
9698
SortPriority: 0
97-
CaseSensitive: false
9899
- Regex: '.*'
99100
Priority: 3
100101
SortPriority: 0
101-
CaseSensitive: false
102102
IncludeIsMainRegex: '([-_](test|unittest))?$'
103103
IncludeIsMainSourceRegex: ''
104104
IndentAccessModifiers: false
105-
IndentCaseLabels: true
105+
IndentCaseLabels: false
106106
IndentCaseBlocks: false
107107
IndentGotoLabels: true
108108
IndentPPDirectives: None
109109
IndentExternBlock: AfterExternBlock
110-
IndentRequires: false
111110
IndentWidth: 2
112111
IndentWrappedFunctionNames: false
113112
InsertTrailingCommas: None
@@ -124,18 +123,18 @@ ObjCBlockIndentWidth: 2
124123
ObjCBreakBeforeNestedBlockParam: true
125124
ObjCSpaceAfterProperty: false
126125
ObjCSpaceBeforeProtocolList: true
126+
PackConstructorInitializers: BinPack
127127
PenaltyBreakAssignment: 2
128-
PenaltyBreakBeforeFirstCallParameter: 1
128+
PenaltyBreakBeforeFirstCallParameter: 19
129129
PenaltyBreakComment: 300
130130
PenaltyBreakFirstLessLess: 120
131131
PenaltyBreakOpenParenthesis: 0
132132
PenaltyBreakString: 1000
133133
PenaltyBreakTemplateDeclaration: 10
134134
PenaltyExcessCharacter: 1000000
135-
PenaltyReturnTypeOnItsOwnLine: 200
136-
PenaltyIndentedWhitespace: 0
137-
PointerAlignment: Left
138-
PPIndentWidth: -1
135+
PenaltyReturnTypeOnItsOwnLine: 60
136+
PointerAlignment: Right
137+
PPIndentWidth: -1
139138
RawStringFormats:
140139
- Language: Cpp
141140
Delimiters:
@@ -195,7 +194,7 @@ SpaceAroundPointerQualifiers: Default
195194
SpaceBeforeRangeBasedForLoopColon: true
196195
SpaceInEmptyBlock: false
197196
SpaceInEmptyParentheses: false
198-
SpacesBeforeTrailingComments: 2
197+
SpacesBeforeTrailingComments: 1 # 2
199198
SpacesInAngles: Never
200199
SpacesInConditionalStatement: false
201200
SpacesInContainerLiterals: true

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ Makefile
4848
# Dataset
4949
*.json
5050

51-
# Clang format
52-
.clang-format
53-
5451
# Cython
5552
python/quartz/_cython/*.cpp
5653
python/build/*

src/benchmark/dp.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ int main() {
4141
}
4242
std::vector<int> num_local_qubits = {28};
4343
KernelCost kernel_cost(
44-
/*fusion_kernel_costs=*/{0, 6.4, 6.2, 6.5, 6.4, 6.4, 25.8, 32.4},
44+
/*fusion_kernel_costs=*/
45+
{0, 6.4, 6.2, 6.5, 6.4, 6.4, 25.8, 32.4},
4546
/*shared_memory_init_cost=*/6,
4647
/*shared_memory_gate_cost=*/
4748
[](quartz::GateType type) {

src/benchmark/nam_middle_circuits.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "quartz/parser/qasm_parser.h"
22
#include "quartz/tasograph/substitution.h"
33
#include "test/gen_ecc_set.h"
4+
45
#include <cmath>
56
#include <filesystem>
67
#include <sstream>

src/quartz/circuitseq/circuitgate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Context;
1515
* Stores the gate type, input and output information.
1616
*/
1717
class CircuitGate {
18-
public:
18+
public:
1919
// Get the minimum qubit index of the gate.
2020
[[nodiscard]] int get_min_qubit_index() const;
2121
// Get the qubit indices of the gate.

src/quartz/circuitseq/circuitseq.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,11 @@ CircuitSeqHashType CircuitSeq::hash(Context *ctx) {
722722
for (int i = 0; i < num_total_params; i++) {
723723
const auto &param = all_parameters[i];
724724
ComplexType shifted =
725-
dot_product * ComplexType{std::cos(param), std::sin(param)};
725+
dot_product * (ComplexType{std::cos(param), std::sin(param)});
726726
generate_hash_values(ctx, shifted, i, all_parameters, &tmp,
727727
&other_hash_values_);
728728
other_hash_values_.emplace_back(tmp, i);
729-
shifted = dot_product * ComplexType{std::cos(param), -std::sin(param)};
729+
shifted = dot_product * (ComplexType{std::cos(param), -std::sin(param)});
730730
generate_hash_values(ctx, shifted, i + num_total_params, all_parameters,
731731
&tmp, &other_hash_values_);
732732
other_hash_values_.emplace_back(tmp, i + num_total_params);
@@ -735,8 +735,8 @@ CircuitSeqHashType CircuitSeq::hash(Context *ctx) {
735735
// Check phase shift of pi/4, 2pi/4, ..., 7pi/4.
736736
for (int i = 1; i < 8; i++) {
737737
const double pi = std::acos(-1.0);
738-
ComplexType shifted = dot_product * ComplexType{std::cos(pi / 4 * i),
739-
std::sin(pi / 4 * i)};
738+
ComplexType shifted = dot_product * (ComplexType{std::cos(pi / 4 * i),
739+
std::sin(pi / 4 * i)});
740740
generate_hash_values(ctx, shifted, i, all_parameters, &tmp,
741741
&other_hash_values_);
742742
other_hash_values_.emplace_back(tmp,
@@ -1227,7 +1227,7 @@ bool CircuitSeq::canonical_representation(
12271227
}
12281228

12291229
class CompareByMinQubitIndex {
1230-
public:
1230+
public:
12311231
bool operator()(CircuitGate *gate1, CircuitGate *gate2) const {
12321232
// std::priority_queue maintains the largest element,
12331233
// so we use ">" to get the gate with minimum qubit index.

src/quartz/circuitseq/circuitseq.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace quartz {
1616
class Context;
1717

1818
class CircuitSeq {
19-
public:
19+
public:
2020
// TODO: Input parameters should be handled in Context instead of here
2121
CircuitSeq(int num_qubits, int num_input_parameters);
2222
CircuitSeq(const CircuitSeq &other); // clone a CircuitSeq
@@ -212,7 +212,7 @@ class CircuitSeq {
212212

213213
static bool same_gate(CircuitGate *gate1, CircuitGate *gate2);
214214

215-
private:
215+
private:
216216
void clone_from(const CircuitSeq &other,
217217
const std::vector<int> &qubit_permutation,
218218
const std::vector<int> &param_permutation);
@@ -243,13 +243,13 @@ class CircuitSeq {
243243
const std::vector<ParamType> &param_values, CircuitSeqHashType *main_hash,
244244
std::vector<std::pair<CircuitSeqHashType, PhaseShiftIdType>> *other_hash);
245245

246-
public:
246+
public:
247247
std::vector<std::unique_ptr<CircuitWire>> wires;
248248
std::vector<std::unique_ptr<CircuitGate>> gates;
249249
std::vector<CircuitWire *> outputs;
250250
std::vector<CircuitWire *> parameters;
251251

252-
private:
252+
private:
253253
int num_qubits, num_input_parameters;
254254
CircuitSeqHashType hash_value_;
255255
// For both floating-point error tolerance
@@ -271,7 +271,7 @@ class CircuitSeq {
271271
};
272272

273273
class UniquePtrCircuitSeqComparator {
274-
public:
274+
public:
275275
bool operator()(const std::unique_ptr<CircuitSeq> &seq1,
276276
const std::unique_ptr<CircuitSeq> &seq2) const {
277277
if (!seq1 || !seq2) {

src/quartz/circuitseq/circuitwire.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CircuitGate;
1111
* Can be a qubit or a parameter (see comment below).
1212
*/
1313
class CircuitWire {
14-
public:
14+
public:
1515
enum Type {
1616
internal_qubit,
1717
input_qubit,

src/quartz/context/context.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace quartz {
1515
class CircuitSeq;
1616

1717
class Context {
18-
public:
18+
public:
1919
explicit Context(const std::vector<GateType> &supported_gates);
2020
Context(const std::vector<GateType> &supported_gates, const int num_qubits,
2121
const int num_params);
@@ -62,7 +62,7 @@ class Context {
6262
// ranging [0, 1].
6363
double random_number();
6464

65-
private:
65+
private:
6666
bool insert_gate(GateType tp);
6767

6868
size_t global_unique_id;

src/quartz/context/rule_parser.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace quartz {
1414

1515
class Command {
16-
public:
16+
public:
1717
Command() {}
1818
Command(const Command &cmd) {
1919
tp = cmd.tp;
@@ -77,7 +77,7 @@ class Command {
7777
};
7878

7979
class RuleParser {
80-
public:
80+
public:
8181
RuleParser(std::vector<std::string> rules_) {
8282
for (auto rule : rules_) {
8383
std::string gate_name;
@@ -151,7 +151,7 @@ class RuleParser {
151151
return false;
152152
}
153153

154-
public:
154+
public:
155155
static std::pair<RuleParser *, RuleParser *> ccz_cx_rz_rules() {
156156
RuleParser *rule_0 =
157157
new RuleParser({"ccz q0 q1 q2 = cx q1 q2; rz q2 -0.25pi; cx q0 q2; rz "
@@ -194,7 +194,7 @@ class RuleParser {
194194
return std::make_pair(rule_0, rule_1);
195195
}
196196

197-
private:
197+
private:
198198
std::map<GateType,
199199
std::vector<std::pair<
200200
Command, std::pair<std::vector<Command>, std::set<GateType>>>>>

src/quartz/dataset/dataset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace quartz {
99

1010
class Dataset {
11-
public:
11+
public:
1212
bool save_json(Context *ctx, const std::string &file_name) const;
1313

1414
// Return the number of DAGs removed.

src/quartz/dataset/equivalence_set.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace quartz {
1515
class EquivalenceSet;
1616

1717
class EquivalenceClass {
18-
public:
18+
public:
1919
// Returns all DAGs in this equivalence class.
2020
[[nodiscard]] std::vector<CircuitSeq *> get_all_dags() const;
2121

@@ -68,12 +68,12 @@ class EquivalenceClass {
6868
static bool less_than(const EquivalenceClass &ecc1,
6969
const EquivalenceClass &ecc2);
7070

71-
private:
71+
private:
7272
std::vector<std::unique_ptr<CircuitSeq>> dags_;
7373
};
7474

7575
class UniquePtrEquivalenceClassComparator {
76-
public:
76+
public:
7777
bool operator()(const std::unique_ptr<EquivalenceClass> &ecc1,
7878
const std::unique_ptr<EquivalenceClass> &ecc2) const {
7979
if (!ecc1 || !ecc2) {
@@ -86,7 +86,7 @@ class UniquePtrEquivalenceClassComparator {
8686

8787
// This class stores all equivalence classes.
8888
class EquivalenceSet {
89-
public:
89+
public:
9090
// |new_representatives| is for Generator::generate().
9191
// It will be pushed back all representatives previously not in
9292
// the equivalence set.
@@ -180,7 +180,7 @@ class EquivalenceSet {
180180
[[nodiscard]] std::vector<EquivalenceClass *>
181181
get_containing_class(Context *ctx, CircuitSeq *dag) const;
182182

183-
private:
183+
private:
184184
void set_possible_class(const CircuitSeqHashType &hash_value,
185185
EquivalenceClass *equiv_class);
186186
void remove_possible_class(const CircuitSeqHashType &hash_value,

src/quartz/dataset/representative_set.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace quartz {
77

88
class RepresentativeSet {
9-
public:
9+
public:
1010
bool load_json(Context *ctx, const std::string &file_name);
1111

1212
bool save_json(const std::string &file_name) const;
@@ -31,7 +31,7 @@ class RepresentativeSet {
3131
// Sort the circuits in this equivalence class by CircuitSeq::less_than().
3232
void sort();
3333

34-
private:
34+
private:
3535
std::vector<std::unique_ptr<CircuitSeq>> dags_;
3636
};
3737

src/quartz/gate/add.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace quartz {
88
class AddGate : public Gate {
9-
public:
9+
public:
1010
AddGate() : Gate(GateType::add, 0 /*num_qubits*/, 2 /*num_parameters*/) {}
1111
ParamType compute(const std::vector<ParamType> &input_params) override {
1212
assert(input_params.size() == 2);

src/quartz/gate/ccx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace quartz {
88
class CCXGate : public Gate {
9-
public:
9+
public:
1010
CCXGate()
1111
: Gate(GateType::ccx, 3 /*num_qubits*/, 0 /*num_parameters*/),
1212
mat({{1, 0, 0, 0, 0, 0, 0, 0},

src/quartz/gate/ccz.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace quartz {
88
class CCZGate : public Gate {
9-
public:
9+
public:
1010
CCZGate()
1111
: Gate(GateType::ccz, 3 /*num_qubits*/, 0 /*num_parameters*/),
1212
mat({{1, 0, 0, 0, 0, 0, 0, 0},

0 commit comments

Comments
 (0)