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
b1cf4a2e
Unverified
Commit
b1cf4a2e
authored
Aug 17, 2021
by
Mccaskey, Alex
Committed by
GitHub
Aug 17, 2021
Browse files
Merge pull request #479 from ausbin/feature/swap-shortest-path-swaps
Consider SWAPs in swap-shortest-path
parents
4b894baf
71e1aefa
Pipeline
#160016
passed with stage
in 34 minutes and 55 seconds
Changes
2
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
quantum/plugins/staq/transformations/staq_swap_short.cpp
View file @
b1cf4a2e
...
...
@@ -78,10 +78,11 @@ void SwapShort::apply(std::shared_ptr<CompositeInstruction> program,
transformations
::
desugar
(
*
prog
);
transformations
::
Inliner
::
config
c
;
// Make sure we treat map all control pauli
// ops as CNOT gates
// ops
and swaps
as CNOT gates
c
.
overrides
.
erase
(
"cx"
);
c
.
overrides
.
erase
(
"cy"
);
c
.
overrides
.
erase
(
"cz"
);
c
.
overrides
.
erase
(
"swap"
);
transformations
::
inline_ast
(
*
prog
,
c
);
}
catch
(
std
::
exception
&
e
)
{
std
::
stringstream
ss
;
...
...
quantum/plugins/staq/transformations/tests/MappingTester.cpp
View file @
b1cf4a2e
...
...
@@ -99,6 +99,37 @@ irt->apply(circuit, qpu);
}
TEST
(
Staq_MappingTester
,
checkSwapShortSwap
)
{
auto
qpu
=
std
::
make_shared
<
AcceleratorWithConnectivity
>
(
std
::
vector
<
std
::
pair
<
int
,
int
>>
{{
0
,
1
},
{
1
,
2
}});
auto
x
=
xacc
::
qalloc
(
3
);
x
->
setName
(
"x"
);
xacc
::
storeBuffer
(
x
);
auto
irt
=
xacc
::
getIRTransformation
(
"swap-shortest-path"
);
auto
compiler
=
xacc
::
getCompiler
(
"xasm"
);
auto
program
=
compiler
->
compile
(
R"(__qpu__ void test_simple_swap(qreg x) {
X(x[0]);
Swap(x[0], x[2]);
Measure(x[0]);
Measure(x[2]);
})"
)
->
getComposite
(
"test_simple_swap"
);
EXPECT_EQ
(
4
,
program
->
nInstructions
());
EXPECT_EQ
(
"Swap"
,
program
->
getInstruction
(
1
)
->
name
());
irt
->
apply
(
program
,
nullptr
);
EXPECT_EQ
(
4
,
program
->
nInstructions
());
irt
->
apply
(
program
,
qpu
);
// Staq will expand the CNOT
EXPECT_EQ
(
9
,
program
->
nInstructions
());
std
::
cout
<<
program
->
toString
()
<<
"
\n
"
;
}
int
main
(
int
argc
,
char
**
argv
)
{
xacc
::
Initialize
(
argc
,
argv
);
xacc
::
set_verbose
(
true
);
...
...
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