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
e47926c9
Commit
e47926c9
authored
Nov 02, 2021
by
Nguyen, Thien Minh
Browse files
Fixed
https://github.com/eclipse/xacc/issues/491
Added tests Signed-off-by:
Thien Nguyen
<
nguyentm@ornl.gov
>
parent
3679fe75
Changes
2
Hide whitespace changes
Inline
Side-by-side
quantum/plugins/staq/compiler/staq_compiler.cpp
View file @
e47926c9
...
...
@@ -67,7 +67,6 @@ gate u(theta,phi,lambda) q { U(theta,phi,lambda) q; })#"},
cx a,b;
u3(-lambda/2,0,0) b;
cx a,b;
ry(lambda) a;
})#"
},
{
"cp"
,
R"#(gate cp(lambda) a,b
{
...
...
quantum/plugins/staq/compiler/tests/StaqCompilerTester.in.cpp
View file @
e47926c9
...
...
@@ -14,6 +14,8 @@
#include "xacc.hpp"
#include "xacc_service.hpp"
#include <regex>
#include <random>
namespace
{
// CU1 decompose: 5 instructions
...
...
@@ -298,6 +300,60 @@ TEST(StaqCompilerTester, checkCustomInclude) {
EXPECT_EQ
(
hello
->
nInstructions
(),
6
);
}
TEST
(
StaqCompilerTester
,
checkCRy
)
{
auto
q
=
xacc
::
qalloc
(
2
);
q
->
setName
(
"q"
);
xacc
::
storeBuffer
(
q
);
auto
src
=
R"(__qpu__ void test(qreg q) {
OPENQASM 2.0;
include "qelib1.inc";
cry(1.2345) q[0], q[1];
})"
;
auto
staq
=
xacc
::
getCompiler
(
"staq"
);
auto
IR
=
staq
->
compile
(
src
);
auto
hello
=
IR
->
getComposites
()[
0
];
std
::
cout
<<
hello
->
toString
()
<<
"
\n
"
;
EXPECT_EQ
(
hello
->
nInstructions
(),
4
);
}
TEST
(
StaqCompilerTester
,
checkCtrlRotationDef
)
{
// Functional test to validate CRx, CRy, CRz decomposition
// in staq compiler.
const
std
::
vector
<
std
::
string
>
ROTATION_GATE
{
"rx"
,
"ry"
,
"rz"
};
std
::
random_device
rd
;
std
::
default_random_engine
eng
(
rd
());
std
::
uniform_real_distribution
<>
distr
(
0.0
,
2.0
*
M_PI
);
const
double
randomAngle
=
distr
(
eng
);
for
(
const
auto
&
rotation
:
ROTATION_GATE
)
{
// Ctrl rotation (control bit set) then reverse the rotation (no control)
std
::
string
src
=
R"(OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
creg c[2];
x q[0];
cGATE_NAME(ANGLE) q[0], q[1];
GATE_NAME(-ANGLE) q[1];
measure q -> c;
)"
;
src
=
std
::
regex_replace
(
src
,
std
::
regex
(
"GATE_NAME"
),
rotation
);
src
=
std
::
regex_replace
(
src
,
std
::
regex
(
"ANGLE"
),
std
::
to_string
(
randomAngle
));
std
::
cout
<<
"HOWDY:
\n
"
<<
src
<<
"
\n
"
;
auto
compiler
=
xacc
::
getCompiler
(
"staq"
);
auto
IR
=
compiler
->
compile
(
src
);
auto
hello
=
IR
->
getComposites
()[
0
];
std
::
cout
<<
hello
->
toString
()
<<
"
\n
"
;
auto
accelerator
=
xacc
::
getAccelerator
(
"qpp"
,
{{
"shots"
,
1024
}});
auto
buffer
=
xacc
::
qalloc
(
2
);
accelerator
->
execute
(
buffer
,
hello
);
buffer
->
print
();
// Control bit is set to 1; target bit must return to 0.
EXPECT_EQ
(
buffer
->
getMeasurementCounts
()[
"10"
],
1024
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
xacc
::
Initialize
(
argc
,
argv
);
xacc
::
set_verbose
(
true
);
...
...
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