Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xacc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ORNL Quantum Computing Institute
xacc
Commits
922ec502
Commit
922ec502
authored
8 years ago
by
Mccaskey, Alex
Browse files
Options
Downloads
Patches
Plain Diff
fixing bug in scaffold test
parent
ed8c28ae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp
+40
-33
40 additions, 33 deletions
quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp
quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp
+1
-1
1 addition, 1 deletion
.../gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp
with
41 additions
and
34 deletions
quantum/gate/compilers/scaffold/ScaffoldCompiler.cpp
+
40
−
33
View file @
922ec502
...
...
@@ -49,7 +49,8 @@ void ScaffoldCompiler::modifySource() {
kernelSource
.
erase
(
kernelSource
.
find
(
"__qpu__"
),
7
);
kernelSource
=
std
::
string
(
"module "
)
+
kernelSource
;
std
::
string
qubitAllocationLine
,
cbitAllocationLine
;
// = " qbit qreg[3];\n";
std
::
string
qubitAllocationLine
,
cbitAllocationLine
,
cbitVarName
;
std
::
map
<
int
,
int
>
cbitToQubit
;
std
::
regex
qbitName
(
"qbit
\\
s.*"
);
qubitAllocationLine
=
(
*
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
...
...
@@ -58,38 +59,44 @@ void ScaffoldCompiler::modifySource() {
boost
::
split
(
splitQbit
,
qubitAllocationLine
,
boost
::
is_any_of
(
" "
));
auto
qbitVarName
=
splitQbit
[
1
].
substr
(
0
,
splitQbit
[
1
].
find_first_of
(
"["
));
std
::
regex
cbitName
(
"cbit
\\
s.*"
);
cbitAllocationLine
=
(
*
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
cbitName
)).
str
()
+
"
\n
"
;
std
::
vector
<
std
::
string
>
splitCbit
;
boost
::
split
(
splitCbit
,
cbitAllocationLine
,
boost
::
is_any_of
(
" "
));
auto
cbitVarName
=
splitCbit
[
1
].
substr
(
0
,
splitCbit
[
1
].
find_first_of
(
"["
));
std
::
regex
measurements
(
".*Meas.*"
);
std
::
map
<
int
,
int
>
cbitToQubit
;
for
(
auto
i
=
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
measurements
);
i
!=
std
::
sregex_iterator
();
++
i
)
{
auto
measurement
=
(
*
i
).
str
();
boost
::
trim
(
measurement
);
boost
::
erase_all
(
measurement
,
"MeasZ"
);
boost
::
erase_all
(
measurement
,
"("
);
boost
::
erase_all
(
measurement
,
")"
);
boost
::
erase_all
(
measurement
,
cbitVarName
);
boost
::
erase_all
(
measurement
,
qbitVarName
);
// Should now have [#] = [#]
boost
::
erase_all
(
measurement
,
"["
);
boost
::
erase_all
(
measurement
,
"]"
);
std
::
vector
<
std
::
string
>
splitVec
;
boost
::
split
(
splitVec
,
measurement
,
boost
::
is_any_of
(
"="
));
auto
cbit
=
splitVec
[
0
];
auto
qbit
=
splitVec
[
1
];
boost
::
trim
(
cbit
);
boost
::
trim
(
qbit
);
cbitToQubit
.
insert
(
std
::
make_pair
(
std
::
stoi
(
cbit
),
std
::
stoi
(
qbit
)));
}
std
::
regex
cbitName
(
"cbit
\\
s.*"
);
auto
it
=
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
cbitName
);
if
(
it
!=
std
::
sregex_iterator
())
{
cbitAllocationLine
=
(
*
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
cbitName
)).
str
()
+
"
\n
"
;
std
::
vector
<
std
::
string
>
splitCbit
;
boost
::
split
(
splitCbit
,
cbitAllocationLine
,
boost
::
is_any_of
(
" "
));
cbitVarName
=
splitCbit
[
1
].
substr
(
0
,
splitCbit
[
1
].
find_first_of
(
"["
));
std
::
regex
measurements
(
".*Meas.*"
);
for
(
auto
i
=
std
::
sregex_iterator
(
kernelSource
.
begin
(),
kernelSource
.
end
(),
measurements
);
i
!=
std
::
sregex_iterator
();
++
i
)
{
auto
measurement
=
(
*
i
).
str
();
boost
::
trim
(
measurement
);
boost
::
erase_all
(
measurement
,
"MeasZ"
);
boost
::
erase_all
(
measurement
,
"("
);
boost
::
erase_all
(
measurement
,
")"
);
boost
::
erase_all
(
measurement
,
cbitVarName
);
boost
::
erase_all
(
measurement
,
qbitVarName
);
// Should now have [#] = [#]
boost
::
erase_all
(
measurement
,
"["
);
boost
::
erase_all
(
measurement
,
"]"
);
std
::
vector
<
std
::
string
>
splitVec
;
boost
::
split
(
splitVec
,
measurement
,
boost
::
is_any_of
(
"="
));
auto
cbit
=
splitVec
[
0
];
auto
qbit
=
splitVec
[
1
];
boost
::
trim
(
cbit
);
boost
::
trim
(
qbit
);
cbitToQubit
.
insert
(
std
::
make_pair
(
std
::
stoi
(
cbit
),
std
::
stoi
(
qbit
)));
}
}
// conditional on measurements
// FIXME FOR NOW WE ONLY ACCEPT format
...
...
This diff is collapsed.
Click to expand it.
quantum/gate/compilers/scaffold/tests/ScaffoldCompilerTester.cpp
+
1
−
1
View file @
922ec502
...
...
@@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) {
" H(qreg[0]);
\n
"
" creg[0] = MeasZ(qreg[0]);
\n
"
" creg[1] = MeasZ(qreg[1]);
\n
"
" if(creg[0] == 1) Z(qreg[2]);
\n
"
" if
(creg[0] == 1) Z(qreg[2]);
\n
"
" if (creg[1] == 1) X(qreg[2]);
\n
"
"}
\n
"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment