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
00160f79
Commit
00160f79
authored
Jun 11, 2021
by
Nguyen, Thien Minh
Browse files
Added tests for grouping
Signed-off-by:
Thien Nguyen
<
nguyentm@ornl.gov
>
parent
62f67156
Changes
3
Show whitespace changes
Inline
Side-by-side
quantum/observable/pauli/PauliOperator.cpp
View file @
00160f79
...
...
@@ -277,7 +277,7 @@ PauliOperator::observe(std::shared_ptr<CompositeInstruction> function, const Het
}
// For this, we require the Accelerator info:
if
(
grouping_options
.
pointerLikeExists
<
Accelerator
>
(
"accelerator"
))
{
if
(
!
grouping_options
.
pointerLikeExists
<
Accelerator
>
(
"accelerator"
))
{
xacc
::
error
(
"'accelerator' is required for Observable grouping"
);
}
auto
qpu
=
grouping_options
.
getPointerLike
<
Accelerator
>
(
"accelerator"
);
...
...
quantum/observable/pauli/tests/PauliOperatorTester.cpp
View file @
00160f79
...
...
@@ -490,6 +490,29 @@ TEST(PauliOperatorTester, checkNormalize) {
}
TEST
(
PauliOperatorTester
,
checkGroupingQaoa
)
{
PauliOperator
op
;
op
.
fromString
(
"(0, -1) Z0 Z1 + (0, -1) Z1 Z2 + (0, -1) Z2 Z0"
);
std
::
cout
<<
op
.
toString
()
<<
"
\n
"
;
auto
qpu
=
xacc
::
getAccelerator
(
"qpp"
,
{{
"shots"
,
1024
}});
auto
gateRegistry
=
xacc
::
getService
<
xacc
::
IRProvider
>
(
"quantum"
);
auto
f
=
gateRegistry
->
createComposite
(
"f"
);
auto
h0
=
gateRegistry
->
createInstruction
(
"H"
,
0
);
auto
h1
=
gateRegistry
->
createInstruction
(
"H"
,
1
);
auto
h2
=
gateRegistry
->
createInstruction
(
"H"
,
2
);
f
->
addInstructions
({
h0
,
h1
,
h2
});
auto
observed
=
op
.
observe
(
f
,
{{
"accelerator"
,
qpu
}});
EXPECT_EQ
(
observed
.
size
(),
1
);
// Check non-commute as well:
PauliOperator
op_non_commute
;
op_non_commute
.
fromString
(
"(0, -1) Z0 Z1 + (0, -1) Z1 Z2 + (0, -1) Z2 X0"
);
std
::
cout
<<
op_non_commute
.
toString
()
<<
"
\n
"
;
auto
observed_non_commute
=
op_non_commute
.
observe
(
f
,
{{
"accelerator"
,
qpu
}});
// Three terms:
EXPECT_EQ
(
observed_non_commute
.
size
(),
3
);
}
int
main
(
int
argc
,
char
**
argv
)
{
xacc
::
Initialize
(
argc
,
argv
);
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
...
...
quantum/plugins/qpp/accelerator/QppAccelerator.hpp
View file @
00160f79
...
...
@@ -28,6 +28,7 @@ public:
virtual
void
initialize
(
const
HeterogeneousMap
&
params
=
{})
override
;
virtual
void
updateConfiguration
(
const
HeterogeneousMap
&
config
)
override
{
initialize
(
config
);};
virtual
const
std
::
vector
<
std
::
string
>
configurationKeys
()
override
{
return
{};
}
virtual
HeterogeneousMap
getProperties
()
override
{
return
{{
"shots"
,
m_shots
}};
}
virtual
BitOrder
getBitOrder
()
override
{
return
BitOrder
::
LSB
;}
virtual
void
execute
(
std
::
shared_ptr
<
AcceleratorBuffer
>
buffer
,
const
std
::
shared_ptr
<
CompositeInstruction
>
compositeInstruction
)
override
;
virtual
void
execute
(
std
::
shared_ptr
<
AcceleratorBuffer
>
buffer
,
const
std
::
vector
<
std
::
shared_ptr
<
CompositeInstruction
>>
compositeInstructions
)
override
;
...
...
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