Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
7c8253de
Commit
7c8253de
authored
Jun 05, 2020
by
Wright, Jerimiah
Browse files
Updated Benchmarksuite
Signed-off-by:
Jerimiah
<
Jerimiah.wright@utexas.edu
>
parent
c48fa59b
Changes
3
Hide whitespace changes
Inline
Side-by-side
python/benchmark/chemistry/chemistry_benchmark.py
View file @
7c8253de
...
...
@@ -36,13 +36,18 @@ 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'
:
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
)
...
...
@@ -74,30 +79,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 +140,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
python/plugins/observables/pyscf_observable.py
View file @
7c8253de
...
...
@@ -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
...
...
python/xacc.py
View file @
7c8253de
...
...
@@ -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'
]
=
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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment