Maestro 0.3.1
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
Simulator.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#ifndef _SIMULATOR_INTERFACE_H_
17#define _SIMULATOR_INTERFACE_H_
18
19#include "State.h"
20
21namespace Simulators {
22
33class ISimulator : public IState, std::enable_shared_from_this<ISimulator> {
34 public:
35 // Native CUDA device, or -1 for CPU/uninitialized simulators.
36 virtual int GetGpuDevice() const { return -1; }
37
44 const Eigen::Matrix2cd& gate) = 0;
45
53 Types::qubit_t qubit1,
54 const Eigen::Matrix4cd& gate) = 0;
55
63 virtual void ApplyP(Types::qubit_t qubit, double lambda) = 0;
64
71 virtual void ApplyX(Types::qubit_t qubit) = 0;
72
79 virtual void ApplyY(Types::qubit_t qubit) = 0;
80
87 virtual void ApplyZ(Types::qubit_t qubit) = 0;
88
95 virtual void ApplyH(Types::qubit_t qubit) = 0;
96
103 virtual void ApplyS(Types::qubit_t qubit) = 0;
104
111 virtual void ApplySDG(Types::qubit_t qubit) = 0;
112
119 virtual void ApplyT(Types::qubit_t qubit) = 0;
120
127 virtual void ApplyTDG(Types::qubit_t qubit) = 0;
128
135 virtual void ApplySx(Types::qubit_t qubit) = 0;
136
143 virtual void ApplySxDAG(Types::qubit_t qubit) = 0;
144
151 virtual void ApplyK(Types::qubit_t qubit) = 0;
152
160 virtual void ApplyRx(Types::qubit_t qubit, double theta) = 0;
161
169 virtual void ApplyRy(Types::qubit_t qubit, double theta) = 0;
170
178 virtual void ApplyRz(Types::qubit_t qubit, double theta) = 0;
179
190 virtual void ApplyU(Types::qubit_t qubit, double theta, double phi,
191 double lambda, double gamma) = 0;
192
200 virtual void ApplyCX(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit) = 0;
201
209 virtual void ApplyCY(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit) = 0;
210
218 virtual void ApplyCZ(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit) = 0;
219
228 virtual void ApplyCP(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit,
229 double lambda) = 0;
230
239 virtual void ApplyCRx(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit,
240 double theta) = 0;
241
250 virtual void ApplyCRy(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit,
251 double theta) = 0;
252
261 virtual void ApplyCRz(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit,
262 double theta) = 0;
263
271 virtual void ApplyCH(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit) = 0;
272
280 virtual void ApplyCSx(Types::qubit_t ctrl_qubit,
281 Types::qubit_t tgt_qubit) = 0;
282
290 virtual void ApplyCSxDAG(Types::qubit_t ctrl_qubit,
291 Types::qubit_t tgt_qubit) = 0;
292
300 virtual void ApplySwap(Types::qubit_t qubit0, Types::qubit_t qubit1) = 0;
301
310 virtual void ApplyCCX(Types::qubit_t qubit0, Types::qubit_t qubit1,
311 Types::qubit_t qubit2) = 0;
312
321 virtual void ApplyCSwap(Types::qubit_t ctrl_qubit, Types::qubit_t qubit0,
322 Types::qubit_t qubit1) = 0;
323
335 virtual void ApplyCU(Types::qubit_t ctrl_qubit, Types::qubit_t tgt_qubit,
336 double theta, double phi, double lambda,
337 double gamma) = 0;
338
346 virtual void ApplyNop() = 0;
347
356 void InitializeToBasisState(size_t num_qubits,
357 Types::qubit_t basisState) override {
358 if (num_qubits == 0) return;
359 Clear();
360 AllocateQubits(num_qubits);
361 Initialize();
362 for (size_t q = 0; q < num_qubits; ++q)
363 if ((basisState >> q) & 1ULL) ApplyX(static_cast<Types::qubit_t>(q));
364 }
365
372 void InitializeToBasisState(size_t num_qubits,
373 const std::vector<bool> &basisState) override {
374 if (num_qubits == 0) return;
375 Clear();
376 AllocateQubits(num_qubits);
377 Initialize();
378 for (size_t q = 0; q < num_qubits && q < basisState.size(); ++q)
379 if (basisState[q]) ApplyX(static_cast<Types::qubit_t>(q));
380 }
381
392 virtual std::unique_ptr<ISimulator> Clone() = 0;
393
401 std::shared_ptr<ISimulator> getptr() { return shared_from_this(); }
402};
403} // namespace Simulators
404
405#endif // !_SIMULATOR_INTERFACE_H_
Interface class for a quantum computing simulator.
Definition Simulator.h:33
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.
std::shared_ptr< ISimulator > getptr()
Get a shared pointer to this object.
Definition Simulator.h:401
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.
void InitializeToBasisState(size_t num_qubits, Types::qubit_t basisState) override
Initializes the state to a computational basis state.
Definition Simulator.h:356
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 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.
void InitializeToBasisState(size_t num_qubits, const std::vector< bool > &basisState) override
Initializes the state to a computational basis state.
Definition Simulator.h:372
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 int GetGpuDevice() const
Definition Simulator.h:36
virtual void ApplyNop()=0
Applies a nop.
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 std::unique_ptr< ISimulator > Clone()=0
Clones the simulator.
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.
Interface class for a quantum computing simulator state.
Definition State.h:119
virtual void Initialize()=0
Initializes the state.
virtual size_t AllocateQubits(size_t num_qubits)=0
Allocates qubits.
virtual void Clear()=0
Clears the state.
uint_fast64_t qubit_t
The type of a qubit.
Definition Types.h:21