Quandary
Loading...
Searching...
No Matches
gate.hpp
Go to the documentation of this file.
1#include <stdio.h>
2#include <iostream>
3#include <math.h>
4#include <assert.h>
5#include <petscmat.h>
6#include <vector>
7#include "defs.hpp"
8#include "util.hpp"
9#pragma once
10
18class Gate {
19 protected:
20 Mat V_re, V_im;
21
22 std::vector<size_t> nessential;
23 std::vector<size_t> nlevels;
27
28 bool quietmode;
29
30 PetscInt dim_ess;
31 PetscInt dim_rho;
32
33 double final_time;
34 std::vector<double> gate_rot_freq;
35
37
38
39 private:
40 Mat VxV_re, VxV_im;
41 Vec x;
42 IS isu, isv;
43
44 public:
45 Gate();
46
57 Gate(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time_, const std::vector<double>& gate_rot_freq, DecoherenceType decoherence_type_, bool quietmode=false);
58
59 virtual ~Gate();
60
66 PetscInt getDimRho() { return dim_rho; };
67
74 void assembleGate();
75
85 void applyGate(const Vec state, Vec VrhoV);
86};
87
97class XGate : public Gate {
98 public:
99 XGate(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
100 ~XGate();
101};
102
112class YGate : public Gate {
113 public:
114 YGate(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
115 ~YGate();
116};
117
127class ZGate : public Gate {
128 public:
129 ZGate(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
130 ~ZGate();
131};
132
142class HadamardGate : public Gate {
143 public:
144 HadamardGate(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
146};
147
159class CNOT : public Gate {
160 public:
161 CNOT(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
162 ~CNOT();
163};
164
176class SWAP: public Gate {
177 public:
178 SWAP(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
179 ~SWAP();
180};
181
182
189class SWAP_0Q: public Gate {
190 public:
191 SWAP_0Q(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
192 ~SWAP_0Q();
193};
194
201class CQNOT: public Gate {
202 public:
203 CQNOT(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
204 ~CQNOT();
205};
206
212class QFT: public Gate {
213 public:
214 QFT(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, bool quietmode=false);
215 ~QFT();
216};
217
223class FromFile: public Gate {
224 public:
236 FromFile(const std::vector<size_t>& nlevels_, const std::vector<size_t>& nessential_, double time, const std::vector<double>& rotation_frequencies_, DecoherenceType decoherence_type_, const std::string& filename, bool quietmode=false);
237 ~FromFile();
238};
239
240
257Gate* initTargetGate(GateType target_gate, const std::string& file, const std::vector<size_t>& nlevels, const std::vector<size_t>& nessential, double total_time, DecoherenceType decoherence_type, const std::vector<double>& gate_rot_freq, bool quietmode);
Controlled-NOT (CNOT) gate implementation.
Definition gate.hpp:159
~CNOT()
Definition gate.cpp:388
Multi-qubit CQNOT gate implementation.
Definition gate.hpp:201
~CQNOT()
Definition gate.cpp:478
Gate loaded from external file.
Definition gate.hpp:223
~FromFile()
Definition gate.cpp:544
Base class for quantum gate operations.
Definition gate.hpp:18
bool quietmode
Flag to suppress output messages.
Definition gate.hpp:28
DecoherenceType decoherence_type
Type of Lindblad operators for open system dynamics.
Definition gate.hpp:36
double final_time
Final time T. Time of gate rotation.
Definition gate.hpp:33
std::vector< double > gate_rot_freq
Frequencies of gate rotation (rad/time). Default: 0.0.
Definition gate.hpp:34
PetscInt dim_rho
Dimension of system matrix rho (non-vectorized), all levels, N.
Definition gate.hpp:31
Gate()
Definition gate.cpp:4
Mat V_re
Definition gate.hpp:20
void applyGate(const Vec state, Vec VrhoV)
Applies the gate transformation to a quantum state.
Definition gate.cpp:261
PetscInt dim_ess
Dimension of target gate matrix (non-vectorized), essential levels only.
Definition gate.hpp:30
PetscInt getDimRho()
Retrieves the dimension of the density matrix.
Definition gate.hpp:66
std::vector< size_t > nlevels
Total number of levels per oscillator.
Definition gate.hpp:23
std::vector< size_t > nessential
Number of essential levels per oscillator.
Definition gate.hpp:22
Mat V_im
Real and imaginary parts of V_target, non-vectorized, essential levels only.
Definition gate.hpp:20
virtual ~Gate()
Definition gate.cpp:78
int mpirank_petsc
MPI rank in PETSc communicator.
Definition gate.hpp:24
int mpirank_world
MPI rank in world communicator.
Definition gate.hpp:26
void assembleGate()
Assembles the vectorized gate matrix.
Definition gate.cpp:89
int mpisize_petsc
MPI size in PETSc communicator.
Definition gate.hpp:25
Hadamard gate implementation.
Definition gate.hpp:142
~HadamardGate()
Definition gate.cpp:362
Quantum Fourier Transform gate implementation.
Definition gate.hpp:212
~QFT()
Definition gate.cpp:503
Multi-qubit SWAP gate implementation.
Definition gate.hpp:189
~SWAP_0Q()
Definition gate.cpp:449
SWAP gate implementation.
Definition gate.hpp:176
~SWAP()
Definition gate.cpp:410
Pauli-X gate implementation.
Definition gate.hpp:97
~XGate()
Definition gate.cpp:304
Pauli-Y gate implementation.
Definition gate.hpp:112
~YGate()
Definition gate.cpp:322
Pauli-Z gate implementation.
Definition gate.hpp:127
~ZGate()
Definition gate.cpp:341
Core type definitions and enumerations for Quandary quantum optimal control.
DecoherenceType
Available Lindblad operator types for open quantum systems, or NONE for closed quantum systems.
Definition defs.hpp:31
GateType
Types of quantum gates used in quantum control.
Definition defs.hpp:200
Gate * initTargetGate(GateType target_gate, const std::string &file, const std::vector< size_t > &nlevels, const std::vector< size_t > &nessential, double total_time, DecoherenceType decoherence_type, const std::vector< double > &gate_rot_freq, bool quietmode)
Factory function to initialize a gate from configuration string.
Definition gate.cpp:547