Commit a443de6e authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

major cleanup on chemistry benchmark. improvements to aer_accelerator


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent fdd8309c
......@@ -41,3 +41,4 @@
**/.ipynb_checkpoints
compile_commands.json
/docs/doxygen/html**
**/*.dat
......@@ -3,6 +3,7 @@ accelerator = aer
shots = 1024
backend = ibmq_johannesburg
readout_error = True
verbose = True
[Decorators]
readout_error = True
......@@ -12,7 +13,6 @@ name = chemistry
algorithm = vqe
[Ansatz]
name = xasm
source = .compiler xasm
.circuit ansatz2
.parameters x
......@@ -20,10 +20,9 @@ source = .compiler xasm
X(q[0]);
X(q[2]);
ucc1(q, x[0]);
circuit_name = ansatz2
[Observable]
name = psi4-frozen-core
name = psi4
basis = sto-3g
geometry = 0 1
Na 0.000000 0.0 0.0
......@@ -33,4 +32,5 @@ fo = [0, 1, 2, 3, 4, 10, 11, 12, 13, 14]
ao = [5, 9, 15, 19]
[Optimizer]
name = nlopt
\ No newline at end of file
name = nlopt
nlopt-maxeval = 20
[XACC]
accelerator = tnqvm
shots = 1024
backend = 'ibmq_johannesburg'
readout_error = True
[Benchmark]
name = chemistry
algorithm = vqe
[Ansatz]
name = xasm
source = .compiler xasm
.circuit ansatz2
.parameters t0
.qbit q
X(q[0]);
Ry(q[1],t0);
CX(q[1],q[0]);
circuit_name = ansatz2
[Observable]
name = pauli
obs_str = 5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1
[Optimizer]
name = nlopt
#[Decorators]
geom = '''
0 1
Na 0.000000 0.0 0.0
H 0.0 0.0 1.914388
symmetry c1
'''
fo = [0, 1, 2, 3, 4, 10, 11, 12, 13, 14]
ao = [5, 9, 15, 19]
H = xacc.getObservable('psi4-frozen-core', {'basis': 'sto-3g',
'geometry': geom,
'frozen-spin-orbitals': fo,
'active-spin-orbitals': ao})
\ No newline at end of file
import xacc
import ast
import numpy as np
import scipy as sp
from xacc import Benchmark
from pelix.ipopo.decorators import ComponentFactory, Property, Requires, Provides, \
......@@ -20,9 +18,11 @@ class Chemistry(Benchmark):
acc_name = xacc_opts['accelerator']
qpu = xacc.getAccelerator(acc_name, xacc_opts)
if 'Decorators' in inputParams:
if 'readout_error' in inputParams['Decorators']:
qpu = xacc.getAcceleratorDecorator('ro-error', qpu)
if 'verbose' in xacc_opts and xacc_opts['verbose']:
xacc.set_verbose(True)
if 'Benchmark' not in inputParams:
xacc.error('Invalid benchmark input - must have Benchmark description')
if 'Observable' not in inputParams:
xacc.error('Invalid benchmark input - must have Observable description')
......@@ -30,6 +30,10 @@ class Chemistry(Benchmark):
if 'Ansatz' not in inputParams:
xacc.error('Invalid benchmark input - must have Ansatz circuit description')
if 'Decorators' in inputParams:
if 'readout_error' in inputParams['Decorators']:
qpu = xacc.getAcceleratorDecorator('ro-error', qpu)
H = None
if inputParams['Observable']['name'] == 'pauli':
obs_str = inputParams['Observable']['obs_str']
......@@ -48,7 +52,26 @@ class Chemistry(Benchmark):
#print('Ham: ', H.toString())
buffer = xacc.qalloc(H.nBits())
optimizer = xacc.getOptimizer(inputParams['Optimizer']['name'] if 'Optimizer' in inputParams else 'nlopt')
optimizer = None
if 'Optimizer' in inputParams:
# check that values that can be ints/floats are
opts = inputParams['Optimizer']
for k,v in inputParams['Optimizer'].items():
try:
i = int(v)
opts[k] = i
continue
except:
pass
try:
f = float(v)
opts[k] = f
continue
except:
pass
optimizer = xacc.getOptimizer(inputParams['Optimizer']['name'] if 'Optimizer' in inputParams else 'nlopt', opts)
else:
optimizer = xacc.getOptimizer('nlopt')
provider = xacc.getIRProvider('quantum')
......@@ -89,10 +112,11 @@ class Chemistry(Benchmark):
coeff = c.getInformation('coefficient')
re += coeff * c.getInformation('ro-fixed-exp-val-z')
ro_energies.append(re)
import numpy as np
import scipy as sp
x_axis = np.arange(len(ro_energies))
interp = sp.interpolate.interp1d(x_axis, ro_energies, bounds_error=False)
min_index = sp.optimization.fmin(interp, 0)
min_index = sp.optimize.fmin(interp, 0)
print('Readout Energy = ', ro_energies[int(min_index)])
print('Optimal Parameters =', uniqueParams[int(min_index)])
......
......@@ -45,23 +45,13 @@ class AerAccelerator(xacc.Accelerator):
qobjStr = self.qobj_compiler.translate(program)
import json
from qiskit import Aer
from qiskit.qobj.qobj import QasmQobjSchema
from qiskit.qobj import (QasmQobj, QobjHeader,
QasmQobjInstruction,
QasmQobjExperiment, QasmQobjExperimentConfig, QobjExperimentHeader, QasmQobjConfig)
qobj_json = json.loads(qobjStr)
# Create the Experiments using qiskit data structures
exps = [QasmQobjExperiment(config=QasmQobjExperimentConfig(memory_slots=e['config']['memory_slots'], n_qubits=e['config']['n_qubits']),
header=QobjExperimentHeader(clbit_labels=e['header']['clbit_labels'],creg_sizes=e['header']['creg_sizes'],
memory_slots=e['header']['memory_slots'],n_qubits=e['header']['n_qubits'],
name=e['header']['name'], qreg_sizes=e['header']['qreg_sizes'],
qubit_labels=e['header']['qubit_labels']),
instructions=[QasmQobjInstruction(name=i['name'], qubits=i['qubits'], params=(i['params'] if 'params' in i else [])) if i['name'] != 'measure'
else QasmQobjInstruction(name=i['name'], qubits=i['qubits'], memory=i['memory']) for i in e['instructions']]) for e in qobj_json['qObject']['experiments']]
qobj = QasmQobj(qobj_id=qobj_json['qObject']['qobj_id'],
header=QobjHeader(), config=QasmQobjConfig(shots=self.shots, memory_slots=qobj_json['qObject']['config']['memory_slots']), experiments=exps, shots=self.shots)
qobj = QasmQobjSchema().load(qobj_json['qObject'])
exps = qobj.experiments
measures = {}
for i in exps[0].instructions:
if i.name == "measure":
......@@ -76,7 +66,6 @@ class AerAccelerator(xacc.Accelerator):
sim_result = job_sim.result()
for b,c in sim_result.get_counts().items():
bitstring = b
if len(b) < buffer.size():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment