Commit 7c8253de authored by Wright, Jerimiah's avatar Wright, Jerimiah
Browse files

Updated Benchmarksuite



Signed-off-by: Wright, Jerimiah's avatarJerimiah <Jerimiah.wright@utexas.edu>
parent c48fa59b
...@@ -36,13 +36,18 @@ class Chemistry(Benchmark): ...@@ -36,13 +36,18 @@ class Chemistry(Benchmark):
elif inputParams['Observable']['name'] == 'fermion': elif inputParams['Observable']['name'] == 'fermion':
obs_str = inputParams['Observable']['obs_str'] obs_str = inputParams['Observable']['obs_str']
H = xacc.getObservable('fermion', obs_str) H = xacc.getObservable('fermion', obs_str)
elif inputParams['Observable']['name'] == 'psi4': elif inputParams['Observable']['name'] == 'psi4':
opts = {'basis':inputParams['Observable']['basis'], 'geometry':inputParams['Observable']['geometry']} opts = {'basis':inputParams['Observable']['basis'], 'geometry':inputParams['Observable']['geometry']}
if 'fo' in inputParams['Observable'] and 'ao' in inputParams['Observable']: if 'fo' in inputParams['Observable'] and 'ao' in inputParams['Observable']:
opts['frozen-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['fo']) opts['frozen-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['fo'])
opts['active-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['ao']) opts['active-spin-orbitals'] = ast.literal_eval(inputParams['Observable']['ao'])
H = xacc.getObservable('psi4', opts) H = xacc.getObservable('psi4', opts)
elif inputParams['Observable']['name'] == 'pyscf':
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('pyscf', opts)
#print('Ham: ', H.toString()) #print('Ham: ', H.toString())
qpu = xacc.getAccelerator(acc_name, xacc_opts) qpu = xacc.getAccelerator(acc_name, xacc_opts)
...@@ -74,30 +79,43 @@ class Chemistry(Benchmark): ...@@ -74,30 +79,43 @@ class Chemistry(Benchmark):
provider = xacc.getIRProvider('quantum') provider = xacc.getIRProvider('quantum')
if 'source' in inputParams['Ansatz']: if inputParams['Benchmark']['algorithm'] == 'adapt-vqe':
# here assume this is xasm always alg = xacc.getAlgorithm(inputParams['Benchmark']['algorithm'], {
src = inputParams['Ansatz']['source'] 'pool' : inputParams['Ansatz']['pool'],
xacc.qasm(src) 'nElectrons' : int(inputParams['Ansatz']['electrons']),
# get the name of the circuit 'accelerator': qpu,
circuit_name = None 'observable': H,
for l in src.split('\n'): 'optimizer': optimizer,
if '.circuit' in l: })
circuit_name = l.split(' ')[1]
ansatz = xacc.getCompiled(circuit_name) alg.execute(buffer)
else: return buffer
ansatz = provider.createInstruction(inputParams['Ansatz']['ansatz'])
ansatz = xacc.asComposite(ansatz) else:
alg = xacc.getAlgorithm(inputParams['Benchmark']['algorithm'], { if 'source' in inputParams['Ansatz']:
'ansatz': ansatz, # here assume this is xasm always
'accelerator': qpu, src = inputParams['Ansatz']['source']
'observable': H, xacc.qasm(src)
'optimizer': optimizer, # get the name of the circuit
}) circuit_name = None
for l in src.split('\n'):
alg.execute(buffer) if '.circuit' in l:
return buffer 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): def analyze(self, buffer, inputParams):
...@@ -122,5 +140,4 @@ class Chemistry(Benchmark): ...@@ -122,5 +140,4 @@ class Chemistry(Benchmark):
print('Optimal Parameters =', uniqueParams[int(min_index)]) print('Optimal Parameters =', uniqueParams[int(min_index)])
print('Energy = ', buffer['opt-val']) print('Energy = ', buffer['opt-val'])
print('Opt Params = ', buffer['opt-params']) print('Opt Params = ', buffer['opt-params'])
\ No newline at end of file
...@@ -35,6 +35,7 @@ class PySCFObservable(xacc.Observable): ...@@ -35,6 +35,7 @@ class PySCFObservable(xacc.Observable):
mol = gto.mole.Mole() mol = gto.mole.Mole()
mol.atom = inputParams['geometry'] mol.atom = inputParams['geometry']
mol.basis = inputParams['basis'] mol.basis = inputParams['basis']
mol.build()
scf_wfn = scf.RHF(mol) # needs to be changed for open-shells scf_wfn = scf.RHF(mol) # needs to be changed for open-shells
scf_wfn.conv_tol = 1e-8 scf_wfn.conv_tol = 1e-8
scf_wfn.kernel() # runs RHF calculations scf_wfn.kernel() # runs RHF calculations
......
...@@ -406,9 +406,19 @@ def benchmark(xacc_settings): ...@@ -406,9 +406,19 @@ def benchmark(xacc_settings):
results_name = "%s_%s_out" % (os.path.splitext( results_name = "%s_%s_out" % (os.path.splitext(
tail)[0], timestr) tail)[0], timestr)
f = open(results_name+".ab", 'w')
f.write(str(buffer)) if 'output_logs' not in xacc_settings['Benchmark']:
f.close() xacc_settings['Benchmark']['output_logs'] = False
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): def benchmark_from_cmd_line(opts):
if opts.benchmark is not None: if opts.benchmark is not None:
......
Supports Markdown
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