gate_named_pauli.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef _MSC_VER
4 extern "C" {
5 #include <csim/update_ops.h>
6 }
7 #else
8 #include <csim/update_ops.h>
9 #endif
10 
11 #include "gate.hpp"
12 #include "state.hpp"
13 #include "utility.hpp"
14 #include "pauli_operator.hpp"
15 
19 class ClsPauliGate : public QuantumGateBase {
20 protected:
22 public:
30  _pauli = pauli;
31  this->_name = "Pauli";
32  auto target_index_list = _pauli->get_index_list();
33  auto pauli_id_list = _pauli->get_pauli_id_list();
34  for (UINT index = 0; index < target_index_list.size(); ++index) {
35  UINT commutation_relation = 0;
36  if (pauli_id_list[index] == 1) commutation_relation = FLAG_X_COMMUTE;
37  else if (pauli_id_list[index] == 2)commutation_relation = FLAG_Y_COMMUTE;
38  else if (pauli_id_list[index] == 3)commutation_relation = FLAG_Z_COMMUTE;
39  this->_target_qubit_list.push_back(TargetQubitInfo(target_index_list[index], commutation_relation));
40  }
41  };
45  virtual ~ClsPauliGate() {
46  delete _pauli;
47  }
53  virtual void update_quantum_state(QuantumStateBase* state) override {
54  auto target_index_list = _pauli->get_index_list();
55  auto pauli_id_list = _pauli->get_pauli_id_list();
56  multi_qubit_Pauli_gate_partial_list(
57  target_index_list.data(), pauli_id_list.data(), (UINT)target_index_list.size(),
58  state->data_c(), state->dim);
59  };
65  virtual QuantumGateBase* copy() const override {
66  return new ClsPauliGate(_pauli->copy());
67  };
68 
74  virtual void set_matrix(ComplexMatrix& matrix) const override {
76  }
77 };
78 
79 
84 protected:
85  double _angle;
87 public:
95  ClsPauliRotationGate(double angle, PauliOperator* pauli)
96  : _angle(angle) {
97  _pauli = pauli;
98  this->_name = "Pauli-rotation";
99  auto target_index_list = _pauli->get_index_list();
100  auto pauli_id_list = _pauli->get_pauli_id_list();
101  for (UINT index = 0; index < target_index_list.size(); ++index) {
102  UINT commutation_relation = 0;
103  if (pauli_id_list[index] == 1) commutation_relation = FLAG_X_COMMUTE;
104  else if (pauli_id_list[index] == 2)commutation_relation = FLAG_Y_COMMUTE;
105  else if (pauli_id_list[index] == 3)commutation_relation = FLAG_Z_COMMUTE;
106  this->_target_qubit_list.push_back(TargetQubitInfo(target_index_list[index], commutation_relation));
107  }
108  };
113  delete _pauli;
114  }
120  virtual void update_quantum_state(QuantumStateBase* state) override {
121  auto target_index_list = _pauli->get_index_list();
122  auto pauli_id_list = _pauli->get_pauli_id_list();
123  multi_qubit_Pauli_rotation_gate_partial_list(
124  target_index_list.data(), pauli_id_list.data(), (UINT)target_index_list.size(),
125  _angle, state->data_c(), state->dim);
126  };
132  virtual QuantumGateBase* copy() const override {
133  return new ClsPauliRotationGate(_angle, _pauli->copy());
134  };
135 
141  virtual void set_matrix(ComplexMatrix& matrix) const override {
143  matrix = cos(_angle)*ComplexMatrix::Identity(matrix.rows(), matrix.cols()) + 1.i * sin(_angle) * matrix;
144  }
145 };
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::string _name
Definition: gate.hpp:80
PauliOperator * _pauli
Definition: gate_named_pauli.hpp:21
Definition: gate_named_pauli.hpp:83
virtual ~ClsPauliGate()
Definition: gate_named_pauli.hpp:45
std::vector< UINT > get_index_list() const
Definition: pauli_operator.hpp:76
virtual ~ClsPauliRotationGate()
Definition: gate_named_pauli.hpp:112
virtual PauliOperator * copy() const
Definition: pauli_operator.cpp:98
Definition and basic functions for QuantumGate.
virtual void update_quantum_state(QuantumStateBase *state) override
Definition: gate_named_pauli.hpp:53
#define FLAG_X_COMMUTE
Flags for bit property: diagonal in X-basis.
Definition: qubit_info.hpp:7
virtual void set_matrix(ComplexMatrix &matrix) const override
Definition: gate_named_pauli.hpp:141
void get_Pauli_matrix(ComplexMatrix &matrix, const std::vector< UINT > &pauli_id_list)
Definition: utility.cpp:4
Definition: qubit_info.hpp:86
virtual QuantumGateBase * copy() const override
Definition: gate_named_pauli.hpp:132
#define FLAG_Y_COMMUTE
Flags for bit property: diagonal in Y-basis.
Definition: qubit_info.hpp:9
std::vector< UINT > get_pauli_id_list() const
Definition: pauli_operator.hpp:90
#define FLAG_Z_COMMUTE
Flags for bit property: diagonal in Z-basis.
Definition: qubit_info.hpp:11
Definition: state.hpp:23
virtual QuantumGateBase * copy() const override
Definition: gate_named_pauli.hpp:65
Definition: pauli_operator.hpp:63
PauliOperator * _pauli
Definition: gate_named_pauli.hpp:86
virtual void update_quantum_state(QuantumStateBase *state) override
Definition: gate_named_pauli.hpp:120
Definition: gate_named_pauli.hpp:19
Definition and basic functions for MultiPauliTerm.
ClsPauliGate(PauliOperator *pauli)
Definition: gate_named_pauli.hpp:29
double _angle
Definition: gate_named_pauli.hpp:85
Definition: state.cpp:14
QuantumGateBase * Identity(UINT qubit_index)
Definition: gate_factory.cpp:20
virtual void set_matrix(ComplexMatrix &matrix) const override
Definition: gate_named_pauli.hpp:74
ClsPauliRotationGate(double angle, PauliOperator *pauli)
Definition: gate_named_pauli.hpp:95
Definition: gate.hpp:75