Skip to content

Commit

Permalink
Merge pull request eclipse#198 from Jeriimiah/master
Browse files Browse the repository at this point in the history
Changes to the Benchmark Suite #2
  • Loading branch information
Alex McCaskey authored Jun 5, 2020
2 parents 50c9ad0 + 2e4caea commit 8835cd9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 32 deletions.
69 changes: 40 additions & 29 deletions python/benchmark/chemistry/chemistry_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ def execute(self, inputParams):
elif inputParams['Observable']['name'] == 'fermion':
obs_str = inputParams['Observable']['obs_str']
H = xacc.getObservable('fermion', obs_str)

elif inputParams['Observable']['name'] == 'psi4':
elif inputParams['Observable']['name'] in ['pyscf','psi4']:
opts = {'basis':inputParams['Observable']['basis'], 'geometry':inputParams['Observable']['geometry']}
if 'fo' in inputParams['Observable'] and 'ao' in inputParams['Observable']:
opts['frozen-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['fo'])
opts['active-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['ao'])
H = xacc.getObservable('psi4', opts)
H = xacc.getObservable(inputParams['Observable']['name'], opts)

#print('Ham: ', H.toString())
qpu = xacc.getAccelerator(acc_name, xacc_opts)
Expand Down Expand Up @@ -74,30 +73,43 @@ def execute(self, inputParams):

provider = xacc.getIRProvider('quantum')

if 'source' in inputParams['Ansatz']:
# here assume this is xasm always
src = inputParams['Ansatz']['source']
xacc.qasm(src)
# get the name of the circuit
circuit_name = None
for l in src.split('\n'):
if '.circuit' in l:
circuit_name = l.split(' ')[1]
ansatz = xacc.getCompiled(circuit_name)
else:
ansatz = provider.createInstruction(inputParams['Ansatz']['ansatz'])
ansatz = xacc.asComposite(ansatz)

alg = xacc.getAlgorithm(inputParams['Benchmark']['algorithm'], {
'ansatz': ansatz,
'accelerator': qpu,
'observable': H,
'optimizer': optimizer,
})

alg.execute(buffer)
return buffer

if inputParams['Benchmark']['algorithm'] == 'adapt-vqe':
alg = xacc.getAlgorithm(inputParams['Benchmark']['algorithm'], {
'pool' : inputParams['Ansatz']['pool'],
'nElectrons' : int(inputParams['Ansatz']['electrons']),
'accelerator': qpu,
'observable': H,
'optimizer': optimizer,
})

alg.execute(buffer)
return buffer

else:

if 'source' in inputParams['Ansatz']:
# here assume this is xasm always
src = inputParams['Ansatz']['source']
xacc.qasm(src)
# get the name of the circuit
circuit_name = None
for l in src.split('\n'):
if '.circuit' in l:
circuit_name = l.split(' ')[1]
ansatz = xacc.getCompiled(circuit_name)
else:
ansatz = provider.createInstruction(inputParams['Ansatz']['ansatz'])
ansatz = xacc.asComposite(ansatz)

alg = xacc.getAlgorithm(inputParams['Benchmark']['algorithm'], {
'ansatz': ansatz,
'accelerator': qpu,
'observable': H,
'optimizer': optimizer,
})

alg.execute(buffer)
return buffer

def analyze(self, buffer, inputParams):

Expand All @@ -122,5 +134,4 @@ def analyze(self, buffer, inputParams):
print('Optimal Parameters =', uniqueParams[int(min_index)])

print('Energy = ', buffer['opt-val'])
print('Opt Params = ', buffer['opt-params'])

print('Opt Params = ', buffer['opt-params'])
1 change: 1 addition & 0 deletions python/plugins/observables/pyscf_observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def fromOptions(self, inputParams):
mol = gto.mole.Mole()
mol.atom = inputParams['geometry']
mol.basis = inputParams['basis']
mol.build()
scf_wfn = scf.RHF(mol) # needs to be changed for open-shells
scf_wfn.conv_tol = 1e-8
scf_wfn.kernel() # runs RHF calculations
Expand Down
16 changes: 13 additions & 3 deletions python/xacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,19 @@ def benchmark(xacc_settings):

results_name = "%s_%s_out" % (os.path.splitext(
tail)[0], timestr)
f = open(results_name+".ab", 'w')
f.write(str(buffer))
f.close()

if 'output_logs' not in xacc_settings['Benchmark']:
xacc_settings['Benchmark']['output_logs'] = True

if xacc_settings['Benchmark']['output_logs'] == True:
f = open(results_name+".ab", 'w')
f.write(str(buffer))
f.close()

else:
pass

return buffer

def benchmark_from_cmd_line(opts):
if opts.benchmark is not None:
Expand Down

0 comments on commit 8835cd9

Please sign in to comment.