diff --git a/quantum/observable/fermion/FermionOperator.hpp b/quantum/observable/fermion/FermionOperator.hpp index 2d0265d9e..9dbd19a06 100644 --- a/quantum/observable/fermion/FermionOperator.hpp +++ b/quantum/observable/fermion/FermionOperator.hpp @@ -197,6 +197,16 @@ class FermionOperator std::shared_ptr normalOrder() override; std::vector> getMeasurementBasisRotations() override; + + std::vector> getSubTerms() override { + std::vector> ret; + for (auto &term : getTerms()) { + ret.emplace_back( + new FermionOperator(term.second.ops(), term.second.coeff())); + } + return ret; + } + }; diff --git a/quantum/python/xacc-quantum-py.cpp b/quantum/python/xacc-quantum-py.cpp index 3ef62bb02..42c44c632 100644 --- a/quantum/python/xacc-quantum-py.cpp +++ b/quantum/python/xacc-quantum-py.cpp @@ -158,7 +158,8 @@ void bind_quantum(py::module &m) { [](PauliOperator &op) { return py::make_iterator(op.begin(), op.end()); }, - py::keep_alive<0, 1>()); + py::keep_alive<0, 1>()) + .def("commutator", &PauliOperator::commutator); py::class_(k, "FermionTerm") .def("coeff", &FermionTerm::coeff) @@ -192,7 +193,9 @@ void bind_quantum(py::module &m) { .def("__repr__", &FermionOperator::toString) .def("fromString", &FermionOperator::fromString) .def("commutator", &FermionOperator::commutator) - .def("hermitianConjugate", &FermionOperator::hermitianConjugate); + .def("hermitianConjugate", &FermionOperator::hermitianConjugate) + .def("getTerms", &FermionOperator::getTerms) + .def("getSubTerms", &FermionOperator::getSubTerms); k.def("getOperatorPool", [](const std::string &name) { return xacc::getService(name);