Unverified Commit 912ea0bc authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #198 from Jeriimiah/master

Changes to the Benchmark Suite #2 
parents c48fa59b 34b4ab91
Pipeline #105610 passed with stage
in 10 minutes and 9 seconds
......@@ -36,13 +36,12 @@ class Chemistry(Benchmark):
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)
......@@ -74,30 +73,43 @@ class Chemistry(Benchmark):
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):
......@@ -122,5 +134,4 @@ class Chemistry(Benchmark):
print('Optimal Parameters =', uniqueParams[int(min_index)])
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):
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
......
......@@ -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:
......
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