Skip to content

Commit 4579b9d

Browse files
authored
[format] Add a space before trailing comments (quantum-compiler#138)
* [format] Add a space before trailing comments * format
1 parent 97fff96 commit 4579b9d

Some content is hidden

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

87 files changed

+185
-184
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ SpaceAroundPointerQualifiers: Default
194194
SpaceBeforeRangeBasedForLoopColon: true
195195
SpaceInEmptyBlock: false
196196
SpaceInEmptyParentheses: false
197-
SpacesBeforeTrailingComments: 1 # 2
197+
SpacesBeforeTrailingComments: 2
198198
SpacesInAngles: Never
199199
SpacesInConditionalStatement: false
200200
SpacesInContainerLiterals: true

src/benchmark/nam_middle_circuits.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ int main() {
9898
std::cout << "ECC set generated." << std::endl;
9999
}
100100
// Logs are printed to Nam_6_3_barenco_tof_10.log, Nam_6_3_gf2^8_mult.log, ...
101-
benchmark_nam("barenco_tof_10"); // 450 gates
102-
benchmark_nam("gf2^8_mult"); // 883 gates
103-
benchmark_nam("qcla_mod_7"); // 884 gates
104-
benchmark_nam("adder_8"); // 900 gates
101+
benchmark_nam("barenco_tof_10"); // 450 gates
102+
benchmark_nam("gf2^8_mult"); // 883 gates
103+
benchmark_nam("qcla_mod_7"); // 884 gates
104+
benchmark_nam("adder_8"); // 900 gates
105105
if (num_benchmark > 0) {
106106
std::cout << "Summary:" << std::endl;
107107
std::cout << summary_result.str();

src/benchmark/nam_small_circuits.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ int main() {
9898
std::cout << "ECC set generated." << std::endl;
9999
}
100100
// Logs are printed to Nam_4_3_tof_3.log, Nam_4_3_barenco_tof_3.log, ...
101-
benchmark_nam("tof_3"); // 45 gates
102-
benchmark_nam("barenco_tof_3"); // 58 gates
103-
benchmark_nam("mod_mult_55"); // 119 gates
104-
benchmark_nam("vbe_adder_3"); // 150 gates
105-
benchmark_nam("gf2^4_mult"); // 225 gates
101+
benchmark_nam("tof_3"); // 45 gates
102+
benchmark_nam("barenco_tof_3"); // 58 gates
103+
benchmark_nam("mod_mult_55"); // 119 gates
104+
benchmark_nam("vbe_adder_3"); // 150 gates
105+
benchmark_nam("gf2^4_mult"); // 225 gates
106106
if (num_benchmark > 0) {
107107
std::cout << "Summary:" << std::endl;
108108
std::cout << summary_result.str();

src/quartz/circuitseq/circuitgate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,4 @@ std::string CircuitGate::to_qasm_style_string(Context *ctx,
230230
return result;
231231
}
232232

233-
} // namespace quartz
233+
} // namespace quartz

src/quartz/circuitseq/circuitgate.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class CircuitGate {
2929
[[nodiscard]] std::string to_string() const;
3030
[[nodiscard]] std::string to_qasm_style_string(Context *ctx,
3131
int param_precision) const;
32-
std::vector<CircuitWire *> input_wires; // Include parameters!
32+
std::vector<CircuitWire *> input_wires; // Include parameters!
3333
std::vector<CircuitWire *> output_wires;
3434

3535
Gate *gate;
3636
};
37-
} // namespace quartz
37+
} // namespace quartz

src/quartz/circuitseq/circuitseq.cpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ bool CircuitSeq::less_than(const CircuitSeq &other) const {
140140
}
141141
}
142142
}
143-
return false; // fully equivalent
143+
return false; // fully equivalent
144144
}
145145

