tket
Loading...
Searching...
No Matches
PauliExpBoxes.hpp
Go to the documentation of this file.
1// Copyright Quantinuum
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include "Boxes.hpp"
20
21namespace tket {
22
23class PauliExpBoxInvalidity : public std::logic_error {
24 public:
25 explicit PauliExpBoxInvalidity(const std::string &message)
26 : std::logic_error(message) {}
27};
28
32class PauliExpBox : public Box {
33 public:
41 const SymPauliTensor &paulis,
42 CXConfigType cx_config_type = CXConfigType::Tree);
43
48
52 PauliExpBox(const PauliExpBox &other);
53
54 ~PauliExpBox() override = default;
55
56 bool is_clifford() const override;
57
58 SymSet free_symbols() const override;
59
63 bool is_equal(const Op &op_other) const override;
64
66 std::vector<Pauli> get_paulis() const { return paulis_.string; }
67
69 Expr get_phase() const { return paulis_.coeff; }
70
72 CXConfigType get_cx_config() const { return cx_config_; }
73
74 Op_ptr dagger() const override;
75
76 Op_ptr transpose() const override;
77
79 const SymEngine::map_basic_basic &sub_map) const override;
80
81 static Op_ptr from_json(const nlohmann::json &j);
82
83 static nlohmann::json to_json(const Op_ptr &op);
84
85 protected:
86 void generate_circuit() const override;
87
88 private:
89 SymPauliTensor paulis_;
90 CXConfigType cx_config_;
91};
92
93class PauliExpPairBox : public Box {
94 public:
96 const SymPauliTensor &paulis0, const SymPauliTensor &paulis1,
97 CXConfigType cx_config_type = CXConfigType::Tree);
98
103
107 PauliExpPairBox(const PauliExpPairBox &other);
108
109 ~PauliExpPairBox() override {}
110
111 bool is_clifford() const override;
112
113 SymSet free_symbols() const override;
114
118 bool is_equal(const Op &op_other) const override;
119
121 std::pair<std::vector<Pauli>, std::vector<Pauli>> get_paulis_pair() const {
122 return std::make_pair(paulis0_.string, paulis1_.string);
123 }
124
126 std::pair<Expr, Expr> get_phase_pair() const {
127 return std::make_pair(paulis0_.coeff, paulis1_.coeff);
128 }
129
131 CXConfigType get_cx_config() const { return cx_config_; }
132
133 Op_ptr dagger() const override;
134
135 Op_ptr transpose() const override;
136
138 const SymEngine::map_basic_basic &sub_map) const override;
139
140 static Op_ptr from_json(const nlohmann::json &j);
141
142 static nlohmann::json to_json(const Op_ptr &op);
143
144 protected:
145 void generate_circuit() const override;
146
147 private:
148 SymPauliTensor paulis0_;
149 SymPauliTensor paulis1_;
150 CXConfigType cx_config_;
151};
152
154 public:
156 const std::vector<SymPauliTensor> &pauli_gadgets,
157 CXConfigType cx_config_type = CXConfigType::Tree);
158
163
168
170
171 bool paulis_commute() const;
172
173 bool is_clifford() const override;
174
175 SymSet free_symbols() const override;
176
180 bool is_equal(const Op &op_other) const override;
181
183 auto get_pauli_gadgets() const { return pauli_gadgets_; }
184
186 auto get_cx_config() const { return cx_config_; }
187
188 Op_ptr dagger() const override;
189
190 Op_ptr transpose() const override;
191
193 const SymEngine::map_basic_basic &sub_map) const override;
194
195 static Op_ptr from_json(const nlohmann::json &j);
196
197 static nlohmann::json to_json(const Op_ptr &op);
198
199 protected:
200 void generate_circuit() const override;
201
202 private:
203 std::vector<SymPauliTensor> pauli_gadgets_;
204 CXConfigType cx_config_;
205};
206
207class TermSequenceBox : public Box {
208 public:
210 const std::vector<SymPauliTensor> &pauli_gadgets,
211 Transforms::PauliSynthStrat synth_strategy =
213 PauliPartitionStrat partition_strategy =
216 CXConfigType cx_configuration = CXConfigType::Tree,
217 double depth_weight = 0.3);
218
223
227 TermSequenceBox(const TermSequenceBox &other);
228
229 ~TermSequenceBox() override {}
230
231 bool is_clifford() const override;
232
233 SymSet free_symbols() const override;
234
238 bool is_equal(const Op &op_other) const override;
239
243
247
250
252 std::vector<SymPauliTensor> get_pauli_gadgets() const;
253
256
259 double get_depth_weight() const;
260
261 Op_ptr dagger() const override;
262
263 Op_ptr transpose() const override;
264
266 const SymEngine::map_basic_basic &sub_map) const override;
267
268 static Op_ptr from_json(const nlohmann::json &j);
269
270 static nlohmann::json to_json(const Op_ptr &op);
271
272 protected:
273 void generate_circuit() const override;
274
275 private:
276 std::vector<SymPauliTensor> pauli_gadgets_;
277 Transforms::PauliSynthStrat synth_strategy_;
278 PauliPartitionStrat partition_strategy_;
279 GraphColourMethod graph_colouring_;
280 CXConfigType cx_configuration_;
281 double depth_weight_;
282};
283
294 Circuit &circ, const SpSymPauliTensor &pauli, CXConfigType cx_config);
295
308 Circuit &circ, const SpSymPauliTensor &pauli0,
309 const SpSymPauliTensor &pauli1, CXConfigType cx_config);
310
323 Circuit &circ, const std::list<SpSymPauliTensor> &gadgets,
324 CXConfigType cx_config);
325
326} // namespace tket
Abstract class for an operation from which a circuit can be extracted.
Definition Boxes.hpp:38
Abstract class representing an operation type.
Definition Op.hpp:53
PauliExpBoxInvalidity(const std::string &message)
Operation defined as the exponential of a tensor of Pauli operators.
void generate_circuit() const override
PauliExpBox()
Construct from the empty vector.
Expr get_phase() const
Get the phase parameter.
CXConfigType get_cx_config() const
Get the cx_config parameter (affects box decomposition)
Op_ptr symbol_substitution(const SymEngine::map_basic_basic &sub_map) const override
Operation with values for symbols substituted.
Op_ptr transpose() const override
Transpose of a unitary operation.
bool is_clifford() const override
Test whether operation is in the Clifford group.
static Op_ptr from_json(const nlohmann::json &j)
bool is_equal(const Op &op_other) const override
Equality check between two PauliExpBox instances.
~PauliExpBox() override=default
SymSet free_symbols() const override
Set of all free symbols occurring in operation parameters.
std::vector< Pauli > get_paulis() const
Get the Pauli string.
Op_ptr dagger() const override
Inverse (of a unitary operation)
static nlohmann::json to_json(const Op_ptr &op)
Op_ptr transpose() const override
Transpose of a unitary operation.
SymSet free_symbols() const override
Set of all free symbols occurring in operation parameters.
static Op_ptr from_json(const nlohmann::json &j)
auto get_cx_config() const
Get the cx_config parameter (affects box decomposition)
bool is_equal(const Op &op_other) const override
Equality check between two instances.
PauliExpCommutingSetBox()
Construct from the empty vector.
static nlohmann::json to_json(const Op_ptr &op)
Op_ptr dagger() const override
Inverse (of a unitary operation)
bool is_clifford() const override
Test whether operation is in the Clifford group.
auto get_pauli_gadgets() const
Get the pauli gadgets.
void generate_circuit() const override
Op_ptr symbol_substitution(const SymEngine::map_basic_basic &sub_map) const override
Operation with values for symbols substituted.
std::pair< std::vector< Pauli >, std::vector< Pauli > > get_paulis_pair() const
Get Pauli strings for the pair.
bool is_clifford() const override
Test whether operation is in the Clifford group.
SymSet free_symbols() const override
Set of all free symbols occurring in operation parameters.
bool is_equal(const Op &op_other) const override
Equality check between two instances.
Op_ptr transpose() const override
Transpose of a unitary operation.
CXConfigType get_cx_config() const
Get the cx_config parameter (affects box decomposition)
Op_ptr dagger() const override
Inverse (of a unitary operation)
Op_ptr symbol_substitution(const SymEngine::map_basic_basic &sub_map) const override
Operation with values for symbols substituted.
static Op_ptr from_json(const nlohmann::json &j)
void generate_circuit() const override
static nlohmann::json to_json(const Op_ptr &op)
std::pair< Expr, Expr > get_phase_pair() const
Get phase parameters for the pair.
PauliExpPairBox()
Construct from the empty vector.
PauliContainer string
SymSet free_symbols() const override
Set of all free symbols occurring in operation parameters.
double get_depth_weight() const
Tuning parameter for depth optimisation, only applies to PauliPartitionStrat::Greedy.
Transforms::PauliSynthStrat get_synth_strategy() const
Get the circuit synthesis strategy parameter (affects box decomposition)
PauliPartitionStrat get_partition_strategy() const
Get the pauli partitioning strategy parameter (affects box decomposition)
void generate_circuit() const override
bool is_equal(const Op &op_other) const override
Equality check between two instances.
static Op_ptr from_json(const nlohmann::json &j)
GraphColourMethod get_graph_colouring() const
Get the graph colouring parameter (affects box decomposition)
Op_ptr dagger() const override
Inverse (of a unitary operation)
static nlohmann::json to_json(const Op_ptr &op)
std::vector< SymPauliTensor > get_pauli_gadgets() const
Get the pauli gadgets.
bool is_clifford() const override
Test whether operation is in the Clifford group.
TermSequenceBox()
Construct from the empty vector.
Op_ptr symbol_substitution(const SymEngine::map_basic_basic &sub_map) const override
Operation with values for symbols substituted.
Op_ptr transpose() const override
Transpose of a unitary operation.
CXConfigType get_cx_config() const
Get the cx config parameter (affects box decomposition)
STL namespace.
Defines tket::DeviceCharacterisation, used in NoiseAwarePlacement and in commute_SQ_gates_through_SWA...
Definition Path.cpp:22
void append_pauli_gadget_pair_as_box(Circuit &circ, const SpSymPauliTensor &pauli0, const SpSymPauliTensor &pauli1, CXConfigType cx_config)
Constructs a PauliExpPairBox for a pair of pauli gadgets and appends it to a circuit.
void append_single_pauli_gadget_as_pauli_exp_box(Circuit &circ, const SpSymPauliTensor &pauli, CXConfigType cx_config)
Constructs a PauliExpBox for a single pauli gadget and appends it to a circuit.
PauliPartitionStrat
A choice of strategies to partition Pauli tensors into sets.
@ CommutingSets
Sets of mutually commuting tensors; requires O(n^2) CXs for diagonalisation.
CXConfigType
Whenever a decomposition choice of Pauli gadgets is presented, users may use either Snake (a....
GraphColourMethod
A choice of methods to perform graph colouring for Pauli partitioning.
@ Lazy
Lazy: does not build the graph before performing the colouring; partitions while iterating through th...
void append_commuting_pauli_gadget_set_as_box(Circuit &circ, const std::list< SpSymPauliTensor > &gadgets, CXConfigType cx_config)
Constructs a PauliExpCommutingSetBox for a set of mutually commuting pauli gadgets and appends it to ...
SymEngine::Expression Expr
Representation of a phase as a multiple of .
std::shared_ptr< const Op > Op_ptr
Definition OpPtr.hpp:24
PauliTensor< QubitPauliMap, Expr > SpSymPauliTensor
std::set< Sym, SymCompareLess > SymSet