34 BGL_FORALL_VERTICES(v, circ.
dag,
DAG) {
36 OpType optype = op->get_type();
40 "Cannot currently do `pauli_gadgets` optimisation on a "
41 "circuit with conditional gates");
42 if (op->get_desc().is_box())
44 "Cannot currently do `pauli_gadgets` optimisation on a "
45 "circuit with boxes");
48 if (q_suc.size() != 1 ||
51 "Cannot currently do `pauli_gadgets` optimisation "
52 "on a circuit with a measure in the middle of the "
62 std::vector<SpSymPauliTensor> pauli_gadgets;
70 std::map<Qubit, SpPauliStabiliser> rx_pauli;
71 std::map<Qubit, SpPauliStabiliser> rz_pauli;
84 const Op_ptr op_ptr = c.get_op_ptr();
86 OpType type = op_ptr->get_type();
120 Qubit q_ctrl(args[0]);
121 Qubit q_trgt(args[1]);
122 rx_pauli[q_ctrl] = rx_pauli[q_ctrl] * rx_pauli[q_trgt];
123 rz_pauli[q_trgt] = rz_pauli[q_ctrl] * rz_pauli[q_trgt];
129 Expr angle = (op_ptr)->get_params()[0];
132 pauli_gadgets.push_back(g);
137 Expr angle = (op_ptr)->get_params()[0];
140 pauli_gadgets.push_back(g);
150 std::string error_gate =
151 "Cannot perform pairwise Pauli gadget optimisation using: " +
164 clifford_circ.
add_op(op_ptr, args);
170 while (g + 1 < pauli_gadgets.size()) {
177 if (g < pauli_gadgets.size()) {
181 circ = gadget_circ >> clifford_circ;
193 std::optional<std::string> name = circ.
get_name();
211 "PauliSynthStrat::Greedy is currently not supported. Try using "
212 "GreedyPauliSimp or a different PauliSynthStrat.");
215 TKET_ASSERT(!
"Unknown Pauli Synthesis Strategy");
230 std::list<Vertex> circbox_verts;
231 BGL_FORALL_VERTICES(v, circ.
dag,
DAG) {
233 circbox_verts.push_back(v);
235 for (
Vertex v : circbox_verts) {
237 std::shared_ptr<const CircBox> box_ptr =
238 std::dynamic_pointer_cast<const CircBox>(op);
239 Circuit inner_circ = *(box_ptr->to_circuit());
240 synther.
apply(inner_circ);
245 return !circbox_verts
Operation type not valid in the current context.
void set_name(const std::string _name)
Set the name of the circuit.
const Op_ptr get_Op_ptr_from_Vertex(const Vertex &vert) const
qubit_vector_t all_qubits() const
Subcircuit singleton_subcircuit(const Vertex &v) const
Construct a subcircuit consisting of a single vertex.
VertexVec get_successors_of_type(const Vertex &vert, EdgeType type) const
void add_bit(const Bit &id, bool reject_dups=true)
void append(const Circuit &c2)
bit_vector_t all_bits() const
void substitute(const Circuit &to_insert, const Subcircuit &to_replace, VertexDeletion vertex_deletion=VertexDeletion::Yes, OpGroupTransfer opgroup_transfer=OpGroupTransfer::Disallow)
Replace a subcircuit with a new circuit.
std::optional< std::string > get_name() const
Get the name of the circuit.
Vertex add_op(const Op_ptr &op, const std::vector< ID > &args, std::optional< std::string > opgroup=std::nullopt)
Append an operation to the circuit.
bool decompose_boxes_recursively(const std::unordered_set< OpType > &excluded_types={}, const std::unordered_set< std::string > &excluded_opgroups={}, const std::optional< std::unordered_set< OpType > > &included_types=std::nullopt, const std::optional< std::unordered_set< std::string > > &included_opgroups=std::nullopt)
Recursively replace each Box operation by applying Box::to_circuit.
void add_phase(Expr a)
Adds a global phase to the circuit.
Expr get_phase() const
Get the global phase offset as a multiple of pi (in the range [0,2)).
void add_qubit(const Qubit &id, bool reject_dups=true)
void replace_all_implicit_wire_swaps()
replaces all implicit wire swaps with SWAP gates
OpType get_OpType_from_Vertex(const Vertex &vert) const
Dependency graph of a circuit wrt Pauli Gadgets.
PauliTensor<PauliContainer, CoeffType>
Location holding a qubit.
Defines tket::DeviceCharacterisation, used in NoiseAwarePlacement and in commute_SQ_gates_through_SWA...
Circuit pauli_gadget(SpSymPauliTensor paulis, CXConfigType cx_config)
Construct a 'Pauli gadget' corresponding to a tensor of Pauli operators.
boost::graph_traits< DAG >::vertex_descriptor Vertex
OpType
Named operation types.
@ Measure
Measure a qubit, producing a classical output.
@ Collapse
Measure a qubit producing no output.
@ Reset
Reset a qubit to the zero state.
@ CX
Controlled OpType::X.
@ Conditional
See Conditional.
Circuit pauli_graph_to_pauli_exp_box_circuit_sets(const PauliGraph &pg, CXConfigType cx_config)
Synthesises a circuit equivalent to the PauliGraph by building sets of mutually commuting pauli gadge...
CXConfigType
Whenever a decomposition choice of Pauli gadgets is presented, users may use either Snake (a....
PauliTensor< QubitPauliMap, quarter_turns_t > SpPauliStabiliser
@ Quantum
A wire carrying quantum information, corresponding to some allocated Qubit.
PauliGraph circuit_to_pauli_graph(const Circuit &circ)
Circuit pauli_gadget_pair(SpSymPauliTensor paulis0, SpSymPauliTensor paulis1, CXConfigType cx_config)
Construct a circuit realising a pair of Pauli gadgets with the fewest two-qubit gates.
SymEngine::Expression Expr
Representation of a phase as a multiple of .
std::shared_ptr< const Op > Op_ptr
bool is_boundary_type(OpType optype)
Test for input, creation, output or discard "ops".
PauliTensor< QubitPauliMap, Expr > SpSymPauliTensor
std::vector< UnitID > unit_vector_t
Circuit pauli_graph_to_pauli_exp_box_circuit_pairwise(const PauliGraph &pg, CXConfigType cx_config)
Synthesises a circuit equivalent to the PauliGraph by inserting pairs of pauli gadgets as PauliExpPai...
bool is_boundary_q_type(OpType optype)
Test for input, creation, output or discard quantum "ops".
bool is_final_q_type(OpType optype)
Test for output or discard quantum "ops".
std::vector< Vertex > VertexVec
boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS, boost::property< boost::vertex_index_t, std::size_t, VertexProperties >, EdgeProperties > DAG
Graph representing a circuit, with operations as nodes.
Circuit pauli_graph_to_pauli_exp_box_circuit_individually(const PauliGraph &pg, CXConfigType cx_config)
Synthesises a circuit equivalent to the PauliGraph by adding each pauli gadget to the circuit as a Pa...
Structure to describe a convex region of the interaction graph.