146146
bool CircuitSeq::add_gate(const std::vector<int> &qubit_indices,
@@ -186,7 +186,7 @@ bool CircuitSeq::add_gate(const std::vector<int> &qubit_indices,
186186
wire->index = qubit_idx;
187187
wire->input_gates.push_back(circuit_gate.get());
188188
circuit_gate->output_wires.push_back(wire.get());
189-
outputs[qubit_idx] = wire.get(); // Update outputs
189+
outputs[qubit_idx] = wire.get(); // Update outputs
190190
wires.push_back(std::move(wire));
191191
}
192192
}
@@ -253,7 +253,7 @@ bool CircuitSeq::insert_gate(int insert_position,
253253
wire->input_gates.push_back(circuit_gate.get());
254254
circuit_gate->output_wires.push_back(wire.get());
255255
if (outputs[qubit_idx] == previous_wires[qubit_idx]) {
256-
outputs[qubit_idx] = wire.get(); // Update outputs
256+
outputs[qubit_idx] = wire.get(); // Update outputs
257257
} else {
258258
for (auto &output_gate : previous_wires[qubit_idx]->output_gates) {
259259
// Should have exactly one |output_gate|
@@ -473,7 +473,7 @@ int CircuitSeq::remove_first_quantum_gate() {
473473
return remove_gate(circuit_gate.get());
474474
}
475475
}
476-
return 0; // nothing removed
476+
return 0; // nothing removed
477477
}
478478

479479
int CircuitSeq::remove_swap_gates() {
@@ -943,7 +943,7 @@ std::string CircuitSeq::to_string(bool line_number) const {
943943
const int num_gates = (int)gates.size();
944944
for (int i = 0; i < num_gates; i++) {
945945
if (line_number) {
946-
char buffer[20]; // enough to store any int
946+
char buffer[20]; // enough to store any int
947947
int max_line_number_width =
948948
std::max(1, (int)std::ceil(std::log10(num_gates - 0.01)));
949949
sprintf(buffer, "%*d", max_line_number_width, i);
@@ -1124,7 +1124,7 @@ std::unique_ptr<CircuitSeq> CircuitSeq::read_json(Context *ctx,
11241124
assert(ch == 'P' || ch == 'Q');
11251125
int index;
11261126
fin >> index;
1127-
fin.ignore(); // '\"'
1127+
fin.ignore(); // '\"'
11281128
if (ch == 'Q') {
11291129
qubit_indices.push_back(index);
11301130
} else {
@@ -1154,7 +1154,7 @@ CircuitSeq::from_qasm_file(Context *ctx, const std::string &filename) {
11541154
CircuitSeq *seq = nullptr;
11551155
parser.load_qasm(filename, seq);
11561156
std::unique_ptr<CircuitSeq> ret;
1157-
ret.reset(seq); // transfer ownership of |seq|
1157+
ret.reset(seq); // transfer ownership of |seq|
11581158
return ret;
11591159
}
11601160

@@ -1463,7 +1463,7 @@ void CircuitSeq::clone_from(const CircuitSeq &other,
14631463
for (int i = 0; i < (int)other.wires.size(); i++) {
14641464
wires.emplace_back(std::make_unique<CircuitWire>(*(other.wires[i])));
14651465
assert(wires[i].get() !=
1466-
other.wires[i].get()); // make sure we make a copy
1466+
other.wires[i].get()); // make sure we make a copy
14671467
wires_mapping[other.wires[i].get()] = wires[i].get();
14681468
}
14691469
} else {
@@ -1475,7 +1475,8 @@ void CircuitSeq::clone_from(const CircuitSeq &other,
14751475
assert(qubit_permutation[i] >= 0 && qubit_permutation[i] < num_qubits);
14761476
wires[qubit_permutation[i]] =
14771477
std::make_unique<CircuitWire>(*(other.wires[i]));
1478-
wires[qubit_permutation[i]]->index = qubit_permutation[i]; // update index
1478+
wires[qubit_permutation[i]]->index =
1479+
qubit_permutation[i]; // update index
14791480
assert(wires[qubit_permutation[i]].get() != other.wires[i].get());
14801481
wires_mapping[other.wires[i].get()] = wires[qubit_permutation[i]].get();
14811482
}
@@ -1488,7 +1489,7 @@ void CircuitSeq::clone_from(const CircuitSeq &other,
14881489
wires[num_qubits + param_permutation[i_inc]] =
14891490
std::make_unique<CircuitWire>(*(other.wires[i]));
14901491
wires[num_qubits + param_permutation[i_inc]]->index =
1491-
param_permutation[i_inc]; // update index
1492+
param_permutation[i_inc]; // update index
14921493
assert(wires[num_qubits + param_permutation[i_inc]].get() !=
14931494
other.wires[i].get());
14941495
wires_mapping[other.wires[i].get()] =
@@ -1498,7 +1499,7 @@ void CircuitSeq::clone_from(const CircuitSeq &other,
14981499
i < (int)other.wires.size(); i++) {
14991500
wires[i] = std::make_unique<CircuitWire>(*(other.wires[i]));
15001501
if (wires[i]->is_qubit()) {
1501-
wires[i]->index = qubit_permutation[wires[i]->index]; // update index
1502+
wires[i]->index = qubit_permutation[wires[i]->index]; // update index
15021503
}
15031504
assert(wires[i].get() != other.wires[i].get());
15041505
wires_mapping[other.wires[i].get()] = wires[i].get();
@@ -1687,4 +1688,4 @@ bool CircuitSeq::same_gate(CircuitGate *gate1, CircuitGate *gate2) {
16871688
return true;
16881689
}
16891690

1690-
} // namespace quartz
1691+
} // namespace quartz

src/quartz/circuitseq/circuitseq.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CircuitSeq {
1919
public:
2020
// TODO: Input parameters should be handled in Context instead of here
2121
CircuitSeq(int num_qubits, int num_input_parameters);
22-
CircuitSeq(const CircuitSeq &other); // clone a CircuitSeq
22+
CircuitSeq(const CircuitSeq &other); // clone a CircuitSeq
2323
[[nodiscard]] std::unique_ptr<CircuitSeq> clone() const;
2424
[[nodiscard]] bool fully_equivalent(const CircuitSeq &other) const;
2525
[[nodiscard]] bool fully_equivalent(Context *ctx, CircuitSeq &other);
@@ -281,4 +281,4 @@ class UniquePtrCircuitSeqComparator {
281281
return seq1->less_than(*seq2);
282282
}
283283
};
284-
} // namespace quartz
284+
} // namespace quartz

src/quartz/circuitseq/circuitwire.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ std::string CircuitWire::to_string() const {
1717
}
1818
}
1919

20-
} // namespace quartz
20+
} // namespace quartz

src/quartz/circuitseq/circuitwire.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ class CircuitWire {
3434
std::vector<CircuitGate *> output_gates;
3535
};
3636

37-
} // namespace quartz
37+
} // namespace quartz

