Commit 8679de4b authored by Nguyen, Thien's avatar Nguyen, Thien

Merge branch 'master' into tnguyen/circuit-opt

parents 60c35f1c 84eaaff9
......@@ -126,6 +126,7 @@ if(Python_FOUND)
if(${Python_VERSION} VERSION_GREATER_EQUAL 3.0.0)
message(STATUS "${BoldGreen}Found Python version ${Python_VERSION}. Building XACC Python API with ${Python_INCLUDE_DIRS}${ColorReset}")
add_subdirectory(python)
add_subdirectory(${CMAKE_SOURCE_DIR}/quantum/python)
# Double check we have module ipopo installed, contributes pelix
execute_process(COMMAND ${Python_EXECUTABLE} -c "import pelix" RESULT_VARIABLE PELIX_EXISTS)
if (PELIX_EXISTS EQUAL "1")
......
......@@ -14,16 +14,23 @@ add_subdirectory(compiler)
add_subdirectory(plugins)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
include_directories(.)
include_directories(${Python_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/tpls/pybind11/include)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -O2 -g -pipe -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fexceptions --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv")
if(APPLE)
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)
add_library(_pyxacc SHARED xacc-py.cpp py_heterogeneous_map.cpp py_ir.cpp py_accelerator.cpp py_compiler.cpp py_algorithm.cpp py_optimizer.cpp py_observable.cpp)
add_library(_pyxacc SHARED xacc-py.cpp
py_heterogeneous_map.cpp
py_ir.cpp py_accelerator.cpp
py_compiler.cpp py_algorithm.cpp
py_optimizer.cpp py_observable.cpp
${CMAKE_SOURCE_DIR}/quantum/python/xacc-quantum-py.cpp)
target_include_directories(_pyxacc PUBLIC .
${Python_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/tpls/pybind11/include
${CMAKE_SOURCE_DIR}/quantum/python
${CMAKE_SOURCE_DIR}/quantum/plugins/utils)
set_target_properties(_pyxacc PROPERTIES PREFIX "")
target_link_libraries(_pyxacc PUBLIC xacc xacc-pauli xacc-fermion)
......
# Demonstrate low-level pulse optimization API
# via direct unitary matrix input.
import xacc, sys, numpy as np
# In this simple example, we just optimize a pulse width (sigma)
# of a Gaussian pulse (1 parameter)
initParams = [4.0]
# Target unitary as a matrix:
# in this example, this is a sqrt(X) = Rx(pi/2)
sqrtX = np.identity(2, dtype = np.cdouble)
sqrtX[0][0] = 0.5 + 1j * 0.5
sqrtX[0][1] = 0.5 - 1j * 0.5
sqrtX[1][0] = 0.5 - 1j * 0.5
sqrtX[1][1] = 0.5 + 1j * 0.5
# Use GOAT optimizer:
# Assuming this is a rotating frame Hamiltonian in the most simple form:
# H = Signal(t) * X,
# where Signal(t) is the pulse to optimize.
optimizer = xacc.getOptimizer("quantum-control", {
# Optimization method
"method": "GOAT",
# System dimension, i.e. number of qubits
"dimension": 1,
# Target unitary
"target-U": sqrtX,
# Control parameter (used in the control function)
"control-params": [ "sigma" ],
# Math expression of the pulse envelop (since GOAT is an analytical method)
"control-funcs": [ "0.062831853*exp(-t^2/(2*sigma^2))" ],
# The list of Hamiltonian terms that are modulated by the control functions
"control-H" : [ "X0" ],
# Initial params
"initial-parameters": initParams,
# Time horizon
"max-time": 100.0
})
# The optimization will return the final fidelity error,
# and the set of optimized parameters,
# which, in this case, only contains a single 'sigma' param.
finalFidelityError, paramValues = optimizer.optimize()
print("Optimal sigma = ", paramValues[0])
import xacc, numpy as np
from xacc import PauliOperator
nAngles = 10
......
......@@ -43,47 +43,6 @@ void bind_observable(py::module &m) {
xacc::Observable::fromString,
"");
py::class_<Term>(m, "Term").def("coeff", &Term::coeff).def("ops", &Term::ops);
py::class_<PauliOperator, xacc::Observable, std::shared_ptr<PauliOperator>>(
m, "PauliOperator")
.def(py::init<>())
.def(py::init<std::complex<double>>())
.def(py::init<double>())
.def(py::init<std::string>())
.def(py::init<std::map<int, std::string>>())
.def(py::init<std::map<int, std::string>, double>())
.def(py::init<std::map<int, std::string>, std::complex<double>>())
.def(py::init<std::map<int, std::string>, std::string>())
.def(py::init<std::map<int, std::string>, std::complex<double>,
std::string>())
.def(py::self + py::self)
.def(py::self += py::self)
.def(py::self *= py::self)
.def(py::self *= double())
.def(py::self * py::self)
.def(py::self *= std::complex<double>())
.def(py::self -= py::self)
.def(py::self - py::self)
.def("__eq__", &PauliOperator::operator==)
.def("__repr__", &PauliOperator::toString)
.def("eval", &PauliOperator::eval)
.def("toBinaryVectors", &PauliOperator::toBinaryVectors)
.def("toXACCIR", &PauliOperator::toXACCIR)
.def("fromXACCIR", &PauliOperator::fromXACCIR)
.def("fromString", &PauliOperator::fromString)
.def("nTerms", &PauliOperator::nTerms)
.def("isClose", &PauliOperator::isClose)
.def("commutes", &PauliOperator::commutes)
.def("__len__", &PauliOperator::nTerms)
.def("nQubits", &PauliOperator::nQubits)
.def("computeActionOnKet", &PauliOperator::computeActionOnKet)
.def("computeActionOnBra", &PauliOperator::computeActionOnBra)
.def(
"__iter__",
[](PauliOperator &op) {
return py::make_iterator(op.begin(), op.end());
},
py::keep_alive<0, 1>());
m.def("getObservable",
[](const std::string &type,
const std::string representation) -> std::shared_ptr<Observable> {
......@@ -136,13 +95,16 @@ void bind_observable(py::module &m) {
t = xacc::getService<Observable>(type, false);
} else if (xacc::hasContributedService<Observable>(type)) {
t = xacc::getContributedService<Observable>(type, false);
} else if (type == "fermion") {
t = std::make_shared<FermionOperator>();
} else if (type == "pauli"){
t = std::make_shared<PauliOperator>();
}
if (!t) {
xacc::error("Invalid Observable type name " + type + ", can't find in service registry.");
}
HeterogeneousMap m;
t->fromOptions(m);
return t;
});
}
\ No newline at end of file
import unittest as test
import sys
import xacc
from xaccvqe import PauliOperator
PauliOperator = xacc.quantum.PauliOperator
class TestDecoratorAPI(test.TestCase):
......
......@@ -23,6 +23,7 @@
#include "py_algorithm.hpp"
#include "py_optimizer.hpp"
#include "py_observable.hpp"
#include "xacc-quantum-py.hpp"
namespace py = pybind11;
using namespace xacc;
......@@ -40,6 +41,7 @@ PYBIND11_MODULE(_pyxacc, m) {
bind_algorithm(m);
bind_optimizer(m);
bind_observable(m);
bind_quantum(m);
// Expose XACC API functions
m.def("Initialize", (void (*)(std::vector<std::string>)) & xacc::Initialize,
......
......@@ -38,3 +38,7 @@ target_link_libraries(qaoa_qubo PRIVATE xacc xacc-quantum-gate)
add_executable(quantum_phase_estimation quantum_phase_estimation.cpp)
target_link_libraries(quantum_phase_estimation PRIVATE xacc xacc-quantum-gate)
add_executable(phase_estimation_qasm phase_estimation_10q.cpp)
target_link_libraries(phase_estimation_qasm PRIVATE xacc xacc-quantum-gate)
target_compile_definitions(phase_estimation_qasm PRIVATE QASM_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources")
#include "xacc.hpp"
int main(int argc, char **argv) {
xacc::Initialize(argc, argv);
// State-vector simulator: "aer", "qpp"
auto accelerator = xacc::getAccelerator("aer");
auto compiler = xacc::getCompiler("staq");
const std::string QASM_SRC_FILE = std::string(QASM_SOURCE_DIR) + "/qasm_src.txt";
// Read source file:
std::ifstream inFile;
inFile.open(QASM_SRC_FILE);
std::stringstream strStream;
strStream << inFile.rdbuf();
const std::string qasmSrcStr = strStream.str();
// Compile:
auto IR = compiler->compile(qasmSrcStr);
auto program = IR->getComposites()[0];
std::cout << "Number of instructions: " << program->nInstructions() << "\n";
// Allocate some qubits and execute:
auto buffer = xacc::qalloc(10);
accelerator->execute(buffer, program);
buffer->print();
xacc::Finalize();
}
\ No newline at end of file
This diff is collapsed.
......@@ -107,33 +107,8 @@ const std::string FermionOperator::toString() {
std::complex<double> c = std::get<0>(kv.second);
s << c << " " << std::get<2>(kv.second) << " ";
Operators ops = std::get<1>(kv.second);
// I changed this to get the operators printed in the order they're built
/*
std::vector<int> creations, annhilations;
for (auto &t : ops) {
if (t.second) {
creations.push_back(t.first);
} else {
annhilations.push_back(t.first);
}
}
for (auto &t : creations) {
s << t << "^" << std::string(" ");
}
for (auto &t : annhilations) {
s << t << std::string(" ");
}*/
for (auto &t : ops) {
if (t.second) {
s << t.first << "^" << std::string(" ");
}
else{
s << t.first << std::string(" ");
}
}
// id now corresponds to the operator string, we can just use it
s << kv.first;
s << "+ ";
}
......@@ -289,6 +264,35 @@ std::shared_ptr<Observable> FermionOperator::commutator(std::shared_ptr<Observab
return commutatorHA;
}
// We obtain the hermitian conjugate of FermionOperator
// by walking back on a string of FermionTerm and changing the boolean
FermionOperator FermionOperator::hermitianConjugate() const {
FermionOperator conjugate;
for (auto &kv : terms) {
auto c = std::get<0>(kv.second);
Operators ops = std::get<1>(kv.second), hcOps;
for (int i = ops.size() - 1; i >= 0; i--) {
if (ops[i].second) {
hcOps.push_back({ops[i].first, 0});
} else {
hcOps.push_back({ops[i].first, 1});
}
}
conjugate += FermionOperator(hcOps, std::conj(c));
}
return conjugate;
}
} // namespace quantum
} // namespace xacc
......
......@@ -83,26 +83,16 @@ public:
}
static const std::string id(const Operators &ops) {
std::vector<int> creations, annhilations;
std::stringstream s;
for (auto &t : ops) {
if (t.second) {
creations.push_back(t.first);
s << t.first << "^" << std::string(" ");
} else {
annhilations.push_back(t.first);
s << t.first << std::string(" ");
}
}
// std::sort(creations.rbegin(), creations.rend());
// std::sort(annhilations.rbegin(), annhilations.rend());
std::stringstream s;
for (auto &t : creations) {
s << t << "^" << std::string(" ");
}
for (auto &t : annhilations) {
s << t << std::string(" ");
}
if (s.str().empty()) {
return "I";
}
......@@ -111,27 +101,16 @@ public:
}
const std::string id() {
std::vector<int> creations, annhilations;
std::stringstream s;
for (auto &t : ops()) {
if (t.second) {
creations.push_back(t.first);
s << t.first << "^" << std::string(" ");
} else {
annhilations.push_back(t.first);
s << t.first << std::string(" ");
}
}
// std::sort(creations.rbegin(), creations.rend());
// std::sort(annhilations.rbegin(), annhilations.rend());
std::stringstream s;
for (auto &t : creations) {
s << t << "^" << std::string(" ");
}
for (auto &t : annhilations) {
s << t << std::string(" ");
}
if (s.str().empty()) {
return "I";
}
......@@ -200,13 +179,15 @@ public:
const std::string description() const override {
return "";
}
void fromOptions(const HeterogeneousMap& options) override {
void fromOptions(const HeterogeneousMap& options) override {
return;
}
std::shared_ptr<Observable>
commutator(std::shared_ptr<Observable> obs) override;
FermionOperator hermitianConjugate() const;
};
} // namespace quantum
......
......@@ -20,7 +20,31 @@ using namespace xacc::quantum;
TEST(FermionOperatorTester, checkDanielBug) {
const std::string str = R"#((-0.165607,-0) 2^ 1^ 2 1 + (0.1202,0) 1^ 0^ 1 0 + (-0.0454063,-0) 3^ 0^ 2 1 + (0.168336,0) 2^ 0^ 2 0 + (0.0454063,0) 2^ 1^ 3 0 + (0.168336,0) 2^ 0^ 2 0 + (0.165607,0) 3^ 0^ 3 0 + (-0.0454063,-0) 3^ 0^ 2 1 + (-0.0454063,-0) 3^ 1^ 2 0 + (-0.0454063,-0) 3^ 1^ 2 0 + (0.165607,0) 2^ 1^ 2 1 + (-0.165607,-0) 3^ 0^ 3 0 + (-0.479678,-0) 3^ 3 + (-0.0454063,-0) 2^ 1^ 3 0 + (-0.174073,-0) 3^ 1^ 3 1 + (-0.0454063,-0) 2^ 0^ 3 1 + (0.1202,0) 1^ 0^ 1 0 + (0.0454063,0) 2^ 0^ 3 1 + (0.174073,0) 3^ 1^ 3 1 + (0.165607,0) 2^ 1^ 2 1 + (-0.0454063,-0) 2^ 1^ 3 0 + (-0.1202,-0) 3^ 2^ 3 2 + (0.1202,0) 3^ 2^ 3 2 + (-0.168336,-0) 2^ 0^ 2 0 + (0.1202,0) 3^ 2^ 3 2 + (-0.1202,-0) 3^ 2^ 3 2 + (0.0454063,0) 3^ 1^ 2 0 + (-1.24885,-0) 0^ 0 + (0.0454063,0) 3^ 1^ 2 0 + (-0.168336,-0) 2^ 0^ 2 0 + (0.165607,0) 3^ 0^ 3 0 + (-0.0454063,-0) 2^ 0^ 3 1 + (0.0454063,0) 2^ 0^ 3 1 + (-1.24885,-0) 2^ 2 + (0.0454063,0) 2^ 1^ 3 0 + (0.174073,0) 3^ 1^ 3 1 + (-0.479678,-0) 1^ 1 + (-0.174073,-0) 3^ 1^ 3 1 + (0.0454063,0) 3^ 0^ 2 1 + (-0.165607,-0) 3^ 0^ 3 0 + (0.0454063,0) 3^ 0^ 2 1 + (-0.165607,-0) 2^ 1^ 2 1 + (-0.1202,-0) 1^ 0^ 1 0 + (-0.1202,-0) 1^ 0^ 1 0 + (0.708024,0))#";
auto str = std::string(
"(-0.1656068,0)1^ 2^ 1 2 + (0.1202005,0)1^ 0^ 0 1 + "
"(-0.0454063,0)0^ 3^ 1 2 + (0.168336,0)2^ 0^ 0 2 + "
"(0.0454063,0)1^ 2^ 3 0 + (0.168336,0)0^ 2^ 2 0 + "
"(0.1656068,0)0^ 3^ 3 0 + (-0.0454063,0)3^ 0^ 2 1 + "
"(-0.0454063,0)1^ 3^ 0 2 + (-0.0454063,0)3^ 1^ 2 0 + "
"(0.1656068,0)1^ 2^ 2 1 + (-0.1656068,0)0^ 3^ 0 3 + "
"(-0.4796778,0)3^ 3 + (-0.0454063,0)1^ 2^ 0 3 + "
"(-0.174073,0)1^ 3^ 1 3 + (-0.0454063,0)0^ 2^ 1 3 + "
"(0.1202005,0)0^ 1^ 1 0 + (0.0454063,0)0^ 2^ 3 1 + "
"(0.174073,0)1^ 3^ 3 1 + (0.1656068,0)2^ 1^ 1 2 + "
"(-0.0454063,0)2^ 1^ 3 0 + (-0.1202005,0)2^ 3^ 2 3 + "
"(0.1202005,0)2^ 3^ 3 2 + (-0.168336,0)0^ 2^ 0 2 + "
"(0.1202005,0)3^ 2^ 2 3 + (-0.1202005,0)3^ 2^ 3 2 + "
"(0.0454063,0)1^ 3^ 2 0 + (-1.2488468,0)0^ 0 + "
"(0.0454063,0)3^ 1^ 0 2 + (-0.168336,0)2^ 0^ 2 0 + "
"(0.1656068,0)3^ 0^ 0 3 + (-0.0454063,0)2^ 0^ 3 1 + "
"(0.0454063,0)2^ 0^ 1 3 + (-1.2488468,0)2^ 2 + "
"(0.0454063,0)2^ 1^ 0 3 + (0.174073,0)3^ 1^ 1 3 + "
"(-0.4796778,0)1^ 1 + (-0.174073,0)3^ 1^ 3 1 + "
"(0.0454063,0)3^ 0^ 1 2 + (-0.1656068,0)3^ 0^ 3 0 + "
"(0.0454063,0)0^ 3^ 2 1 + (-0.1656068,0)2^ 1^ 2 1 + "
"(-0.1202005,0)0^ 1^ 0 1 + (-0.1202005,0)1^ 0^ 1 0 + "
"(0.7080241,0)");
FermionOperator op(str);
std::cout << op.toString() << "\n";
......@@ -106,6 +130,16 @@ TEST(FermionOperatorTester, checkMult) {
std::cout << op3.toString() << "\n";
}
TEST(FermionOperatorTester, checkHermitianConjugate) {
std::string src = "3^ 2^ 1 0";
FermionOperator op(src);
auto opHC = op.hermitianConjugate();
std::cout << "Operator" << "\t" << op.toString() << "\n";
std::cout << "Hermitian conjugate" << "\t" << opHC.toString() << "\n";
}
int main(int argc, char** argv) {
xacc::Initialize(argc,argv);
::testing::InitGoogleTest(&argc, argv);
......
......@@ -15,6 +15,7 @@
#include "operator_pools/QubitPool.hpp"
#include "operator_pools/SingleQubitQAOA.hpp"
#include "operator_pools/MultiQubitQAOA.hpp"
#include "operator_pools/CustomPool.hpp"
#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
......@@ -47,6 +48,9 @@ public:
auto mqaoa = std::make_shared<xacc::quantum::MultiQubitQAOA>();
context.RegisterService<xacc::quantum::OperatorPool>(mqaoa);
auto custom = std::make_shared<xacc::quantum::CustomPool>();
context.RegisterService<xacc::quantum::OperatorPool>(custom);
}
void Stop(BundleContext /*context*/) {}
......
/*******************************************************************************
* Copyright (c) 2020 UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompanies this
* distribution. The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution
*License is available at https://eclipse.org/org/documents/edl-v10.php
*
* Contributors:
* Daniel Claudino - initial API and implementation
*******************************************************************************/
#ifndef XACC_CUSTOM_POOL_HPP_
#define XACC_CUSTOM_POOL_HPP_
#include "OperatorPool.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "Observable.hpp"
#include "xacc_observable.hpp"
#include "FermionOperator.hpp"
#include "Circuit.hpp"
#include "ObservableTransform.hpp"
#include <memory>
using namespace xacc;
using namespace xacc::quantum;
namespace xacc {
namespace quantum {
// The idea of this pool is to expose the OperatorPool
// so any collection of operators can be passed
// to an algorithm
class CustomPool : public OperatorPool {
protected:
std::vector<std::shared_ptr<Observable>> pool;
public:
CustomPool() = default;
// pass a single FermionOperator, likely a sum of operators
void setOperators(const FermionOperator op) override {
pool = {std::dynamic_pointer_cast<Observable>(std::make_shared<FermionOperator>(op))};
return;
}
// pass a single PauliOperator, likely a sum of operators
void setOperators(const PauliOperator op) override {
pool = {std::dynamic_pointer_cast<Observable>(std::make_shared<PauliOperator>(op))};
return;
}
// pass a sum of Pauli/FermionOperators as shared_ptr<Observable>
// from getObservable
void setOperators(const std::shared_ptr<Observable> op) override {
std::shared_ptr<Observable> obs;
if (op->toString().find("^") != std::string::npos) {
auto jw = xacc::getService<ObservableTransform>("jw");
if (std::dynamic_pointer_cast<FermionOperator>(op)) {
obs = jw->transform(op);
} else {
auto fermionOp = xacc::quantum::getObservable("fermion", op->toString());
obs = jw->transform(std::dynamic_pointer_cast<Observable>(fermionOp));
}
} else if (op->toString().find("X") != std::string::npos
|| op->toString().find("Y") != std::string::npos
|| op->toString().find("Z") != std::string::npos
&& !std::dynamic_pointer_cast<PauliOperator>(op)){
auto pauliOp = xacc::quantum::getObservable("pauli", op->toString());
obs = std::dynamic_pointer_cast<Observable>(pauliOp);
} else {
pool = {op};
}
pool = {obs};
return;
}
// pass a vector of FermionOperator, likely a sum of operators
void setOperators(const std::vector<FermionOperator> ops) override {
for (auto op : ops) {
pool.push_back(std::dynamic_pointer_cast<Observable>((std::make_shared<FermionOperator>(op))));
}
}
// pass a vector of PauliOperator, likely a sum of operators
void setOperators(const std::vector<PauliOperator> ops) override {
for (auto op : ops) {
pool.push_back(std::dynamic_pointer_cast<Observable>((std::make_shared<PauliOperator>(op))));
}
}
bool optionalParameters(const HeterogeneousMap parameters) override {
return true;
}
// generate the pool
std::vector<std::shared_ptr<Observable>> generate(const int &nQubits) override {
if(std::dynamic_pointer_cast<PauliOperator>(pool[0])){
return pool;
} else {
std::vector<std::shared_ptr<Observable>> jwPool;
auto jw = xacc::getService<ObservableTransform>("jw");
for(auto op : pool){
jwPool.push_back(jw->transform(op));
}
return jwPool;
}
}
std::string operatorString(const int index) override {
return pool[index]->toString();
}
std::shared_ptr<CompositeInstruction>
getOperatorInstructions(const int opIdx, const int varIdx) const override {
// Instruction service for the operator to be added to the ansatz
auto gate = std::dynamic_pointer_cast<quantum::Circuit>(
xacc::getService<Instruction>("exp_i_theta"));
// Create instruction for new operator
std::shared_ptr<Observable> pauliOp;
if (std::dynamic_pointer_cast<PauliOperator>(pool[opIdx])) {
pauliOp = pool[opIdx];
} else {
pauliOp = xacc::getService<ObservableTransform>("jw")->transform(pool[opIdx]);
}
gate->expand(
{std::make_pair("pauli", pauliOp->toString()),
std::make_pair("param_id", "x" + std::to_string(varIdx))
});
return gate;
}
const std::string name() const override { return "custom-pool"; }
const std::string description() const override { return ""; }
};
} // namespace quantum
} // namespace xacc
#endif
\ No newline at end of file
......@@ -147,8 +147,7 @@ xacc::info(std::to_string(varIdx));
// Create instruction for new operator
gate->expand(
{std::make_pair("pauli", pool[opIdx]->toString()),
std::make_pair("param_id", "x" + std::to_string(varIdx)),
std::make_pair("no-i", true)});
std::make_pair("param_id", "x" + std::to_string(varIdx))});
return gate;
......
......@@ -98,8 +98,7 @@ public:
// Create instruction for new operator
mixerInstructions->expand(
{std::make_pair("pauli", pool[opIdx]->toString()),
std::make_pair("param_id", "x" + std::to_string(varIdx))
});
std::make_pair("param_id", "x" + std::to_string(varIdx))});
return mixerInstructions;
......
......@@ -73,11 +73,8 @@ public:
// spin-adapted singles
FermionOperator fermiOp;
fermiOp = FermionOperator({{aa, 1}, {ia, 0}}, 0.5);
fermiOp -= FermionOperator({{ia, 1}, {aa, 0}}, 0.5);
fermiOp += FermionOperator({{ab, 1}, {ib, 0}}, 0.5);
fermiOp -= FermionOperator({{ib, 1}, {ab, 0}}, 0.5);
fermiOp -= fermiOp.hermitianConjugate();
pool.push_back(std::dynamic_pointer_cast<Observable>(std::make_shared<FermionOperator>(fermiOp)));
}
......@@ -98,38 +95,21 @@ public:
int bb = b + _nOccupied + _nOrbs;
FermionOperator fermiOp;
fermiOp = FermionOperator({{aa, 1}, {ia, 0}, {ba, 1}, {ja, 0}}, 2.0 / std::sqrt(24.0));
fermiOp -= FermionOperator({{ja, 1}, {ba, 0}, {ia, 1}, {aa, 0}}, 2.0 / std::sqrt(24.0));
fermiOp = FermionOperator({{aa, 1}, {ia, 0}, {ba, 1}, {ja, 0}}, 2.0 / std::sqrt(24.0));
fermiOp += FermionOperator({{ab, 1}, {ib, 0}, {bb, 1}, {jb, 0}}, 2.0 / std::sqrt(24.0));
fermiOp -= FermionOperator({{jb, 1}, {bb