Commit 176c2804 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

update qite demo to show of openfermion integration, chemistry to show off...


update qite demo to show of openfermion integration, chemistry to show off scikit-quant integration. add set_shots to python api

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 6452b254
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
from qcor import *

@qjit
def ghz(q : qreg):
    first = q.head()
    H(first)
    for i in range(q.size()-1):
        X.ctrl([q[i]], q[i+1])

    Measure(q)

set_qpu('ibm:ibmq_paris')
set_shots(100)
q = qalloc(6)

ghz(q)

counts = q.counts()
for bit, count in counts.items():
    print(bit, ": ", count)

ghz.print_kernel(q)
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ H 0.0 0.0 .7474)#";
      },
      2);

  optimizer = createOptimizer("skquant");

  auto [ground_energy2, opt_params2] = optimizer->optimize(one_qubit_opt_function);
  print("Energy: ", ground_energy2);

+7 −5
Original line number Diff line number Diff line
# Goals here are to just show the API, that is similar to C++
# and to show off 3rd party integration.

from qcor import *
from openfermion.ops import QubitOperator as QOp

@qjit
def state_prep(q : qreg):
@@ -6,14 +10,12 @@ def state_prep(q : qreg):

qsearch_optimizer = createTransformation("qsearch")

observable = -2.1433 * X(0) * X(1) - 2.1433 * Y(0) * Y(1) + \
                    .21829 * Z(0) - 6.125 * Z(1) + 5.907


observable = QOp('', 5.907) + QOp('Y0 Y1', -2.1433) + \
                QOp('X0 X1', -2.1433) + QOp('Z0', .21829) + QOp('Z1', -6.125) 
n_steps = 5
step_size = 0.1

problemModel = QuaSiMo.ModelFactory.createModel(state_prep, observable, 2, 0)
problemModel = QuaSiMo.ModelFactory.createModel(state_prep, observable, 2)
workflow = QuaSiMo.getWorkflow("qite", {"steps": n_steps,
                           "step-size":step_size, "circuit-optimizer": qsearch_optimizer})

+1 −0
Original line number Diff line number Diff line
@@ -510,6 +510,7 @@ PYBIND11_MODULE(_pyqcor, m) {
      py::arg("placement_name"), "Set the placement strategy.");

  m.def("qalloc", &::qalloc, py::return_value_policy::reference, "");
  m.def("set_shots", &qcor::set_shots, "");
  py::class_<xacc::internal_compiler::qubit>(m, "qubit", "");
  py::class_<xacc::internal_compiler::qreg>(m, "qreg", "")
      .def("size", &xacc::internal_compiler::qreg::size, "")