src/quartz/context/context.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ Context union_contexts(Context *ctx_0, Context *ctx_1) {
270270
return Context(union_vector);
271271
}
272272

273-
} // namespace quartz
273+
} // namespace quartz

src/quartz/context/context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ class Context {
9393
// TODO: This function does not consider the parameters
9494
Context union_contexts(Context *ctx_0, Context *ctx_1);
9595

96-
} // namespace quartz
96+
} // namespace quartz

src/quartz/context/rule_parser.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ class RuleParser {
202202
rules;
203203
};
204204

205-
} // namespace quartz
205+
} // namespace quartz

src/quartz/dataset/dataset.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int Dataset::remove_singletons(Context *ctx) {
8484
found_possible_equivalence = true;
8585
break;
8686
}
87-
assert(hash_value == it_hash_value + 1); // Only deal with this case...
87+
assert(hash_value == it_hash_value + 1); // Only deal with this case...
8888
}
8989
// ...so that we know for sure that only DAGs with hash value equal
9090
// to |it_hash_value - 1| can have other_hash_values() containing
@@ -133,7 +133,7 @@ int Dataset::normalize_to_canonical_representations(Context *ctx) {
133133
if (!dag_already_exists(*new_dag, new_dags)) {
134134
new_dags.push_back(std::move(new_dag));
135135
}
136-
dag = nullptr; // delete the original CircuitSeq
136+
dag = nullptr; // delete the original CircuitSeq
137137
}
138138
}
139139
if (!new_dags.empty()) {
@@ -166,7 +166,7 @@ int Dataset::normalize_to_canonical_representations(Context *ctx) {
166166
for (auto &dag : dags_to_insert_afterwards) {
167167
const auto hash_value = dag->hash(ctx);
168168
if (!dag_already_exists(*dag, dataset[hash_value])) {
169-
num_removed--; // Insert |circuitseq| back.
169+
num_removed--; // Insert |circuitseq| back.
170170
dataset[hash_value].push_back(std::move(dag));
171171
}
172172
}
@@ -203,4 +203,4 @@ void Dataset::clear() {
203203
std::vector<std::unique_ptr<CircuitSeq>>>();
204204
}
205205

206-
} // namespace quartz
206+
} // namespace quartz

