general_quantum_operator.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "type.hpp"
4 #include <cstdio>
5 #include <vector>
6 #include <utility>
7 #include <iostream>
8 #include <string>
9 
10 class PauliOperator;
11 class QuantumStateBase;
12 
13 
15 private:
17  std::vector<PauliOperator*> _operator_list;
19  UINT _qubit_count;
20  bool _is_hermitian;
21 public:
30  GeneralQuantumOperator(UINT qubit_count);
31 
36  virtual ~GeneralQuantumOperator();
37 
44  virtual bool is_hermitian() const { return _is_hermitian; }
45 
52  virtual void add_operator(const PauliOperator* mpt);
53 
61  virtual void add_operator(CPPCTYPE coef, std::string pauli_string);
62 
68  virtual UINT get_qubit_count() const { return _qubit_count; }
69 
75  virtual ITYPE get_state_dim() const { return (1ULL) << _qubit_count; }
76 
82  virtual UINT get_term_count() const { return (UINT)_operator_list.size(); }
83 
90  virtual const PauliOperator* get_term(UINT index) const {
91  if (index >= _operator_list.size()) {
92  std::cerr << "Error: PauliOperator::get_term(UINT): index out of range" << std::endl;
93  return NULL;
94  }
95  return _operator_list[index];
96  }
97 
103  virtual std::vector<PauliOperator*> get_terms() const { return _operator_list;}
104 
112  virtual CPPCTYPE get_expectation_value(const QuantumStateBase* state) const ;
113 
122  virtual CPPCTYPE get_transition_amplitude(const QuantumStateBase* state_bra, const QuantumStateBase* state_ket) const;
123 
124 };
125 
126 namespace quantum_operator{
136 
146 
153  DllExport std::pair<GeneralQuantumOperator*, GeneralQuantumOperator*> create_split_general_quantum_operator(std::string file_path);
154 }
155 
#define DllExport
Definition: type.hpp:32
virtual bool is_hermitian() const
Definition: general_quantum_operator.hpp:44
virtual std::vector< PauliOperator * > get_terms() const
Definition: general_quantum_operator.hpp:103
virtual UINT get_qubit_count() const
Definition: general_quantum_operator.hpp:68
std::pair< GeneralQuantumOperator *, GeneralQuantumOperator * > create_split_general_quantum_operator(std::string file_path)
Definition: general_quantum_operator.cpp:164
virtual ITYPE get_state_dim() const
Definition: general_quantum_operator.hpp:75
Definition: general_quantum_operator.cpp:78
std::complex< double > CPPCTYPE
Definition: type.hpp:14
Definition: general_quantum_operator.hpp:14
Definition: state.hpp:24
GeneralQuantumOperator * create_general_quantum_operator_from_openfermion_file(std::string file_path)
Definition: general_quantum_operator.cpp:79
Definition: pauli_operator.hpp:66
bool check_Pauli_operator(const GeneralQuantumOperator *quantum_operator, const PauliOperator *pauli_operator)
Definition: general_quantum_operator.cpp:226
virtual const PauliOperator * get_term(UINT index) const
Definition: general_quantum_operator.hpp:90
Definition: state.cpp:15
virtual UINT get_term_count() const
Definition: general_quantum_operator.hpp:82
GeneralQuantumOperator * create_general_quantum_operator_from_openfermion_text(std::string text)
Definition: general_quantum_operator.cpp:126