Loading examples/qcor_demos/pnnl_tutorials/tut2/intro/chemistry_vqe.py 0 → 100644 +24 −0 Original line number Diff line number Diff line from qcor import * @qjit def ansatz(q: qreg, theta: float): X(q[0]) Ry(q[1], theta) CX(q[1], q[0]) # Define the hamiltonian H = 5.907 - 2.1433 * X(0) * X(1) - 2.1433 * Y(0) * Y(1) + .21829 * Z(0) - 6.125 * Z(1) # Define the optimization objective def obj(x : List[float]): e_at_x = ansatz.observe(H, qalloc(2), x[0]) print('E({}) = {}'.format(x[0], e_at_x)) return e_at_x # create the cobyla optimizer optimizer = createOptimizer('nlopt', {'maxeval':25}) # Run VQE... results = optimizer.optimize(obj, 1) print(results) examples/qcor_demos/pnnl_tutorials/tut2/intro/honeywell.py 0 → 100644 +19 −0 Original line number Diff line number Diff line # Honeywell job submission summary: # - Set up credentials: qcor -set-credentials honeywell from qcor import * @qjit def ghz(q : qreg): H(q[0]) for i in range(q.size()-1): X.ctrl([q[i]], q[i+1]) Measure(q) set_qpu('honeywell:HQS-LT-S1-SIM') set_shots(1024) q = qalloc(6) ghz(q) q.print() examples/qcor_demos/pnnl_tutorials/tut2/intro/qcor_qiskit.py 0 → 100644 +26 −0 Original line number Diff line number Diff line # Interop with Qiskit from qcor import * import qiskit # Generate 3-qubit GHZ state with Qiskit qiskit_circ = qiskit.QuantumCircuit(3) qiskit_circ.h(0) qiskit_circ.cx(0, 1) qiskit_circ.cx(1, 2) qiskit_circ.measure_all() # Convert Qiskit circuit to QCOR IR qcor_kernel = qjit(qiskit_circ) # Allocate the qreg q = qalloc(3) # Examine the QCOR IR: print('QCOR IR:') qcor_kernel.print_kernel(q) set_qpu('ionq') set_shots(1024) qcor_kernel(q) q.print() No newline at end of file Loading
examples/qcor_demos/pnnl_tutorials/tut2/intro/chemistry_vqe.py 0 → 100644 +24 −0 Original line number Diff line number Diff line from qcor import * @qjit def ansatz(q: qreg, theta: float): X(q[0]) Ry(q[1], theta) CX(q[1], q[0]) # Define the hamiltonian H = 5.907 - 2.1433 * X(0) * X(1) - 2.1433 * Y(0) * Y(1) + .21829 * Z(0) - 6.125 * Z(1) # Define the optimization objective def obj(x : List[float]): e_at_x = ansatz.observe(H, qalloc(2), x[0]) print('E({}) = {}'.format(x[0], e_at_x)) return e_at_x # create the cobyla optimizer optimizer = createOptimizer('nlopt', {'maxeval':25}) # Run VQE... results = optimizer.optimize(obj, 1) print(results)
examples/qcor_demos/pnnl_tutorials/tut2/intro/honeywell.py 0 → 100644 +19 −0 Original line number Diff line number Diff line # Honeywell job submission summary: # - Set up credentials: qcor -set-credentials honeywell from qcor import * @qjit def ghz(q : qreg): H(q[0]) for i in range(q.size()-1): X.ctrl([q[i]], q[i+1]) Measure(q) set_qpu('honeywell:HQS-LT-S1-SIM') set_shots(1024) q = qalloc(6) ghz(q) q.print()
examples/qcor_demos/pnnl_tutorials/tut2/intro/qcor_qiskit.py 0 → 100644 +26 −0 Original line number Diff line number Diff line # Interop with Qiskit from qcor import * import qiskit # Generate 3-qubit GHZ state with Qiskit qiskit_circ = qiskit.QuantumCircuit(3) qiskit_circ.h(0) qiskit_circ.cx(0, 1) qiskit_circ.cx(1, 2) qiskit_circ.measure_all() # Convert Qiskit circuit to QCOR IR qcor_kernel = qjit(qiskit_circ) # Allocate the qreg q = qalloc(3) # Examine the QCOR IR: print('QCOR IR:') qcor_kernel.print_kernel(q) set_qpu('ionq') set_shots(1024) qcor_kernel(q) q.print() No newline at end of file