Skip to content

Commit

Permalink
Merge pull request #53 from danclaudino/fermion_bindings
Browse files Browse the repository at this point in the history
FermionOperator bindings for getTerms
  • Loading branch information
danclaudino authored Oct 16, 2024
2 parents 97c1dff + c3f7f45 commit 8adf8ac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions quantum/observable/fermion/FermionOperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ class FermionOperator
std::shared_ptr<Observable> normalOrder() override;

std::vector<std::shared_ptr<CompositeInstruction>> getMeasurementBasisRotations() override;

std::vector<std::shared_ptr<Observable>> getSubTerms() override {
std::vector<std::shared_ptr<Observable>> ret;
for (auto &term : getTerms()) {
ret.emplace_back(
new FermionOperator(term.second.ops(), term.second.coeff()));
}
return ret;
}


};

Expand Down
7 changes: 5 additions & 2 deletions quantum/python/xacc-quantum-py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<FermionTerm>(k, "FermionTerm")
.def("coeff", &FermionTerm::coeff)
Expand Down Expand Up @@ -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<OperatorPool>(name);
Expand Down

0 comments on commit 8adf8ac

Please sign in to comment.