8 #include "Identifiable.hpp"
9 #include "heterogeneous.hpp"
10 #include "operators.hpp"
11 #include "qcor_pimpl.hpp"
12 #include "qcor_utils.hpp"
16 using namespace tao::operators;
25 :
public commutative_ring<Operator>,
26 public equality_comparable<Operator>,
27 public commutative_multipliable<Operator, double>,
28 public commutative_multipliable<Operator, std::complex<double>> {
37 Operator(
const std::string &name, xacc::HeterogeneousMap &options);
38 Operator(
const std::string &type,
const std::string &expr);
47 Operator transform(
const std::string &type, xacc::HeterogeneousMap m = {});
51 std::shared_ptr<xacc::Identifiable> get_as_opaque();
57 bool operator==(
const Operator &v) noexcept;
58 Operator &operator*=(
const double v) noexcept;
59 Operator &operator*=(
const std::complex<double> v) noexcept;
63 int nBits() {
return nQubits(); }
67 std::vector<std::shared_ptr<CompositeInstruction>> observe(
68 std::shared_ptr<CompositeInstruction>
function);
71 std::vector<Operator> getSubTerms();
74 std::vector<Operator> getNonIdentitySubTerms();
80 bool hasIdentitySubTerm();
83 std::string toString()
const;
87 std::complex<double> coefficient();
92 std::pair<std::vector<int>, std::vector<int>> toBinaryVectors(
96 void mapQubitSites(std::map<int, int> &siteMap);
100 : std::tuple<std::uint64_t, std::uint64_t, std::complex<double>> {
103 std::complex<double> coeff) {
104 std::get<0>(*
this) = r;
105 std::get<1>(*
this) = c;
106 std::get<2>(*
this) = coeff;
108 std::uint64_t row() {
return std::get<0>(*
this); }
109 std::uint64_t col() {
return std::get<1>(*
this); }
110 const std::complex<double> coeff() {
return std::get<2>(*
this); }
114 std::vector<SparseElement> to_sparse_matrix();
120 void __internal_exec_observer(
121 xacc::AcceleratorBuffer *,
122 std::vector<std::shared_ptr<CompositeInstruction>>);
142 Eigen::MatrixXcd get_dense_matrix(
Operator &op);
145 double observe(std::shared_ptr<CompositeInstruction> program,
Operator &obs,
148 namespace __internal__ {
150 std::vector<std::shared_ptr<CompositeInstruction>> observe(
151 Operator &obs, std::shared_ptr<CompositeInstruction> program);
154 extern std::map<std::size_t, Operator> cached_observables;
158 Operator _internal_python_createObservable(
const std::string &name,
159 const std::string &repr);
163 Operator createObservable(
const std::string &repr);
164 Operator createObservable(
const std::string &name,
const std::string &repr);
165 Operator createOperator(
const std::string &repr);
166 Operator createOperator(
const std::string &name,
const std::string &repr);
167 Operator createOperator(
const std::string &name, HeterogeneousMap &&options);
168 Operator createOperator(
const std::string &name, HeterogeneousMap &options);
171 Operator operatorTransform(
const std::string &type, Operator &op);
177 std::ostream &operator<<(std::ostream &os,
qcor::Operator const &m);