@@ -25,7 +25,7 @@ bool equal_to_2k_pi(double d);
2525
2626class Op {
2727 public:
28- Op (void );
28+ Op ();
2929 Op (size_t _guid, Gate *_ptr) : guid(_guid), ptr(_ptr) {}
3030 inline bool operator ==(const Op &b) const {
3131 if (guid != b.guid )
@@ -146,13 +146,13 @@ class PosCompare {
146146
147147class Tensor {
148148 public:
149- Tensor (void );
149+ Tensor ();
150150 int idx;
151151 Op op;
152152};
153153
154154struct Edge {
155- Edge (void );
155+ Edge ();
156156 Edge (const Op &_srcOp, const Op &_dstOp, int _srcIdx, int _dstIdx);
157157 Op srcOp, dstOp;
158158 int srcIdx, dstIdx;
@@ -177,21 +177,22 @@ class OpX;
177177
178178class Graph {
179179 public:
180- Graph (Context *ctx);
180+ explicit Graph (Context *ctx);
181181 Graph (Context *ctx, const CircuitSeq *seq);
182182 Graph (const Graph &graph);
183183 [[nodiscard]] std::unique_ptr<CircuitSeq> to_circuit_sequence () const ;
184184 void _construct_pos_2_logical_qubit ();
185185 void add_edge (const Op &srcOp, const Op &dstOp, int srcIdx, int dstIdx);
186- bool has_edge (const Op &srcOp, const Op &dstOp, int srcIdx, int dstIdx) const ;
186+ [[nodiscard]] bool has_edge (const Op &srcOp, const Op &dstOp, int srcIdx,
187+ int dstIdx) const ;
187188 Op add_qubit (int qubit_idx);
188- Op add_parameter (const ParamType p);
189+ Op add_parameter (const ParamType & p);
189190 Op new_gate (GateType gt);
190- bool has_loop () const ;
191+ [[nodiscard]] bool has_loop () const ;
191192 size_t hash ();
192- bool equal (const Graph &other) const ;
193+ [[nodiscard]] bool equal (const Graph &other) const ;
193194 bool check_correctness ();
194- int specific_gate_count (GateType gate_type) const ;
195+ [[nodiscard]] int specific_gate_count (GateType gate_type) const ;
195196 [[nodiscard]] float total_cost () const ;
196197 [[nodiscard]] int gate_count () const ;
197198 [[nodiscard]] int circuit_depth () const ;
@@ -273,7 +274,8 @@ class Graph {
273274 bool continue_storing_all_steps = false);
274275 void constant_and_rotation_elimination ();
275276 void rotation_merging (GateType target_rotation);
276- std::string to_qasm (bool print_result = false , bool print_guid = false ) const ;
277+ [[nodiscard]] std::string to_qasm (bool print_result = false ,
278+ bool print_guid = false ) const ;
277279 void to_qasm (const std::string &save_filename, bool print_result,
278280 bool print_guid) const ;
279281 template <class _CharT , class _Traits >
@@ -283,10 +285,10 @@ class Graph {
283285 static std::shared_ptr<Graph> from_qasm_file (Context *ctx,
284286 const std::string &filename);
285287 static std::shared_ptr<Graph> from_qasm_str (Context *ctx,
286- const std::string qasm_str);
288+ const std::string & qasm_str);
287289 void draw_circuit (const std::string &qasm_str,
288290 const std::string &save_filename);
289- size_t get_num_qubits () const ;
291+ [[nodiscard]] size_t get_num_qubits () const ;
290292 void print_qubit_ops ();
291293 std::shared_ptr<Graph> toffoli_flip_greedy (GateType target_rotation,
292294 GraphXfer *xfer,
@@ -298,9 +300,9 @@ class Graph {
298300 toffoli_flip_by_instruction (GateType target_rotation, GraphXfer *xfer,
299301 GraphXfer *inverse_xfer,
300302 std::vector<int > instruction);
301- std::vector<size_t > appliable_xfers (Op op,
302- const std::vector<GraphXfer *> &) const ;
303- std::vector<size_t >
303+ [[nodiscard]] std::vector<size_t >
304+ appliable_xfers (Op op, const std::vector<GraphXfer *> &) const ;
305+ [[nodiscard]] std::vector<size_t >
304306 appliable_xfers_parallel (Op op, const std::vector<GraphXfer *> &) const ;
305307 bool xfer_appliable (GraphXfer *xfer, Op op) const ;
306308 std::shared_ptr<Graph> apply_xfer (GraphXfer *xfer, Op op,
@@ -318,16 +320,16 @@ class Graph {
318320 std::shared_ptr<Graph> ccz_flip_greedy_rz ();
319321 std::shared_ptr<Graph> ccz_flip_greedy_u1 ();
320322 bool _loop_check_after_matching (GraphXfer *xfer) const ;
321- std::shared_ptr<Graph>
323+ [[nodiscard]] std::shared_ptr<Graph>
322324 subgraph (const std::unordered_set<Op, OpHash> &ops) const ;
323- std::vector<std::shared_ptr<Graph>>
325+ [[nodiscard]] std::vector<std::shared_ptr<Graph>>
324326 topology_partition (const int partition_gate_count) const ;
325327 /* *
326328 * Return the parameter value if the Op is a constant parameter,
327329 * or return 0 otherwise.
328330 */
329- ParamType get_param_value (const Op &op) const ;
330- bool param_has_value (const Op &op) const ;
331+ [[nodiscard]] ParamType get_param_value (const Op &op) const ;
332+ [[nodiscard]] bool param_has_value (const Op &op) const ;
331333
332334 private:
333335 void replace_node (Op oldOp, Op newOp);
@@ -344,11 +346,23 @@ class Graph {
344346 bool moveable (GateType tp);
345347 bool move_forward (Pos &pos, bool left);
346348 bool merge_2_rotation_op (Op op_0, Op op_1);
347- // The common core part of the API xfer_appliable, apply_xfer, and
348- // apply_xfer_and_track_node. Matches the src dag of xfer to the local dag
349- // in the circuit whose topological-order root is op. If failed, it
350- // automatically unmaps the matched nodes. Otherwise, the caller should
351- // unmap the matched nodes after their work is done.
349+ /* *
350+ * The common core part of the API xfer_applicable, apply_xfer, and
351+ * apply_xfer_and_track_node. Matches the src dag of xfer to the local dag
352+ * in the circuit whose topological-order root is op. If failed, it
353+ * automatically unmaps the matched nodes. Otherwise, the caller should
354+ * unmap the matched nodes after their work is done.
355+ * Because the src dag is connected, this function traverses the src dag
356+ * and try to match the local dag in a connected way (not necessarily in
357+ * topological order). For example, the pattern H(q0) H(q1) CX(q0, q1)
358+ * may be matched in the order
359+ * H(q0) (match qubit 0) -> CX(q0, q1) (match qubit 1) <- H(q1).
360+ * @param xfer The xfer with a src dag and a target dag.
361+ * @param op The node to begin with in the local dag.
362+ * @param matched_opx_op_pairs_dq A deque to store matched nodes from
363+ * the src dag to the local dag.
364+ * @return If the match is successful.
365+ */
352366 bool _pattern_matching (
353367 GraphXfer *xfer, Op op,
354368 std::deque<std::pair<OpX *, Op>> &matched_opx_op_pairs_dq) const ;
0 commit comments