gate_reflect.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  QuantumStateBase* reflection_state;
27 public:
28  ClsStateReflectionGate(const QuantumStateBase* _reflection_state) {
29  reflection_state = _reflection_state->copy();
30  UINT qubit_count = _reflection_state->qubit_count;
31  for (UINT qubit_index = 0; qubit_index < qubit_count; ++qubit_index) {
32  this->_target_qubit_list.push_back(TargetQubitInfo(qubit_index, 0));
33  }
34  this->_name = "Reflection";
35  };
37  delete reflection_state;
38  }
39 
45  virtual void update_quantum_state(QuantumStateBase* state) override {
46  if (state->is_state_vector()) {
47 #ifdef _USE_GPU
48  if (state->get_device_name() != reflection_state->get_device_name()) {
49  std::cerr << "Quantum state on CPU (GPU) cannot be reflected using quantum state on GPU (CPU)" << std::endl;
50  return;
51  }
52  if (state->get_device_name() == "gpu") {
53  std::cerr << "Not Implemented" << std::endl;
54  exit(0);
55  //reversible_boolean_gate_gpu(target_index.data(), target_index.size(), function_ptr, state->data_c(), state->dim);
56  }
57  else {
58  reflection_gate(reflection_state->data_c(), state->data_c(), state->dim);
59  }
60 #else
61  reflection_gate(reflection_state->data_c(), state->data_c(), state->dim);
62 #endif
63  }
64  else {
65  std::cerr << "not implemented" << std::endl;
66  }
67  };
73  virtual QuantumGateBase* copy() const override {
74  return new ClsStateReflectionGate(this->reflection_state);
75  };
81  virtual void set_matrix(ComplexMatrix& matrix) const override {
82  std::cerr << "ReflectionGate::set_matrix is not implemented" << std::endl;
83  exit(0);
84  }
85 };
86 
87 
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.
virtual CTYPE * data_c() const =0
virtual ~ClsStateReflectionGate()
Definition: gate_reflect.hpp:36
virtual const std::string get_device_name() const =0
ClsStateReflectionGate(const QuantumStateBase *_reflection_state)
Definition: gate_reflect.hpp:28
Definition: qubit_info.hpp:86
virtual void update_quantum_state(QuantumStateBase *state) override
Definition: gate_reflect.hpp:45
Definition: state.hpp:24
virtual QuantumGateBase * copy() const override
Definition: gate_reflect.hpp:73
virtual void set_matrix(ComplexMatrix &matrix) const override
Definition: gate_reflect.hpp:81
virtual QuantumStateBase * copy() const =0
Definition: state.cpp:15
const UINT & qubit_count
Definition: state.hpp:31
Definition: gate_reflect.hpp:24
Definition: gate.hpp:76