gate_reversible.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gate.hpp"
4 #include "state.hpp"
5 #ifndef _MSC_VER
6 extern "C" {
7 #include <csim/update_ops.h>
8 }
9 #else
10 #include <csim/update_ops.h>
11 #endif
12 #include <csim/update_ops_cpp.hpp>
13 
14 #include <cmath>
15 
16 #ifdef _USE_GPU
17 #include <gpusim/update_ops_cuda.h>
18 #endif
19 #include <iostream>
20 
25 private:
26  std::function<ITYPE(ITYPE, ITYPE)> function_ptr;
27 public:
28  ClsReversibleBooleanGate(std::vector<UINT> target_qubit_index_list, std::function<ITYPE(ITYPE, ITYPE)> _function_ptr) : function_ptr(_function_ptr){
29  for (auto val : target_qubit_index_list) {
30  this->_target_qubit_list.push_back(TargetQubitInfo(val, 0));
31  }
32  this->_name = "ReversibleBoolean";
33  };
34 
40  virtual void update_quantum_state(QuantumStateBase* state) override {
41  std::vector<UINT> target_index;
42  for (auto val : this->_target_qubit_list) {
43  target_index.push_back(val.index());
44  }
45 #ifdef _USE_GPU
46  if (state->get_device_name() == "gpu") {
47  std::cerr << "Not Implemented" << std::endl;
48  exit(0);
49  //reversible_boolean_gate_gpu(target_index.data(), target_index.size(), function_ptr, state->data_c(), state->dim);
50  }
51  else {
52  reversible_boolean_gate(target_index.data(), target_index.size(), function_ptr, state->data_c(), state->dim);
53  }
54 #else
55  reversible_boolean_gate(target_index.data(), target_index.size(), function_ptr, state->data_c(), state->dim);
56 #endif
57  };
63  virtual QuantumGateBase* copy() const override {
64  return new ClsReversibleBooleanGate(*this);
65  };
71  virtual void set_matrix(ComplexMatrix& matrix) const override {
72  ITYPE matrix_dim = 1ULL << this->_target_qubit_list.size();
73  matrix = ComplexMatrix::Zero(matrix_dim, matrix_dim);
74  for (ITYPE index = 0; index < matrix_dim; ++index) {
75  ITYPE target_index = function_ptr(index, matrix_dim);
76  matrix(target_index, index) = 1;
77  }
78  }
79 };
80 
81 
ClsReversibleBooleanGate(std::vector< UINT > target_qubit_index_list, std::function< ITYPE(ITYPE, ITYPE)> _function_ptr)
Definition: gate_reversible.hpp:28
Eigen::Matrix< CPPCTYPE, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrix
Definition: type.hpp:18
std::vector< TargetQubitInfo > _target_qubit_list
Definition: gate.hpp:78
std::string _name
Definition: gate.hpp:81
Definition and basic functions for QuantumGate.
Definition: gate_reversible.hpp:24
Definition: qubit_info.hpp:86
virtual QuantumGateBase * copy() const override
Definition: gate_reversible.hpp:63
Definition: state.hpp:24
virtual void update_quantum_state(QuantumStateBase *state) override
Definition: gate_reversible.hpp:40
Definition: state.cpp:15
virtual void set_matrix(ComplexMatrix &matrix) const override
Definition: gate_reversible.hpp:71
Definition: gate.hpp:76