Commit a46d23d5 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Pushed qjit paper scripts for references



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 5dcf66d8
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
from qcor import *
import time 

@qjit
def trotter_circ(q : qreg, exp_args: List[PauliOperator], n_steps: int):
  for i in range(n_steps):
    for exp_arg in exp_args:
      exp_i_theta(q, 1.0, exp_arg)



#H2 = createOperator('pyscf', {'basis': 'sto-3g', 'geometry': 'H  0.000000   0.0      0.0\nH   0.0        0.0  .7474'})

# H_2_O = createOperator('pyscf', {'basis': 'sto-3g', 'geometry': 
# '''O    0.   0.       0
# h    0.   -0.757   0.587
# h    0.   0.757    0.587'''})

#N2 = createOperator('pyscf', {'basis': 'sto-3g', 'geometry': 'N 0 0 0 \n N 0 0 1.1'})


C2_H_4 = createOperator('pyscf', {'basis': 'sto-3g', 'geometry': 
'''C -0.65830719  0.61123287 -0.00800148
   C 0.73685281  0.61123287 -0.00800148
   H  1.43439081  1.81898387 -0.00800148
   H -1.35568919  1.81920887 -0.00868348
   H -1.20806619 -0.34108413 -0.00755148
   H  1.28636081 -0.34128013 -0.00668648
'''})


H = C2_H_4
# print(H.toString())
# print(H.nBits())
# print(H.asPauli.getNonIdentitySubTerms())

q = qalloc(H.nBits())
nbSteps = 1

print('n_bits =', H.nBits())
print('n_terms =', len(H.asPauli.getNonIdentitySubTerms()))
start = time.time()
n_instructions = trotter_circ.n_instructions(q, H.asPauli.getNonIdentitySubTerms(), nbSteps)
end = time.time()
print('Elapsed time =', end - start, "[secs]")
print(n_instructions)
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
import time 
from qiskit.chemistry import FermionicOperator
from qiskit.chemistry.drivers import PySCFDriver, UnitsType
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

# driver = PySCFDriver(atom='O 0. 0. 0.;H 0. -0.757 0.587;H 0. 0.757 0.587', unit=UnitsType.ANGSTROM, basis='sto3g')
# driver = PySCFDriver(atom='N 0 0 0; N 0 0 1.1', unit=UnitsType.ANGSTROM, basis='sto3g')
driver = PySCFDriver(atom='C -0.65830719 0.61123287 -0.00800148;C 0.73685281 0.61123287 -0.00800148;H 1.43439081 1.81898387 -0.00800148;H -1.35568919 1.81920887 -0.00868348;H -1.20806619 -0.34108413 -0.00755148;H 1.28636081 -0.34128013 -0.00668648', unit=UnitsType.ANGSTROM, basis='sto3g')

molecule = driver.run()
fer_op = FermionicOperator(h1=molecule.one_body_integrals, h2=molecule.two_body_integrals)
map_type = 'PARITY'
qubit_op = fer_op.mapping(map_type)
print(qubit_op)


nbQubits = qubit_op.num_qubits
print(nbQubits)
ham_op = qubit_op
nbSteps = 1
q = QuantumRegister(nbQubits, 'q')
start = time.time()
circuit = ham_op.evolve().decompose()
end = time.time()
print("Kernel eval time:", end - start, " [secs]")
ops_count = circuit.count_ops()
print(ops_count)
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
from qcor import *
@qjit
def ansatz(q : qreg, t0: float):
  X(q[0])
  Ry(q[1], t0)
  CNOT(q[1],q[0])    

# Define the Hamiltonian
H = -2.1433 * X(0) * X(1) \
    - 2.1433 * Y(0) * Y(1) \
    + .21829 * Z(0) \
    - 6.125 * Z(1) \
    + 5.907

# Create the ObjectiveFunction
obj = createObjectiveFunction(ansatz, H, 1, {'verbose': True})

# Create the nlopt optimizer 
# Use COBYLA method by default.
optimizer = createOptimizer('nlopt')

# Run VQE.
results = optimizer.optimize(obj)

print(results)
 No newline at end of file