17 Eigen::MatrixXcd
generic;
22 if (
kind != Kind::kNone && order.size() > 1 &&
kind != Kind::kSwapGateType)
23 std::reverse(order.begin(), order.end());
37 case Kind::kPhaseGateType:
39 case Kind::kXGateType:
41 case Kind::kYGateType:
43 case Kind::kZGateType:
45 case Kind::kHadamardGateType:
47 case Kind::kSGateType:
49 case Kind::kSdgGateType:
51 case Kind::kTGateType:
53 case Kind::kTdgGateType:
55 case Kind::kSxGateType:
57 case Kind::kSxDagGateType:
59 case Kind::kKGateType:
61 case Kind::kRxGateType:
63 case Kind::kRyGateType:
65 case Kind::kRzGateType:
67 case Kind::kUGateType:
69 case Kind::kSwapGateType:
71 case Kind::kCXGateType:
73 case Kind::kCYGateType:
75 case Kind::kCZGateType:
77 case Kind::kCPGateType:
79 case Kind::kCRxGateType:
81 case Kind::kCRyGateType:
83 case Kind::kCRzGateType:
85 case Kind::kCHGateType:
87 case Kind::kCSxGateType:
89 case Kind::kCSxDagGateType:
91 case Kind::kCUGateType:
93 case Kind::kCSwapGateType:
95 case Kind::kCCXGateType:
98 throw std::logic_error(
"Unknown fusion gate");
116 if (result.
kind == Kind::kNone)
121 std::copy_n(p.begin(), std::min(p.size(), result.
params.size()), result.
params.begin());
128 (
kind != Kind::kNone ||
136 case Kind::kPhaseGateType:
137 case Kind::kXGateType:
138 case Kind::kYGateType:
139 case Kind::kZGateType:
140 case Kind::kSGateType:
141 case Kind::kSdgGateType:
142 case Kind::kTGateType:
143 case Kind::kTdgGateType:
144 case Kind::kRzGateType:
145 case Kind::kSwapGateType:
146 case Kind::kCXGateType:
147 case Kind::kCYGateType:
148 case Kind::kCZGateType:
149 case Kind::kCPGateType:
150 case Kind::kCRzGateType:
151 case Kind::kCSwapGateType:
152 case Kind::kCCXGateType:
165 case Kind::kPhaseGateType:
168 case Kind::kXGateType:
171 case Kind::kYGateType:
174 case Kind::kZGateType:
177 case Kind::kHadamardGateType:
180 case Kind::kSGateType:
183 case Kind::kSdgGateType:
186 case Kind::kTGateType:
189 case Kind::kTdgGateType:
192 case Kind::kSxGateType:
195 case Kind::kSxDagGateType:
198 case Kind::kKGateType:
201 case Kind::kRxGateType:
204 case Kind::kRyGateType:
207 case Kind::kRzGateType:
210 case Kind::kUGateType:
213 case Kind::kSwapGateType:
216 case Kind::kCXGateType:
219 case Kind::kCYGateType:
222 case Kind::kCZGateType:
225 case Kind::kCPGateType:
228 case Kind::kCRxGateType:
231 case Kind::kCRyGateType:
234 case Kind::kCRzGateType:
237 case Kind::kCHGateType:
240 case Kind::kCSxGateType:
243 case Kind::kCSxDagGateType:
246 case Kind::kCUGateType:
249 case Kind::kCSwapGateType:
252 case Kind::kCCXGateType:
258 else if (
qubits.size() == 2)
264 throw std::logic_error(
"Unknown fusion gate");
267 std::vector<FusionGate>
Expand(
unsigned width)
const
269 if (
qubits.size() <= width)
271 if (width != 2 || (
kind != Kind::kCCXGateType &&
kind != Kind::kCSwapGateType))
272 throw std::invalid_argument(
"Unsupported generic gate width");
274 return std::vector<FusionGate>{{Kind::kCSxGateType, {b, c}, {}, {}},
275 {Kind::kCXGateType, {a, b}, {}, {}},
276 {Kind::kCSxDagGateType, {b, c}, {}, {}},
277 {Kind::kCXGateType, {a, b}, {}, {}},
278 {Kind::kCSxGateType, {a, c}, {}, {}}};
280 if (
kind == Kind::kCCXGateType)
284 result.insert(result.begin(), cx);
285 result.push_back(cx);
312 throw std::logic_error(
"A routing operation cannot be executed");
315 std::shared_ptr<Circuits::IOperation<>>
Clone()
const override
320 std::shared_ptr<Circuits::IOperation<>>
Remap(
const std::unordered_map<Types::qubit_t, Types::qubit_t> &map,
321 const std::unordered_map<Types::qubit_t, Types::qubit_t> & = {})
const override
323 auto targets = targets_;
324 for (
auto &q : targets)
326 return std::make_shared<FusionRoutingOperation>(std::move(targets), schmidtRank, isSwap);
The controlled controlled x gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The controlled x rotation gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The controlled y rotation gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The controlled z rotation gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The controlled swap gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The controlled Sx dagger gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
virtual Types::qubit_t GetQubit(unsigned int index=0) const =0
Get the qubit involved.
virtual unsigned int GetNumQubits() const =0
Get the number of qubits.
IOperation(Time delay=0)
Construct a new IOperation object.
The interface for quantum gates.
virtual QuantumGateType GetGateType() const =0
Get the type of the quantum gate.
virtual Eigen::MatrixXcd GetMatrix() const =0
Get the matrix representation of the quantum gate.
virtual std::vector< double > GetParams() const
Get the gate parameters.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
The state class that stores the classical state of a quantum circuit execution.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
Eigen::MatrixXcd GetMatrix() const override
Get the matrix representation of the quantum gate.
FusionRoutingOperation(Types::qubits_vector targets, double rank=4, bool swap=false)
std::shared_ptr< Circuits::IOperation<> > Clone() const override
Get a shared pointer to a clone of this object.
std::shared_ptr< Circuits::IOperation<> > Remap(const std::unordered_map< Types::qubit_t, Types::qubit_t > &map, const std::unordered_map< Types::qubit_t, Types::qubit_t > &={}) const override
Get a shared pointer to a remapped operation.
Types::qubits_vector AffectedQubits() const override
Returns the affected qubits.
void Execute(const std::shared_ptr< ISimulator > &, Circuits::OperationState &) const override
Execute the operation.
Circuits::OperationType GetType() const override
Get the type of the operation.
Interface class for a quantum computing simulator.
virtual void ApplyCRz(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRz gate to the qubits.
virtual void ApplySDG(Types::qubit_t qubit)=0
Applies a S dagger gate to the qubit.
virtual void ApplyCCX(Types::qubit_t qubit0, Types::qubit_t qubit1, Types::qubit_t qubit2)=0
Applies a controlled controlled not gate to the qubits.
virtual void ApplyX(Types::qubit_t qubit)=0
Applies a not gate to the qubit.
virtual void ApplyCSxDAG(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CSx dagger gate to the qubits.
virtual void ApplyU(Types::qubit_t qubit, double theta, double phi, double lambda, double gamma)=0
Applies a U gate to the qubit.
virtual void ApplyP(Types::qubit_t qubit, double lambda)=0
Applies a phase shift gate to the qubit.
virtual void ApplySx(Types::qubit_t qubit)=0
Applies a Sx gate to the qubit.
virtual void ApplyTDG(Types::qubit_t qubit)=0
Applies a T dagger gate to the qubit.
virtual void ApplyCU(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta, double phi, double lambda, double gamma)=0
Applies a controlled U gate to the qubits.
virtual void ApplyGenericThreeQubitGate(Types::qubit_t, Types::qubit_t, Types::qubit_t, const Matrix8cd &)
virtual void ApplyCRy(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRy gate to the qubits.
virtual void ApplyCX(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CX gate to the qubits.
virtual void ApplyRy(Types::qubit_t qubit, double theta)=0
Applies a Ry gate to the qubit.
virtual void ApplyCH(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CH gate to the qubits.
virtual void ApplySwap(Types::qubit_t qubit0, Types::qubit_t qubit1)=0
Applies a swap gate to the qubits.
virtual void ApplyCSx(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CSx gate to the qubits.
virtual void ApplyGenericTwoQubitGate(Types::qubit_t qubit0, Types::qubit_t qubit1, const Eigen::Matrix4cd &gate)=0
Apply a generic two-qubit gate to the specified qubits.
virtual void ApplyK(Types::qubit_t qubit)=0
Applies a K gate to the qubit.
virtual void ApplyY(Types::qubit_t qubit)=0
Applies a Y gate to the qubit.
virtual void ApplyT(Types::qubit_t qubit)=0
Applies a T gate to the qubit.
virtual void ApplyS(Types::qubit_t qubit)=0
Applies a S gate to the qubit.
virtual void ApplyCSwap(Types::qubit_t ctrl_qubit, Types::qubit_t qubit0, Types::qubit_t qubit1)=0
Applies a controlled swap gate to the qubits.
virtual void ApplyZ(Types::qubit_t qubit)=0
Applies a Z gate to the qubit.
virtual void ApplyRz(Types::qubit_t qubit, double theta)=0
Applies a Rz gate to the qubit.
virtual void ApplyCRx(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double theta)=0
Applies a CRx gate to the qubits.
virtual void ApplyCY(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CY gate to the qubits.
virtual void ApplyCZ(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit)=0
Applies a CZ gate to the qubits.
virtual void ApplyH(Types::qubit_t qubit)=0
Applies a Hadamard gate to the qubit.
virtual void ApplyRx(Types::qubit_t qubit, double theta)=0
Applies a Rx gate to the qubit.
virtual void ApplySxDAG(Types::qubit_t qubit)=0
Applies a Sx dagger gate to the qubit.
virtual void ApplyCP(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit, double lambda)=0
Applies a CP gate to the qubits.
virtual void ApplyGenericOneQubitGate(Types::qubit_t qubit, const Eigen::Matrix2cd &gate)=0
Apply a generic one-qubit gate to the specified qubit.
QuantumGateType
The type of quantum gates.
OperationType
The type of operations.
@ kGate
the usual quantum gate, result stays in simulator's state
Bounded online routing based on current physical bond dimensions.
double RoutingSchmidtRank(Circuits::QuantumGateType type, double angle, MatrixFn &&matrix)
std::vector< qubit_t > qubits_vector
The type of a vector of qubits.
uint_fast64_t qubit_t
The type of a qubit.
double SchmidtRank() const
Eigen::MatrixXcd Matrix() const
bool Matches(const FusionGate &other) const
void Apply(ISimulator &sim) const
std::vector< FusionGate > Expand(unsigned width) const
bool IsStructured() const
Types::qubits_vector qubits
static FusionGate FromCircuit(const Circuits::IQuantumGate<> &gate)
std::array< double, 4 > params
Circuits::QuantumGateType Kind
Types::qubits_vector Targets() const