Loading examples/fermi/fermi_op.cpp +115 −76 Original line number Diff line number Diff line #include "qcor.hpp" #include <iomanip> using namespace qcor; __qpu__ void ansatz(qreg q, double theta) { X(q[0]); Loading @@ -24,31 +23,50 @@ __qpu__ void ansatz(qreg q, double theta) { int main(int argc, char **argv) { auto q = qalloc(4); auto H = -0.165606823582*adag(1)*adag(2)*a(1)*a(2) + 0.120200490713*adag(1)*adag(0)*a(0)*a(1) + -0.0454063328691*adag(0)*adag(3)*a(1)*a(2) + 0.168335986252*adag(2)*adag(0)*a(0)*a(2) + 0.0454063328691*adag(1)*adag(2)*a(3)*a(0) + 0.168335986252*adag(0)*adag(2)*a(2)*a(0) + 0.165606823582*adag(0)*adag(3)*a(3)*a(0) - 0.0454063328691*adag(3)*adag(0)*a(2)*a(1) + -0.0454063328691*adag(1)*adag(3)*a(0)*a(2) - 0.0454063328691*adag(3)*adag(1)*a(2)*a(0) + 0.165606823582*adag(1)*adag(2)*a(2)*a(1) - 0.165606823582*adag(0)*adag(3)*a(0)*a(3) -0.0454063328691*adag(1)*adag(2)*a(0)*a(3) - 0.479677813134*adag(3)*a(3) -0.174072892497*adag(1)*adag(3)*a(1)*a(3) - 0.0454063328691*adag(0)*adag(2)*a(1)*a(3) + 0.120200490713*adag(0)*adag(1)*a(1)*a(0) + 0.0454063328691*adag(0)*adag(2)*a(3)*a(1) + 0.174072892497*adag(1)*adag(3)*a(3)*a(1) + 0.165606823582*adag(2)*adag(1)*a(1)*a(2) + -0.0454063328691*adag(2)*adag(1)*a(3)*a(0) - 0.120200490713*adag(2)*adag(3)*a(2)*a(3) + 0.120200490713*adag(2)*adag(3)*a(3)*a(2) - 0.168335986252*adag(0)*adag(2)*a(0)*a(2) + 0.120200490713*adag(3)*adag(2)*a(2)*a(3) - 0.120200490713*adag(3)*adag(2)*a(3)*a(2) + 0.0454063328691*adag(1)*adag(3)*a(2)*a(0) - 1.2488468038*adag(0)*a(0) + 0.0454063328691*adag(3)*adag(1)*a(0)*a(2) - 0.168335986252*adag(2)*adag(0)*a(2)*a(0) + 0.0165606823582*adag(3)*adag(0)*a(0)*a(3) + 2.0*0.0454063328691*adag(2)*adag(0)*a(1)*a(3) -1.2488468038*adag(2)*a(2) + 0.0454063328691*adag(2)*adag(1 )*a(0)*a(3) + 0.174072892497*adag(3)*adag(1)*a(1)*a(3) - 0.174072892497*adag(3)*adag(1)*a(3)*a(1) + 0.0454063328691*adag(3)*adag(0)*a(1)*a(2) - 0.479677813134*adag(1)*a(1) -0.165606823582*adag(3)*adag(0)*a(3)*a(0) + 0.0454063328691*adag(0)*adag(3)*a(2)*a(1) + -0.165606823582*adag(2)*adag(1)*a(2)*a(1) - 0.120200490713*adag(0)*adag(1)*a(0)*a(1) + auto H = -0.165606823582 * adag(1) * adag(2) * a(1) * a(2) + 0.120200490713 * adag(1) * adag(0) * a(0) * a(1) + -0.0454063328691 * adag(0) * adag(3) * a(1) * a(2) + 0.168335986252 * adag(2) * adag(0) * a(0) * a(2) + 0.0454063328691 * adag(1) * adag(2) * a(3) * a(0) + 0.168335986252 * adag(0) * adag(2) * a(2) * a(0) + 0.165606823582 * adag(0) * adag(3) * a(3) * a(0) - 0.0454063328691 * adag(3) * adag(0) * a(2) * a(1) + -0.0454063328691 * adag(1) * adag(3) * a(0) * a(2) - 0.0454063328691 * adag(3) * adag(1) * a(2) * a(0) + 0.165606823582 * adag(1) * adag(2) * a(2) * a(1) - 0.165606823582 * adag(0) * adag(3) * a(0) * a(3) - 0.0454063328691 * adag(1) * adag(2) * a(0) * a(3) - 0.479677813134 * adag(3) * a(3) - 0.174072892497 * adag(1) * adag(3) * a(1) * a(3) - 0.0454063328691 * adag(0) * adag(2) * a(1) * a(3) + 0.120200490713 * adag(0) * adag(1) * a(1) * a(0) + 0.0454063328691 * adag(0) * adag(2) * a(3) * a(1) + 0.174072892497 * adag(1) * adag(3) * a(3) * a(1) + 0.165606823582 * adag(2) * adag(1) * a(1) * a(2) + -0.0454063328691 * adag(2) * adag(1) * a(3) * a(0) - 0.120200490713 * adag(2) * adag(3) * a(2) * a(3) + 0.120200490713 * adag(2) * adag(3) * a(3) * a(2) - 0.168335986252 * adag(0) * adag(2) * a(0) * a(2) + 0.120200490713 * adag(3) * adag(2) * a(2) * a(3) - 0.120200490713 * adag(3) * adag(2) * a(3) * a(2) + 0.0454063328691 * adag(1) * adag(3) * a(2) * a(0) - 1.2488468038 * adag(0) * a(0) + 0.0454063328691 * adag(3) * adag(1) * a(0) * a(2) - 0.168335986252 * adag(2) * adag(0) * a(2) * a(0) + 0.0165606823582 * adag(3) * adag(0) * a(0) * a(3) + 2.0 * 0.0454063328691 * adag(2) * adag(0) * a(1) * a(3) - 1.2488468038 * adag(2) * a(2) + 0.0454063328691 * adag(2) * adag(1) * a(0) * a(3) + 0.174072892497 * adag(3) * adag(1) * a(1) * a(3) - 0.174072892497 * adag(3) * adag(1) * a(3) * a(1) + 0.0454063328691 * adag(3) * adag(0) * a(1) * a(2) - 0.479677813134 * adag(1) * a(1) - 0.165606823582 * adag(3) * adag(0) * a(3) * a(0) + 0.0454063328691 * adag(0) * adag(3) * a(2) * a(1) + -0.165606823582 * adag(2) * adag(1) * a(2) * a(1) - 0.120200490713 * adag(0) * adag(1) * a(0) * a(1) + -0.120200490713 * adag(1) * adag(0) * a(1) * a(0) + 0.7080240981; std::cout<<H.toString()<<std::endl; auto objective = qcor::createObjectiveFunction("vqe", ansatz, H); auto optimizer = qcor::createOptimizer("nlopt"); qcor::OptFunction f( Loading @@ -62,29 +80,50 @@ int main(int argc, char **argv){ return 0; } /* auto H = createObservable("fermion", "(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 + " "(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 + " "(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 + " "(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 + " "(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 + " "(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 + " "(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 + " "(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 + " "(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 + " "(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 + " "(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 + " "(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 + " "(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 + " "(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 + " "(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 + " "(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 + " "(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 + " "(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 + " "(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 + " "(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 + " "(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 + " "(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + (0.7080240981,0)"); auto H = createObservable("fermion", "(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 + " "(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 + " "(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 + " "(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 + " "(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 + " "(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 + " "(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 + " "(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 + " "(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 + " "(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 + " "(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 + " "(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 + " "(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 + " "(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 + " "(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 + " "(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 + " "(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 + " "(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 + " "(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 + " "(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 + " "(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 + " "(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + (0.7080240981,0)"); */ No newline at end of file examples/fermi/mixed_op.cpp +21 −22 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ using namespace qcor; __qpu__ void ansatz(qreg q, double theta, std::shared_ptr<xacc::Observable> H) { X(q[0]); X(q[1]); Loading Loading @@ -39,7 +38,7 @@ int main(int argc, char **argv){ auto H = X(0) + X(0) * a(1) + adag(1) * X(0) + X(0) * adag(0) * adag(1); std::cout<<"ARE WE HERE??"<<std::endl; std::cout << "Mixed sum and products: " << std::endl; std::cout << H.toString() << std::endl; } No newline at end of file runtime/CMakeLists.txt +0 −4 Original line number Diff line number Diff line Loading @@ -6,11 +6,7 @@ add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC . qrt) <<<<<<< HEAD target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate qrt xacc::pauli) ======= target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate qrt xacc::pauli xacc::fermion) >>>>>>> init commit xacc_configure_library_rpath(${LIBRARY_NAME}) Loading runtime/qcor.cpp +13 −11 Original line number Diff line number Diff line Loading @@ -2,11 +2,12 @@ #include "Optimizer.hpp" #include "qalloc.hpp" #include "qrt.hpp" #include "xacc.hpp" #include "xacc_quantum_gate_api.hpp" #include "xacc_service.hpp" #include "qalloc.hpp" #include "qrt.hpp" #include <memory> namespace qcor { void set_verbose(bool verbose) { xacc::set_verbose(verbose); } Loading Loading @@ -61,15 +62,16 @@ double observe(std::shared_ptr<CompositeInstruction> program, Observable &obs, } } // namespace __internal__ std::shared_ptr<Observable> transform(Observable &obs, std::string transf){ if (transf != "jw"){ throw "transform: " + transf + " not defined! Using Jordan-Wigner (`jw`)"; } auto obsv = xacc::as_shared_ptr(&obs); return (*xacc::getService<xacc::ObservableTransform>("jw")).transform(obsv); PauliOperator transform(FermionOperator &obs, std::string transf) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); auto obsv = std::make_shared<FermionOperator>(obs); auto terms = std::dynamic_pointer_cast<PauliOperator>( xacc::getService<xacc::ObservableTransform>(transf)->transform(obsv)); return *terms; } std::shared_ptr<xacc::Optimizer> createOptimizer(const char *type, std::shared_ptr<xacc::Optimizer> createOptimizer(const std::string &type, HeterogeneousMap &&options) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); Loading @@ -82,13 +84,13 @@ std::shared_ptr<xacc::Observable> createObservable(const std::string &repr) { return xacc::quantum::getObservable("pauli", std::string(repr)); } std::shared_ptr<Observable> createObservable(const std::string& type, const std::string& repr) { std::shared_ptr<Observable> createObservable(const std::string &type, const std::string &repr) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); return xacc::quantum::getObservable(type, std::string(repr)); } std::shared_ptr<xacc::CompositeInstruction> compile(const std::string &src) { return xacc::getCompiler("xasm")->compile(src)->getComposites()[0]; } Loading runtime/qcor.hpp +98 −96 Original line number Diff line number Diff line Loading @@ -11,13 +11,12 @@ #include "Observable.hpp" #include "Optimizer.hpp" #include "qalloc" #include "xacc_internal_compiler.hpp" #include "PauliOperator.hpp" #include "FermionOperator.hpp" #include "ObservableTransform.hpp" #include "PauliOperator.hpp" #include "qalloc" #include "qrt.hpp" #include "xacc_internal_compiler.hpp" namespace qcor { Loading @@ -29,15 +28,9 @@ using CompositeInstruction = xacc::CompositeInstruction; using PauliOperator = xacc::quantum::PauliOperator; using FermionOperator = xacc::quantum::FermionOperator; PauliOperator X(int idx){ return PauliOperator({{idx, "X"}}); } PauliOperator Y(int idx){ return PauliOperator({{idx, "Y"}}); } PauliOperator Z(int idx){ return PauliOperator({{idx, "Z"}}); } PauliOperator X(int idx) { return PauliOperator({{idx, "X"}}); } PauliOperator Y(int idx) { return PauliOperator({{idx, "Y"}}); } PauliOperator Z(int idx) { return PauliOperator({{idx, "Z"}}); } PauliOperator SP(int idx) { std::complex<double> imag(0.0, 1.0); return X(idx) + imag * Y(idx); Loading Loading @@ -66,69 +59,84 @@ PauliOperator allZs(const int nQubits) { // transform FermionOperator to PauliOperator PauliOperator transform(FermionOperator &obs, std::string transf = "jw"); template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(T coeff, PauliOperator &op) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(PauliOperator &op, T coeff) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(T coeff, PauliOperator &op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(PauliOperator &op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(T coeff, FermionOperator &op) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(FermionOperator &op, T coeff) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(T coeff, FermionOperator &op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(FermionOperator &op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(T coeff, PauliOperator &&op) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(PauliOperator &&op, T coeff) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(T coeff, PauliOperator &&op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(PauliOperator &&op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(T coeff, FermionOperator &&op) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(FermionOperator &&op, T coeff) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(T coeff, FermionOperator &&op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(FermionOperator &&op, T coeff) { return -1.0 * coeff + op; } Loading Loading @@ -173,9 +181,6 @@ PauliOperator operator*(FermionOperator &fop, PauliOperator &pop){ return pop * pfop; } class ResultsBuffer { public: xacc::internal_compiler::qreg q_buffer; Loading Loading @@ -238,8 +243,6 @@ kernel_as_composite_instruction(QuantumKernel &k, Args... args) { // #endif } // Observe the given kernel, and return the expected value double observe(std::shared_ptr<CompositeInstruction> program, std::shared_ptr<Observable> obs, Loading Loading @@ -413,12 +416,11 @@ createOptimizer(const std::string& type, HeterogeneousMap &&options = {}); // Create an observable from a string representation std::shared_ptr<Observable> createObservable(const std::string &repr); std::shared_ptr<Observable> createObservable(const std::string& type, const std::string& repr); std::shared_ptr<Observable> createObservable(const std::string &type, const std::string &repr); std::shared_ptr<ObjectiveFunction> createObjectiveFunction( const std::string &obj_name, std::shared_ptr<CompositeInstruction> kernel, std::shared_ptr<Observable> observable, HeterogeneousMap &&options = {}) { std::cout<<"shared_ptr OBSERVABLE CALLED"<<std::endl; std::shared_ptr<Observable> observable, HeterogeneousMap &&options = {}) { auto obj_func = qcor::__internal__::get_objective(obj_name); obj_func->initialize(observable.get(), kernel); obj_func->set_options(options); Loading Loading
examples/fermi/fermi_op.cpp +115 −76 Original line number Diff line number Diff line #include "qcor.hpp" #include <iomanip> using namespace qcor; __qpu__ void ansatz(qreg q, double theta) { X(q[0]); Loading @@ -24,31 +23,50 @@ __qpu__ void ansatz(qreg q, double theta) { int main(int argc, char **argv) { auto q = qalloc(4); auto H = -0.165606823582*adag(1)*adag(2)*a(1)*a(2) + 0.120200490713*adag(1)*adag(0)*a(0)*a(1) + -0.0454063328691*adag(0)*adag(3)*a(1)*a(2) + 0.168335986252*adag(2)*adag(0)*a(0)*a(2) + 0.0454063328691*adag(1)*adag(2)*a(3)*a(0) + 0.168335986252*adag(0)*adag(2)*a(2)*a(0) + 0.165606823582*adag(0)*adag(3)*a(3)*a(0) - 0.0454063328691*adag(3)*adag(0)*a(2)*a(1) + -0.0454063328691*adag(1)*adag(3)*a(0)*a(2) - 0.0454063328691*adag(3)*adag(1)*a(2)*a(0) + 0.165606823582*adag(1)*adag(2)*a(2)*a(1) - 0.165606823582*adag(0)*adag(3)*a(0)*a(3) -0.0454063328691*adag(1)*adag(2)*a(0)*a(3) - 0.479677813134*adag(3)*a(3) -0.174072892497*adag(1)*adag(3)*a(1)*a(3) - 0.0454063328691*adag(0)*adag(2)*a(1)*a(3) + 0.120200490713*adag(0)*adag(1)*a(1)*a(0) + 0.0454063328691*adag(0)*adag(2)*a(3)*a(1) + 0.174072892497*adag(1)*adag(3)*a(3)*a(1) + 0.165606823582*adag(2)*adag(1)*a(1)*a(2) + -0.0454063328691*adag(2)*adag(1)*a(3)*a(0) - 0.120200490713*adag(2)*adag(3)*a(2)*a(3) + 0.120200490713*adag(2)*adag(3)*a(3)*a(2) - 0.168335986252*adag(0)*adag(2)*a(0)*a(2) + 0.120200490713*adag(3)*adag(2)*a(2)*a(3) - 0.120200490713*adag(3)*adag(2)*a(3)*a(2) + 0.0454063328691*adag(1)*adag(3)*a(2)*a(0) - 1.2488468038*adag(0)*a(0) + 0.0454063328691*adag(3)*adag(1)*a(0)*a(2) - 0.168335986252*adag(2)*adag(0)*a(2)*a(0) + 0.0165606823582*adag(3)*adag(0)*a(0)*a(3) + 2.0*0.0454063328691*adag(2)*adag(0)*a(1)*a(3) -1.2488468038*adag(2)*a(2) + 0.0454063328691*adag(2)*adag(1 )*a(0)*a(3) + 0.174072892497*adag(3)*adag(1)*a(1)*a(3) - 0.174072892497*adag(3)*adag(1)*a(3)*a(1) + 0.0454063328691*adag(3)*adag(0)*a(1)*a(2) - 0.479677813134*adag(1)*a(1) -0.165606823582*adag(3)*adag(0)*a(3)*a(0) + 0.0454063328691*adag(0)*adag(3)*a(2)*a(1) + -0.165606823582*adag(2)*adag(1)*a(2)*a(1) - 0.120200490713*adag(0)*adag(1)*a(0)*a(1) + auto H = -0.165606823582 * adag(1) * adag(2) * a(1) * a(2) + 0.120200490713 * adag(1) * adag(0) * a(0) * a(1) + -0.0454063328691 * adag(0) * adag(3) * a(1) * a(2) + 0.168335986252 * adag(2) * adag(0) * a(0) * a(2) + 0.0454063328691 * adag(1) * adag(2) * a(3) * a(0) + 0.168335986252 * adag(0) * adag(2) * a(2) * a(0) + 0.165606823582 * adag(0) * adag(3) * a(3) * a(0) - 0.0454063328691 * adag(3) * adag(0) * a(2) * a(1) + -0.0454063328691 * adag(1) * adag(3) * a(0) * a(2) - 0.0454063328691 * adag(3) * adag(1) * a(2) * a(0) + 0.165606823582 * adag(1) * adag(2) * a(2) * a(1) - 0.165606823582 * adag(0) * adag(3) * a(0) * a(3) - 0.0454063328691 * adag(1) * adag(2) * a(0) * a(3) - 0.479677813134 * adag(3) * a(3) - 0.174072892497 * adag(1) * adag(3) * a(1) * a(3) - 0.0454063328691 * adag(0) * adag(2) * a(1) * a(3) + 0.120200490713 * adag(0) * adag(1) * a(1) * a(0) + 0.0454063328691 * adag(0) * adag(2) * a(3) * a(1) + 0.174072892497 * adag(1) * adag(3) * a(3) * a(1) + 0.165606823582 * adag(2) * adag(1) * a(1) * a(2) + -0.0454063328691 * adag(2) * adag(1) * a(3) * a(0) - 0.120200490713 * adag(2) * adag(3) * a(2) * a(3) + 0.120200490713 * adag(2) * adag(3) * a(3) * a(2) - 0.168335986252 * adag(0) * adag(2) * a(0) * a(2) + 0.120200490713 * adag(3) * adag(2) * a(2) * a(3) - 0.120200490713 * adag(3) * adag(2) * a(3) * a(2) + 0.0454063328691 * adag(1) * adag(3) * a(2) * a(0) - 1.2488468038 * adag(0) * a(0) + 0.0454063328691 * adag(3) * adag(1) * a(0) * a(2) - 0.168335986252 * adag(2) * adag(0) * a(2) * a(0) + 0.0165606823582 * adag(3) * adag(0) * a(0) * a(3) + 2.0 * 0.0454063328691 * adag(2) * adag(0) * a(1) * a(3) - 1.2488468038 * adag(2) * a(2) + 0.0454063328691 * adag(2) * adag(1) * a(0) * a(3) + 0.174072892497 * adag(3) * adag(1) * a(1) * a(3) - 0.174072892497 * adag(3) * adag(1) * a(3) * a(1) + 0.0454063328691 * adag(3) * adag(0) * a(1) * a(2) - 0.479677813134 * adag(1) * a(1) - 0.165606823582 * adag(3) * adag(0) * a(3) * a(0) + 0.0454063328691 * adag(0) * adag(3) * a(2) * a(1) + -0.165606823582 * adag(2) * adag(1) * a(2) * a(1) - 0.120200490713 * adag(0) * adag(1) * a(0) * a(1) + -0.120200490713 * adag(1) * adag(0) * a(1) * a(0) + 0.7080240981; std::cout<<H.toString()<<std::endl; auto objective = qcor::createObjectiveFunction("vqe", ansatz, H); auto optimizer = qcor::createOptimizer("nlopt"); qcor::OptFunction f( Loading @@ -62,29 +80,50 @@ int main(int argc, char **argv){ return 0; } /* auto H = createObservable("fermion", "(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 + " "(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 + " "(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 + " "(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 + " "(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 + " "(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 + " "(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 + " "(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 + " "(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 + " "(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 + " "(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 + " "(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 + " "(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 + " "(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 + " "(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 + " "(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 + " "(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 + " "(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 + " "(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 + " "(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 + " "(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 + " "(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + (0.7080240981,0)"); auto H = createObservable("fermion", "(-0.165606823582,-0) 1^ 2^ 1 2 + (0.120200490713,0) 1^ 0^ 0 1 + " "(-0.0454063328691,-0) 0^ 3^ 1 2 + (0.168335986252,0) 2^ 0^ 0 2 + " "(0.0454063328691,0) 1^ 2^ 3 0 + (0.168335986252,0) 0^ 2^ 2 0 + " "(0.165606823582,0) 0^ 3^ 3 0 + (-0.0454063328691,-0) 3^ 0^ 2 1 + " "(-0.0454063328691,-0) 1^ 3^ 0 2 + (-0.0454063328691,-0) 3^ 1^ 2 0 + " "(0.165606823582,0) 1^ 2^ 2 1 + (-0.165606823582,-0) 0^ 3^ 0 3 + " "(-0.479677813134,-0) 3^ 3 + (-0.0454063328691,-0) 1^ 2^ 0 3 + " "(-0.174072892497,-0) 1^ 3^ 1 3 + (-0.0454063328691,-0) 0^ 2^ 1 3 + " "(0.120200490713,0) 0^ 1^ 1 0 + (0.0454063328691,0) 0^ 2^ 3 1 + " "(0.174072892497,0) 1^ 3^ 3 1 + (0.165606823582,0) 2^ 1^ 1 2 + " "(-0.0454063328691,-0) 2^ 1^ 3 0 + (-0.120200490713,-0) 2^ 3^ 2 3 + " "(0.120200490713,0) 2^ 3^ 3 2 + (-0.168335986252,-0) 0^ 2^ 0 2 + " "(0.120200490713,0) 3^ 2^ 2 3 + (-0.120200490713,-0) 3^ 2^ 3 2 + " "(0.0454063328691,0) 1^ 3^ 2 0 + (-1.2488468038,-0) 0^ 0 + " "(0.0454063328691,0) 3^ 1^ 0 2 + (-0.168335986252,-0) 2^ 0^ 2 0 + " "(0.165606823582,0) 3^ 0^ 0 3 + (-0.0454063328691,-0) 2^ 0^ 3 1 + " "(0.0454063328691,0) 2^ 0^ 1 3 + (-1.2488468038,-0) 2^ 2 + " "(0.0454063328691,0) 2^ 1^ 0 3 + (0.174072892497,0) 3^ 1^ 1 3 + " "(-0.479677813134,-0) 1^ 1 + (-0.174072892497,-0) 3^ 1^ 3 1 + " "(0.0454063328691,0) 3^ 0^ 1 2 + (-0.165606823582,-0) 3^ 0^ 3 0 + " "(0.0454063328691,0) 0^ 3^ 2 1 + (-0.165606823582,-0) 2^ 1^ 2 1 + " "(-0.120200490713,-0) 0^ 1^ 0 1 + (-0.120200490713,-0) 1^ 0^ 1 0 + (0.7080240981,0)"); */ No newline at end of file
examples/fermi/mixed_op.cpp +21 −22 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ using namespace qcor; __qpu__ void ansatz(qreg q, double theta, std::shared_ptr<xacc::Observable> H) { X(q[0]); X(q[1]); Loading Loading @@ -39,7 +38,7 @@ int main(int argc, char **argv){ auto H = X(0) + X(0) * a(1) + adag(1) * X(0) + X(0) * adag(0) * adag(1); std::cout<<"ARE WE HERE??"<<std::endl; std::cout << "Mixed sum and products: " << std::endl; std::cout << H.toString() << std::endl; } No newline at end of file
runtime/CMakeLists.txt +0 −4 Original line number Diff line number Diff line Loading @@ -6,11 +6,7 @@ add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC . qrt) <<<<<<< HEAD target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate qrt xacc::pauli) ======= target_link_libraries(${LIBRARY_NAME} PUBLIC xacc::xacc xacc::quantum_gate qrt xacc::pauli xacc::fermion) >>>>>>> init commit xacc_configure_library_rpath(${LIBRARY_NAME}) Loading
runtime/qcor.cpp +13 −11 Original line number Diff line number Diff line Loading @@ -2,11 +2,12 @@ #include "Optimizer.hpp" #include "qalloc.hpp" #include "qrt.hpp" #include "xacc.hpp" #include "xacc_quantum_gate_api.hpp" #include "xacc_service.hpp" #include "qalloc.hpp" #include "qrt.hpp" #include <memory> namespace qcor { void set_verbose(bool verbose) { xacc::set_verbose(verbose); } Loading Loading @@ -61,15 +62,16 @@ double observe(std::shared_ptr<CompositeInstruction> program, Observable &obs, } } // namespace __internal__ std::shared_ptr<Observable> transform(Observable &obs, std::string transf){ if (transf != "jw"){ throw "transform: " + transf + " not defined! Using Jordan-Wigner (`jw`)"; } auto obsv = xacc::as_shared_ptr(&obs); return (*xacc::getService<xacc::ObservableTransform>("jw")).transform(obsv); PauliOperator transform(FermionOperator &obs, std::string transf) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); auto obsv = std::make_shared<FermionOperator>(obs); auto terms = std::dynamic_pointer_cast<PauliOperator>( xacc::getService<xacc::ObservableTransform>(transf)->transform(obsv)); return *terms; } std::shared_ptr<xacc::Optimizer> createOptimizer(const char *type, std::shared_ptr<xacc::Optimizer> createOptimizer(const std::string &type, HeterogeneousMap &&options) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); Loading @@ -82,13 +84,13 @@ std::shared_ptr<xacc::Observable> createObservable(const std::string &repr) { return xacc::quantum::getObservable("pauli", std::string(repr)); } std::shared_ptr<Observable> createObservable(const std::string& type, const std::string& repr) { std::shared_ptr<Observable> createObservable(const std::string &type, const std::string &repr) { if (!xacc::isInitialized()) xacc::internal_compiler::compiler_InitializeXACC(); return xacc::quantum::getObservable(type, std::string(repr)); } std::shared_ptr<xacc::CompositeInstruction> compile(const std::string &src) { return xacc::getCompiler("xasm")->compile(src)->getComposites()[0]; } Loading
runtime/qcor.hpp +98 −96 Original line number Diff line number Diff line Loading @@ -11,13 +11,12 @@ #include "Observable.hpp" #include "Optimizer.hpp" #include "qalloc" #include "xacc_internal_compiler.hpp" #include "PauliOperator.hpp" #include "FermionOperator.hpp" #include "ObservableTransform.hpp" #include "PauliOperator.hpp" #include "qalloc" #include "qrt.hpp" #include "xacc_internal_compiler.hpp" namespace qcor { Loading @@ -29,15 +28,9 @@ using CompositeInstruction = xacc::CompositeInstruction; using PauliOperator = xacc::quantum::PauliOperator; using FermionOperator = xacc::quantum::FermionOperator; PauliOperator X(int idx){ return PauliOperator({{idx, "X"}}); } PauliOperator Y(int idx){ return PauliOperator({{idx, "Y"}}); } PauliOperator Z(int idx){ return PauliOperator({{idx, "Z"}}); } PauliOperator X(int idx) { return PauliOperator({{idx, "X"}}); } PauliOperator Y(int idx) { return PauliOperator({{idx, "Y"}}); } PauliOperator Z(int idx) { return PauliOperator({{idx, "Z"}}); } PauliOperator SP(int idx) { std::complex<double> imag(0.0, 1.0); return X(idx) + imag * Y(idx); Loading Loading @@ -66,69 +59,84 @@ PauliOperator allZs(const int nQubits) { // transform FermionOperator to PauliOperator PauliOperator transform(FermionOperator &obs, std::string transf = "jw"); template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(T coeff, PauliOperator &op) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(PauliOperator &op, T coeff) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(T coeff, PauliOperator &op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(PauliOperator &op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(T coeff, FermionOperator &op) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(FermionOperator &op, T coeff) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(T coeff, FermionOperator &op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(FermionOperator &op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(T coeff, PauliOperator &&op) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator+(PauliOperator &&op, T coeff) { return PauliOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(T coeff, PauliOperator &&op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> PauliOperator operator-(PauliOperator &&op, T coeff) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(T coeff, FermionOperator &&op) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator+(FermionOperator &&op, T coeff) { return FermionOperator(coeff) + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(T coeff, FermionOperator &&op) { return -1.0 * coeff + op; } template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type> template <typename T, typename = typename std::enable_if< std::is_arithmetic<T>::value, T>::type> FermionOperator operator-(FermionOperator &&op, T coeff) { return -1.0 * coeff + op; } Loading Loading @@ -173,9 +181,6 @@ PauliOperator operator*(FermionOperator &fop, PauliOperator &pop){ return pop * pfop; } class ResultsBuffer { public: xacc::internal_compiler::qreg q_buffer; Loading Loading @@ -238,8 +243,6 @@ kernel_as_composite_instruction(QuantumKernel &k, Args... args) { // #endif } // Observe the given kernel, and return the expected value double observe(std::shared_ptr<CompositeInstruction> program, std::shared_ptr<Observable> obs, Loading Loading @@ -413,12 +416,11 @@ createOptimizer(const std::string& type, HeterogeneousMap &&options = {}); // Create an observable from a string representation std::shared_ptr<Observable> createObservable(const std::string &repr); std::shared_ptr<Observable> createObservable(const std::string& type, const std::string& repr); std::shared_ptr<Observable> createObservable(const std::string &type, const std::string &repr); std::shared_ptr<ObjectiveFunction> createObjectiveFunction( const std::string &obj_name, std::shared_ptr<CompositeInstruction> kernel, std::shared_ptr<Observable> observable, HeterogeneousMap &&options = {}) { std::cout<<"shared_ptr OBSERVABLE CALLED"<<std::endl; std::shared_ptr<Observable> observable, HeterogeneousMap &&options = {}) { auto obj_func = qcor::__internal__::get_objective(obj_name); obj_func->initialize(observable.get(), kernel); obj_func->set_options(options); Loading