src/quartz/dataset/dataset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ class Dataset {
4141
std::vector<std::unique_ptr<CircuitSeq>>>
4242
dataset;
4343
};
44-
} // namespace quartz
44+
} // namespace quartz

src/quartz/dataset/equivalence_set.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ CircuitSeqHashType EquivalenceClass::hash(Context *ctx) {
162162
return dag->hash(ctx);
163163
}
164164
}
165-
return 0; // empty class
165+
return 0; // empty class
166166
}
167167

168168
void EquivalenceClass::sort() {
@@ -239,14 +239,14 @@ bool EquivalenceSet::load_json(Context *ctx, const std::string &file_name,
239239
// the tags
240240
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\"');
241241
fin >> std::hex >> hash_value;
242-
fin.ignore(); // '_'
242+
fin.ignore(); // '_'
243243
fin >> std::dec >> id;
244244
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\"');
245245
EquivClassTag class1 = std::make_pair(hash_value, id);
246246

247247
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\"');
248248
fin >> std::hex >> hash_value;
249-
fin.ignore(); // '_'
249+
fin.ignore(); // '_'
250250
fin >> std::dec >> id;
251251
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\"');
252252
EquivClassTag class2 = std::make_pair(hash_value, id);
@@ -304,7 +304,7 @@ bool EquivalenceSet::load_json(Context *ctx, const std::string &file_name,
304304
// the tag
305305
CircuitSeqHashType hash_value;
306306
fin >> std::hex >> hash_value;
307-
fin.ignore(); // '_'
307+
fin.ignore(); // '_'
308308
int id;
309309
fin >> std::dec >> id;
310310
EquivClassTag class_tag = std::make_pair(hash_value, id);
@@ -335,7 +335,7 @@ bool EquivalenceSet::load_json(Context *ctx, const std::string &file_name,
335335
}
336336

337337
// New CircuitSeq
338-
fin.unget(); // '['
338+
fin.unget(); // '['
339339
auto dag = CircuitSeq::read_json(ctx, fin);
340340
auto dag_hash_value = dag->hash(ctx);
341341
// Due to floating point errors and for compatibility of
@@ -579,7 +579,7 @@ int EquivalenceSet::normalize_to_canonical_representations(Context *ctx,
579579
for (const auto &other_hash : dag->other_hash_values()) {
580580
hash_values_to_remove.insert(other_hash);
581581
}
582-
dag = nullptr; // delete the CircuitSeq
582+
dag = nullptr; // delete the CircuitSeq
583583
}
584584
}
585585
if (!class_modified) {
@@ -594,7 +594,7 @@ int EquivalenceSet::normalize_to_canonical_representations(Context *ctx,
594594
std::unordered_set<CircuitSeqHashType> existing_hash_values;
595595
std::unordered_set<CircuitSeqHashType> hash_values_to_insert;
596596
num_class_modified++;
597-
item->set_dags({}); // insert the DAGs one by one
597+
item->set_dags({}); // insert the DAGs one by one
598598
for (auto &dag : dags) {
599599
if (dag) {
600600
existing_hash_values.insert(dag->hash(ctx));
@@ -777,7 +777,7 @@ int EquivalenceSet::remove_unused_qubits_and_input_params(Context *ctx,
777777
if (already_exist) {
778778
// Remove the new class.
779779
classes_to_insert.pop_back();
780-
keep_dag_class = false; // unused
780+
keep_dag_class = false; // unused
781781
} else {
782782
// Add pointers to the new class.
783783
for (auto &dag : new_dag_class->get_all_dags()) {
@@ -1136,7 +1136,7 @@ int EquivalenceSet::first_class_with_common_first_or_last_gates() const {
11361136
}
11371137
class_id++;
11381138
}
1139-
return -1; // no common first or last gates found
1139+
return -1; // no common first or last gates found
11401140
}
11411141

11421142
std::string EquivalenceSet::get_class_id(int num_class) const {
@@ -1225,4 +1225,4 @@ void EquivalenceSet::remove_possible_class(const CircuitSeqHashType &hash_value,
12251225
possible_classes.erase(equiv_class);
12261226
}
12271227

1228-
} // namespace quartz
1228+
} // namespace quartz

src/quartz/dataset/equivalence_set.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,4 @@ class EquivalenceSet {
194194
possible_classes_;
195195
};
196196

197-
} // namespace quartz
197+
} // namespace quartz

src/quartz/dataset/representative_set.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool RepresentativeSet::load_json(Context *ctx, const std::string &file_name) {
2727
}
2828

2929
// New CircuitSeq
30-
fin.unget(); // '['
30+
fin.unget(); // '['
3131
auto dag = CircuitSeq::read_json(ctx, fin);
3232
dags_.emplace_back(std::move(dag));
3333
}
@@ -90,4 +90,4 @@ void RepresentativeSet::sort() {
9090
std::sort(dags_.begin(), dags_.end(), UniquePtrCircuitSeqComparator());
9191
}
9292

93-
} // namespace quartz
93+
} // namespace quartz

src/quartz/dataset/representative_set.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ class RepresentativeSet {
3535
std::vector<std::unique_ptr<CircuitSeq>> dags_;
3636
};
3737

38-
} // namespace quartz
38+
} // namespace quartz

src/quartz/gate/add.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ class AddGate : public Gate {
1616
bool is_commutative() const override { return true; }
1717
};
1818

19-
} // namespace quartz
19+
} // namespace quartz

src/quartz/gate/ccx.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class CCXGate : public Gate {
2424
Matrix<8> mat;
2525
};
2626

27-
} // namespace quartz
27+
} // namespace quartz

src/quartz/gate/ccz.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ class CCZGate : public Gate {
2626
Matrix<8> mat;
2727
};
2828

29-
} // namespace quartz
29+
} // namespace quartz

src/quartz/gate/ch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class CHGate : public Gate {
1919
Matrix<4> mat;
2020
};
2121

22-
} // namespace quartz
22+
} // namespace quartz

src/quartz/gate/cp.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ class CPGate : public Gate {
2929
std::unordered_map<float, std::unique_ptr<Matrix<4>>> cached_matrices;
3030
};
3131

32-
} // namespace quartz
32+
} // namespace quartz

src/quartz/gate/cu1.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ class CU1Gate : public Gate {
2828
std::unordered_map<ParamType, std::unique_ptr<Matrix<4>>> cached_matrices;
2929
};
3030

31-
} // namespace quartz
31+
} // namespace quartz

0 commit comments

Comments
 (0)