Loading python/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ endif(APPLE) file(GLOB SRC *.cpp) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC . ${CMAKE_SOURCE_DIR}/lib/qsim ${Python_INCLUDE_DIRS} ${XACC_ROOT}/include/pybind11/include) set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "") Loading python/examples/qsim_example.py +13 −3 Original line number Diff line number Diff line Loading @@ -3,7 +3,17 @@ from pathlib import Path sys.path.insert(1, str(Path.home()) + '/.xacc') from qcor import * # Get the NLOpt Optimzier observable = X(0)*X(1) + Z(0) print("Hamiltonian = ", observable.toString()) # Time-dependent Hamiltonian: # Returns the Pauli operators at a time point. def td_hamiltonian(t): omega = 1.0 print("HOWDY: Python callback") return X(0) + X(1) + X(2) # This is for testing-purposes only observable = X(0)*X(1) + Z(0) + Z(1) print("observable = ", observable.toString()) optimizer = createOptimizer('nlopt') model = qsim.ModelBuilder.createModel(observable, td_hamiltonian) No newline at end of file python/py-qcor.cpp +27 −3 Original line number Diff line number Diff line #include "qcor/qcor_optimizer.hpp" #include "base/qcor_qsim.hpp" #include <pybind11/functional.h> #include <pybind11/pybind11.h> namespace py = pybind11; PYBIND11_MODULE(_pyqcor, m) { Loading @@ -22,5 +22,29 @@ PYBIND11_MODULE(_pyqcor, m) { py::arg("name"), py::arg("p") = py::dict(), py::return_value_policy::reference, "Return the Optimizer with given name."); { py::module qsim = m.def_submodule("qsim", "QCOR's python qsim submodule"); } // qsim sub-module bindings: { py::module qsim = m.def_submodule("qsim", "QCOR's python qsim submodule"); // QuantumSimulationModel bindings: py::class_<qcor::qsim::QuantumSimulationModel>( qsim, "QuantumSimulationModel", "The QuantumSimulationModel captures the quantum simulation problem " "description.") .def(py::init<>()); // ModelBuilder bindings: py::class_<qcor::qsim::ModelBuilder>( qsim, "ModelBuilder", "The ModelBuilder interface provides methods to " "construct qsim problem models.") .def(py::init<>()) .def( "createModel", [](qcor::PauliOperator &obs, qcor::qsim::TdObservable ham_func) { return qcor::qsim::ModelBuilder::createModel(obs, ham_func); }, "Return the Model for a time-dependent problem."); } } Loading
python/CMakeLists.txt +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ endif(APPLE) file(GLOB SRC *.cpp) add_library(${LIBRARY_NAME} SHARED ${SRC}) target_include_directories(${LIBRARY_NAME} PUBLIC . ${CMAKE_SOURCE_DIR}/lib/qsim ${Python_INCLUDE_DIRS} ${XACC_ROOT}/include/pybind11/include) set_target_properties(${LIBRARY_NAME} PROPERTIES PREFIX "") Loading
python/examples/qsim_example.py +13 −3 Original line number Diff line number Diff line Loading @@ -3,7 +3,17 @@ from pathlib import Path sys.path.insert(1, str(Path.home()) + '/.xacc') from qcor import * # Get the NLOpt Optimzier observable = X(0)*X(1) + Z(0) print("Hamiltonian = ", observable.toString()) # Time-dependent Hamiltonian: # Returns the Pauli operators at a time point. def td_hamiltonian(t): omega = 1.0 print("HOWDY: Python callback") return X(0) + X(1) + X(2) # This is for testing-purposes only observable = X(0)*X(1) + Z(0) + Z(1) print("observable = ", observable.toString()) optimizer = createOptimizer('nlopt') model = qsim.ModelBuilder.createModel(observable, td_hamiltonian) No newline at end of file
python/py-qcor.cpp +27 −3 Original line number Diff line number Diff line #include "qcor/qcor_optimizer.hpp" #include "base/qcor_qsim.hpp" #include <pybind11/functional.h> #include <pybind11/pybind11.h> namespace py = pybind11; PYBIND11_MODULE(_pyqcor, m) { Loading @@ -22,5 +22,29 @@ PYBIND11_MODULE(_pyqcor, m) { py::arg("name"), py::arg("p") = py::dict(), py::return_value_policy::reference, "Return the Optimizer with given name."); { py::module qsim = m.def_submodule("qsim", "QCOR's python qsim submodule"); } // qsim sub-module bindings: { py::module qsim = m.def_submodule("qsim", "QCOR's python qsim submodule"); // QuantumSimulationModel bindings: py::class_<qcor::qsim::QuantumSimulationModel>( qsim, "QuantumSimulationModel", "The QuantumSimulationModel captures the quantum simulation problem " "description.") .def(py::init<>()); // ModelBuilder bindings: py::class_<qcor::qsim::ModelBuilder>( qsim, "ModelBuilder", "The ModelBuilder interface provides methods to " "construct qsim problem models.") .def(py::init<>()) .def( "createModel", [](qcor::PauliOperator &obs, qcor::qsim::TdObservable ham_func) { return qcor::qsim::ModelBuilder::createModel(obs, ham_func); }, "Return the Model for a time-dependent problem."); } }