Loading README.md +5 −4 Original line number Diff line number Diff line Loading @@ -20,11 +20,12 @@ Quick Start ----------- QCOR is available via pre-built deb packages on Ubuntu Bionic (18.04) and Focal (20.04). To install on Bionic ```bash $ wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/bionic/PUBLIC-KEY.gpg | apt-key add - $ wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/bionic/aide-qc-bionic.list" > /etc/apt/sources.list.d/aide-qc-bionic.list $ apt-get update && apt-get install qcor wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/PUBLIC-KEY.gpg | sudo apt-key add - sudo wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/$(lsb_release -cs)/aide-qc.list" > /etc/apt/sources.list.d/aide-qc.list sudo apt-get update sudo apt-get install qcor ``` For Focal, replace bionic with focal in the above commands. Note that the above requires you have `lsb_release` installed (usually is, if not, `apt-get install lsb-release`). QCOR nightly docker images are available that serve up an Eclipse Theia IDE (the same IDE Gitpod uses) on port 3000. To get started, run ```bash Loading python/examples/qsim_vqe.py 0 → 100644 +31 −0 Original line number Diff line number Diff line from qcor import * # Define the deuteron hamiltonian H = -2.1433 * X(0) * X(1) - 2.1433 * \ Y(0) * Y(1) + .21829 * Z(0) - 6.125 * Z(1) + 5.907 # Define the quantum kernel by providing a # python function that is annotated with qjit for # quantum just in time compilation @qjit def ansatz(q : qreg, theta : float): X(q[0]) Ry(q[1], theta) CX(q[1], q[0]) # Create the problem model, provide the state # prep circuit, Hamiltonian and note how many qubits # and variational parameters num_params = 1 problemModel = qsim.ModelBuilder.createModel(ansatz, H, num_params) # Create the NLOpt derivative free optimizer optimizer = createOptimizer('nlopt') # Create the VQE workflow workflow = qsim.getWorkflow('vqe', {'optimizer': optimizer}) # Execute and print the result result = workflow.execute(problemModel) energy = result['energy'] print(energy) No newline at end of file python/py-qcor.cpp +33 −20 Original line number Diff line number Diff line Loading @@ -119,7 +119,6 @@ class PyObjectiveFunction : public qcor::ObjectiveFunction { PyObjectiveFunction(py::object q, qcor::PauliOperator &qq, const int n_dim, const std::string &helper_name) : py_kernel(q) { // Set the OptFunction dimensions _dim = n_dim; Loading Loading @@ -359,6 +358,20 @@ PYBIND11_MODULE(_pyqcor, m) { return qcor::qsim::ModelBuilder::createModel(obs, ham_func); }, "Return the Model for a time-dependent problem.") .def( "createModel", [](py::object py_kernel, qcor::PauliOperator &obs, const int n_params) { qcor::qsim::QuantumSimulationModel model; auto nq = obs.nBits(); auto kernel_functor = std::make_shared<qcor::PyKernelFunctor>( py_kernel, nq, n_params); model.observable = &obs; model.user_defined_ansatz = kernel_functor; return std::move(model); }, "") .def( "createModel", [](py::object py_kernel, qcor::PauliOperator &obs, Loading Loading
README.md +5 −4 Original line number Diff line number Diff line Loading @@ -20,11 +20,12 @@ Quick Start ----------- QCOR is available via pre-built deb packages on Ubuntu Bionic (18.04) and Focal (20.04). To install on Bionic ```bash $ wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/bionic/PUBLIC-KEY.gpg | apt-key add - $ wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/bionic/aide-qc-bionic.list" > /etc/apt/sources.list.d/aide-qc-bionic.list $ apt-get update && apt-get install qcor wget -qO- https://aide-qc.github.io/deploy/aide_qc/debian/PUBLIC-KEY.gpg | sudo apt-key add - sudo wget -qO- "https://aide-qc.github.io/deploy/aide_qc/debian/$(lsb_release -cs)/aide-qc.list" > /etc/apt/sources.list.d/aide-qc.list sudo apt-get update sudo apt-get install qcor ``` For Focal, replace bionic with focal in the above commands. Note that the above requires you have `lsb_release` installed (usually is, if not, `apt-get install lsb-release`). QCOR nightly docker images are available that serve up an Eclipse Theia IDE (the same IDE Gitpod uses) on port 3000. To get started, run ```bash Loading
python/examples/qsim_vqe.py 0 → 100644 +31 −0 Original line number Diff line number Diff line from qcor import * # Define the deuteron hamiltonian H = -2.1433 * X(0) * X(1) - 2.1433 * \ Y(0) * Y(1) + .21829 * Z(0) - 6.125 * Z(1) + 5.907 # Define the quantum kernel by providing a # python function that is annotated with qjit for # quantum just in time compilation @qjit def ansatz(q : qreg, theta : float): X(q[0]) Ry(q[1], theta) CX(q[1], q[0]) # Create the problem model, provide the state # prep circuit, Hamiltonian and note how many qubits # and variational parameters num_params = 1 problemModel = qsim.ModelBuilder.createModel(ansatz, H, num_params) # Create the NLOpt derivative free optimizer optimizer = createOptimizer('nlopt') # Create the VQE workflow workflow = qsim.getWorkflow('vqe', {'optimizer': optimizer}) # Execute and print the result result = workflow.execute(problemModel) energy = result['energy'] print(energy) No newline at end of file
python/py-qcor.cpp +33 −20 Original line number Diff line number Diff line Loading @@ -119,7 +119,6 @@ class PyObjectiveFunction : public qcor::ObjectiveFunction { PyObjectiveFunction(py::object q, qcor::PauliOperator &qq, const int n_dim, const std::string &helper_name) : py_kernel(q) { // Set the OptFunction dimensions _dim = n_dim; Loading Loading @@ -359,6 +358,20 @@ PYBIND11_MODULE(_pyqcor, m) { return qcor::qsim::ModelBuilder::createModel(obs, ham_func); }, "Return the Model for a time-dependent problem.") .def( "createModel", [](py::object py_kernel, qcor::PauliOperator &obs, const int n_params) { qcor::qsim::QuantumSimulationModel model; auto nq = obs.nBits(); auto kernel_functor = std::make_shared<qcor::PyKernelFunctor>( py_kernel, nq, n_params); model.observable = &obs; model.user_defined_ansatz = kernel_functor; return std::move(model); }, "") .def( "createModel", [](py::object py_kernel, qcor::PauliOperator &obs, Loading