Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ORNL Quantum Computing Institute
xacc
Commits
159ce1f5
Commit
159ce1f5
authored
Jun 12, 2020
by
Daniel Claudino
Browse files
Print circuit and number of terms in commutator
Signed-off-by:
Daniel Claudino
<
6d3@ornl.gov
>
parent
2b073add
Changes
4
Hide whitespace changes
Inline
Side-by-side
python/examples/adapt_vqe_h2.py
View file @
159ce1f5
...
...
@@ -20,6 +20,6 @@ adapt = xacc.getAlgorithm('adapt-vqe', {'accelerator': qpu,
'threshold'
:
1.0e-2
,
'print-threshold'
:
1.0e-10
,
'maxiter'
:
2
,
'pool'
:
"uccsd"
})
'pool'
:
"
singlet-adapted-
uccsd"
})
# execute
adapt
.
execute
(
buffer
)
quantum/plugins/algorithms/adapt_vqe/adapt_vqe.cpp
View file @
159ce1f5
...
...
@@ -217,29 +217,34 @@ void ADAPT_VQE::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
for
(
int
operatorIdx
=
0
;
operatorIdx
<
commutators
.
size
();
operatorIdx
++
){
// only compute commutators if they aren't zero
if
(
std
::
dynamic_pointer_cast
<
PauliOperator
>
(
commutators
[
operatorIdx
])
->
getTerms
().
size
()
!=
0
){
// observe the commutators with the updated circuit ansatz
auto
grad_vqe
=
xacc
::
getAlgorithm
(
"vqe"
,
{
std
::
make_pair
(
"observable"
,
commutators
[
operatorIdx
]),
std
::
make_pair
(
"optimizer"
,
optimizer
),
std
::
make_pair
(
"accelerator"
,
accelerator
),
std
::
make_pair
(
"ansatz"
,
ansatzInstructions
)});
auto
tmp_buffer
=
xacc
::
qalloc
(
buffer
->
size
());
auto
commutatorValue
=
std
::
real
(
grad_vqe
->
execute
(
tmp_buffer
,
x
)[
0
]);
if
(
abs
(
commutatorValue
)
>
_printThreshold
){
ss
<<
std
::
setprecision
(
12
)
<<
"[H,"
<<
operatorIdx
<<
"] = "
<<
commutatorValue
<<
"
\n
"
;
xacc
::
info
(
ss
.
str
());
ss
.
str
(
std
::
string
());
}
int
nTermsCommutator
=
std
::
dynamic_pointer_cast
<
PauliOperator
>
(
commutators
[
operatorIdx
])
->
getTerms
().
size
();
if
(
nTermsCommutator
!=
0
){
// Print number of instructions for computing <observable>
xacc
::
info
(
"Number of instructions for commutator calculation: "
+
std
::
to_string
(
nTermsCommutator
));
// observe the commutators with the updated circuit ansatz
auto
grad_vqe
=
xacc
::
getAlgorithm
(
"vqe"
,
{
std
::
make_pair
(
"observable"
,
commutators
[
operatorIdx
]),
std
::
make_pair
(
"optimizer"
,
optimizer
),
std
::
make_pair
(
"accelerator"
,
accelerator
),
std
::
make_pair
(
"ansatz"
,
ansatzInstructions
)});
auto
tmp_buffer
=
xacc
::
qalloc
(
buffer
->
size
());
auto
commutatorValue
=
std
::
real
(
grad_vqe
->
execute
(
tmp_buffer
,
x
)[
0
]);
if
(
abs
(
commutatorValue
)
>
_printThreshold
){
ss
<<
std
::
setprecision
(
12
)
<<
"[H,"
<<
operatorIdx
<<
"] = "
<<
commutatorValue
<<
"
\n
"
;
xacc
::
info
(
ss
.
str
());
ss
.
str
(
std
::
string
());
}
// update maxCommutator
if
(
abs
(
commutatorValue
)
>
abs
(
maxCommutator
)){
maxCommutatorIdx
=
operatorIdx
;
maxCommutator
=
commutatorValue
;
}
// update maxCommutator
if
(
abs
(
commutatorValue
)
>
abs
(
maxCommutator
)){
maxCommutatorIdx
=
operatorIdx
;
maxCommutator
=
commutatorValue
;
}
gradientNorm
+=
commutatorValue
*
commutatorValue
;
gradientNorm
+=
commutatorValue
*
commutatorValue
;
}
}
...
...
@@ -266,6 +271,8 @@ void ADAPT_VQE::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
xacc
::
info
(
ss
.
str
()
+
"
\n
"
);
ss
.
str
(
std
::
string
());
xacc
::
info
(
"Final ADAPT-VQE circuit
\n
"
+
ansatzInstructions
->
toString
());
return
;
}
else
if
(
iter
<
_maxIter
)
{
// Add operator and reoptimize
...
...
quantum/plugins/algorithms/adapt_vqe/operator_pools/pools.hpp
View file @
159ce1f5
...
...
@@ -126,7 +126,7 @@ public:
return
pool
;
}
const
std
::
string
name
()
const
override
{
return
"uccsd"
;
}
const
std
::
string
name
()
const
override
{
return
"
singlet-adapted-
uccsd"
;
}
const
std
::
string
description
()
const
override
{
return
""
;
}
};
...
...
quantum/plugins/algorithms/adapt_vqe/tests/AdaptVQETester.cpp
View file @
159ce1f5
...
...
@@ -61,7 +61,7 @@ TEST(AdaptVQETester, checkSimple) {
EXPECT_TRUE
(
adapt_vqe
->
initialize
({
std
::
make_pair
(
"accelerator"
,
acc
),
std
::
make_pair
(
"observable"
,
H
),
std
::
make_pair
(
"optimizer"
,
optimizer
),
std
::
make_pair
(
"pool"
,
"uccsd"
),
std
::
make_pair
(
"pool"
,
"
singlet-adapted-
uccsd"
),
std
::
make_pair
(
"gradient-strategy"
,
"parameter-shift-gradient"
),
std
::
make_pair
(
"nElectrons"
,
2
)}));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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