Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to the Benchmark Suite #2 #198

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 44 additions & 27 deletions python/benchmark/chemistry/chemistry_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ 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':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 2 elifs provide the same code, you should remove the pyscf one and replace the one elif with

elif inputParams['Observable']['name'] in ['pyscf','psi4']:

Copy link
Contributor Author

@Jeriimiah Jeriimiah Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this - Do I need to make a new pull request in order for the new changes to take effect?

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)
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())
qpu = xacc.getAccelerator(acc_name, xacc_opts)
Expand Down Expand Up @@ -74,30 +79,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 +140,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()
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
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']:
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
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):
if opts.benchmark is not None:
Expand Down