gate.hpp
Go to the documentation of this file.
1 
51 #pragma once
52 
53 #include "type.hpp"
54 #include "qubit_info.hpp"
55 #include <vector>
56 #include <iostream>
57 #include <ostream>
58 #include <string>
59 
61 #define FLAG_PAULI 0x01
62 #define FLAG_CLIFFORD 0x02
64 #define FLAG_GAUSSIAN 0x04
66 #define FLAG_PARAMETRIC 0x08
68 
69 class QuantumGateMatrix;
70 class QuantumStateBase;
71 
76 protected:
77  std::vector<TargetQubitInfo> _target_qubit_list;
78  std::vector<ControlQubitInfo> _control_qubit_list;
79  UINT _gate_property=0;
80  std::string _name="Generic gate";
81 
82  // prohibit constructor, destructor, copy constructor, and insertion
84  QuantumGateBase(const QuantumGateBase& obj) = default;
85  QuantumGateBase& operator=(const QuantumGateBase& rhs) = default;
86 public:
90  virtual ~QuantumGateBase() {};
91 
92  const std::vector<TargetQubitInfo>& target_qubit_list = _target_qubit_list;
93  const std::vector<ControlQubitInfo>& control_qubit_list = _control_qubit_list;
100  std::vector<UINT> get_target_index_list() const {
101  std::vector<UINT> res(target_qubit_list.size());
102  for (UINT i = 0; i < target_qubit_list.size(); ++i) res[i] = target_qubit_list[i].index();
103  return res;
104  }
110  std::vector<UINT> get_control_index_list() const {
111  std::vector<UINT> res(control_qubit_list.size());
112  for (UINT i = 0; i < control_qubit_list.size(); ++i) res[i] = control_qubit_list[i].index();
113  return res;
114  }
115 
121  virtual void update_quantum_state(QuantumStateBase* state) = 0 ;
127  virtual QuantumGateBase* copy() const = 0;
133  virtual void set_matrix(ComplexMatrix& matrix) const = 0;
134 
144  bool is_commute(const QuantumGateBase* gate) const;
151  bool is_Pauli() const;
158  bool is_Clifford() const;
165  bool is_Gaussian() const;
172  bool is_parametric() const;
179  bool is_diagonal() const;
180 
187  UINT get_property_value() const;
188 
197  bool commute_Pauli_at(UINT qubit_index, UINT pauli_type) const;
198 
204  virtual std::string to_string() const;
205 
211  friend DllExport std::ostream& operator<<(std::ostream& os, const QuantumGateBase&);
217  friend DllExport std::ostream& operator<<(std::ostream& os, const QuantumGateBase* gate);
218 };
219 
Eigen::Matrix< CPPCTYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrix
Definition: type.hpp:17
std::vector< TargetQubitInfo > _target_qubit_list
Definition: gate.hpp:77
std::vector< ControlQubitInfo > _control_qubit_list
Definition: gate.hpp:78
#define DllExport
Definition: type.hpp:30
Definition: gate_matrix.hpp:9
Definition: gate_factory.cpp:17
virtual ~QuantumGateBase()
Definition: gate.hpp:90
std::vector< UINT > get_target_index_list() const
Definition: gate.hpp:100
Definition: state.hpp:23
QuantumGateBase()
Definition: gate.hpp:83
std::ostream & operator<<(std::ostream &stream, const QuantumCircuit &circuit)
Definition: circuit.cpp:163
Definition: state.cpp:14
std::vector< UINT > get_control_index_list() const
Definition: gate.hpp:110
Definition: gate.hpp:75