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
qcor
Commits
9360b902
Commit
9360b902
authored
Apr 17, 2019
by
Mccaskey, Alex
Browse files
enabling exp_i_theta gen from fermion operator
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
95983d99
Pipeline
#48841
passed with stages
in 2 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
examples/deuteron_H2_from_fermion_expgen.cpp
0 → 100644
View file @
9360b902
#include
"qcor.hpp"
int
main
(
int
argc
,
char
**
argv
)
{
qcor
::
Initialize
(
argc
,
argv
);
auto
optimizer
=
qcor
::
getOptimizer
(
"nlopt"
,
{{
"nlopt-optimizer"
,
"cobyla"
},
{
"nlopt-maxeval"
,
20
}});
auto
op
=
qcor
::
getObservable
(
"pauli"
,
"5.907 - 2.1433 X0X1 - 2.1433 Y0Y1 + .21829 Z0 - 6.125 Z1"
);
auto
future
=
qcor
::
submit
([
&
](
qcor
::
qpu_handler
&
qh
)
{
qh
.
vqe
(
[
&
](
double
x
)
{
X
(
0
);
exp_i_theta
(
x
,
{{
"fermion"
,
"0^ 1 - 1^ 0"
}});
},
op
,
optimizer
);
});
auto
results
=
future
.
get
();
auto
energy
=
mpark
::
get
<
double
>
(
results
->
getInformation
(
"opt-val"
));
std
::
cout
<<
"Results: "
<<
energy
<<
"
\n
"
;
}
ir/digital/generators/exp/exp.cpp
View file @
9360b902
#include
"exp.hpp"
#include
"FermionOperator.hpp"
#include
"IRProvider.hpp"
#include
"ObservableTransform.hpp"
#include
"PauliOperator.hpp"
#include
"XACC.hpp"
#include
"xacc_service.hpp"
#include
<memory>
#include
<regex>
using
namespace
xacc
;
...
...
@@ -11,10 +15,13 @@ using namespace xacc::quantum;
namespace
qcor
{
namespace
instructions
{
bool
Exp
::
validateOptions
()
{
if
(
!
options
.
count
(
"pauli"
))
{
return
false
;
if
(
options
.
count
(
"pauli"
))
{
return
true
;
}
if
(
options
.
count
(
"fermion"
))
{
return
true
;
}
return
tru
e
;
return
fals
e
;
}
std
::
shared_ptr
<
Function
>
...
...
@@ -41,17 +48,26 @@ Exp::generate(std::map<std::string, InstructionParameter> &¶meters) {
std
::
string
paramLetter
=
"t"
;
if
(
options
.
count
(
"param-id"
))
{
paramLetter
=
options
[
"param-id"
].
toString
();
paramLetter
=
options
[
"param-id"
].
toString
();
}
auto
pauliStr
=
options
[
"pauli"
].
toString
();
PauliOperator
op
(
pauliStr
);
double
pi
=
3.1415926
;
std
::
unordered_map
<
std
::
string
,
xacc
::
quantum
::
Term
>
terms
;
if
(
options
.
count
(
"fermion"
))
{
auto
fermionStr
=
options
[
"fermion"
].
toString
();
auto
op
=
std
::
make_shared
<
FermionOperator
>
(
fermionStr
);
terms
=
std
::
dynamic_pointer_cast
<
PauliOperator
>
(
xacc
::
getService
<
ObservableTransform
>
(
"jw"
)
->
transform
(
op
))
->
getTerms
();
}
else
{
auto
pauliStr
=
options
[
"pauli"
].
toString
();
PauliOperator
op
(
pauliStr
);
terms
=
op
.
getTerms
();
}
double
pi
=
3.1415926
;
auto
gateRegistry
=
xacc
::
getService
<
IRProvider
>
(
"gate"
);
auto
function
=
gateRegistry
->
createFunction
(
"temp"
,
{},
{});
auto
terms
=
op
.
getTerms
();
for
(
auto
spinInst
:
terms
)
{
// Get the individual pauli terms
...
...
@@ -95,8 +111,8 @@ Exp::generate(std::map<std::string, InstructionParameter> &¶meters) {
// std::stringstream ss;
// ss << 2 * std::imag(std::get<0>(spinInst.second)) << " * "
// << std::get<1>(spinInst.second);
auto
rz
=
gateRegistry
->
createInstruction
(
"Rz"
,
std
::
vector
<
int
>
{
qbitIdx
},
{
paramLetter
});
auto
rz
=
gateRegistry
->
createInstruction
(
"Rz"
,
std
::
vector
<
int
>
{
qbitIdx
},
{
paramLetter
});
// InstructionParameter p(ss.str());
// rz->setParameter(0, p);
...
...
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