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
9ee0d3a8
Commit
9ee0d3a8
authored
7 years ago
by
Mccaskey, Alex
Browse files
Options
Downloads
Patches
Plain Diff
Adding GateQIR.persist using rapidjson
parent
69acb9f7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
quantum/gate/gateqir/GateQIR.hpp
+66
-11
66 additions, 11 deletions
quantum/gate/gateqir/GateQIR.hpp
quantum/gate/gateqir/tests/GateQIRTester.cpp
+18
-3
18 additions, 3 deletions
quantum/gate/gateqir/tests/GateQIRTester.cpp
with
84 additions
and
14 deletions
quantum/gate/gateqir/GateQIR.hpp
+
66
−
11
View file @
9ee0d3a8
...
...
@@ -38,6 +38,11 @@
#include
"Hadamard.hpp"
#include
"CNOT.hpp"
#include
"X.hpp"
#include
"Z.hpp"
#include
"ConditionalFunction.hpp"
#include
"Rz.hpp"
#include
"Measure.hpp"
#define RAPIDJSON_HAS_STDSTRING 1
...
...
@@ -75,16 +80,24 @@ class JsonSerializerGateVisitor:
public
BaseInstructionVisitor
,
public
InstructionVisitor
<
GateFunction
>
,
public
InstructionVisitor
<
Hadamard
>
,
public
InstructionVisitor
<
CNOT
>
{
public
InstructionVisitor
<
CNOT
>
,
public
InstructionVisitor
<
Rz
>
,
public
InstructionVisitor
<
ConditionalFunction
>
,
public
InstructionVisitor
<
X
>
,
public
InstructionVisitor
<
Z
>
,
public
InstructionVisitor
<
Measure
>
{
protected:
Writer
&
writer
;
int
nFuncInsts
=
0
;
std
::
string
currentFuncName
;
std
::
string
previousFuncName
;
std
::
map
<
std
::
string
,
int
>
subInstMap
;
public:
JsonSerializerGateVisitor
(
Writer
&
w
)
:
writer
(
w
)
{}
void
baseGateInst
(
GateInstruction
&
inst
)
{
void
baseGateInst
(
GateInstruction
&
inst
,
bool
endObject
=
true
)
{
writer
.
StartObject
();
writer
.
String
(
"gate"
);
writer
.
String
(
inst
.
getName
().
c_str
());
...
...
@@ -96,10 +109,15 @@ public:
writer
.
Int
(
qi
);
}
writer
.
EndArray
();
writer
.
EndObject
();
nFuncInsts
--
;
if
(
nFuncInsts
==
0
)
{
if
(
endObject
)
{
writer
.
EndObject
();
}
subInstMap
[
currentFuncName
]
--
;
if
(
subInstMap
[
currentFuncName
]
==
0
)
{
std
::
cout
<<
"ENDING "
<<
currentFuncName
<<
", setting "
<<
previousFuncName
<<
"
\n
"
;
endFunction
();
currentFuncName
=
previousFuncName
;
}
}
...
...
@@ -109,6 +127,42 @@ public:
void
visit
(
CNOT
&
cn
)
{
baseGateInst
(
dynamic_cast
<
GateInstruction
&>
(
cn
));
}
void
visit
(
Rz
&
rz
)
{
baseGateInst
(
dynamic_cast
<
GateInstruction
&>
(
rz
),
false
);
writer
.
String
(
"angle"
);
writer
.
Double
(
rz
.
getParameter
(
0
));
writer
.
EndObject
();
}
void
visit
(
ConditionalFunction
&
cn
)
{
writer
.
StartObject
();
writer
.
String
(
"conditional_function"
);
writer
.
String
(
cn
.
getName
());
writer
.
String
(
"conditional_qubit"
);
writer
.
Int
(
cn
.
getConditionalQubit
());
writer
.
String
(
"instructions"
);
writer
.
StartArray
();
subInstMap
.
insert
(
std
::
make_pair
(
cn
.
getName
(),
cn
.
nInstructions
()));
previousFuncName
=
currentFuncName
;
currentFuncName
=
cn
.
getName
();
}
void
visit
(
Measure
&
cn
)
{
// baseGateInst(dynamic_cast<GateInstruction&>(cn));
baseGateInst
(
dynamic_cast
<
GateInstruction
&>
(
cn
),
false
);
writer
.
String
(
"classicalBitIdx"
);
writer
.
Int
(
cn
.
getParameter
(
0
));
writer
.
EndObject
();
}
void
visit
(
X
&
cn
)
{
baseGateInst
(
dynamic_cast
<
GateInstruction
&>
(
cn
));
}
void
visit
(
Z
&
cn
)
{
baseGateInst
(
dynamic_cast
<
GateInstruction
&>
(
cn
));
}
void
visit
(
GateFunction
&
function
)
{
writer
.
StartObject
();
...
...
@@ -117,7 +171,8 @@ public:
writer
.
String
(
"instructions"
);
writer
.
StartArray
();
nFuncInsts
=
function
.
nInstructions
();
subInstMap
.
insert
(
std
::
make_pair
(
function
.
getName
(),
function
.
nInstructions
()));
currentFuncName
=
function
.
getName
();
}
private
:
...
...
@@ -202,11 +257,11 @@ private:
while
(
it
.
hasNext
())
{
// Get the next node in the tree
auto
nextInst
=
it
.
next
();
if
(
nextInst
->
isEnabled
())
{
nextInst
->
accept
(
visitor
);
}
nextInst
->
accept
(
visitor
);
}
writer
.
EndArray
();
writer
.
EndObject
();
}
writer
.
EndArray
();
...
...
This diff is collapsed.
Click to expand it.
quantum/gate/gateqir/tests/GateQIRTester.cpp
+
18
−
3
View file @
9ee0d3a8
...
...
@@ -34,9 +34,6 @@
#include
<boost/test/included/unit_test.hpp>
#include
"GateFunction.hpp"
#include
"Hadamard.hpp"
#include
"CNOT.hpp"
#include
"Rz.hpp"
#include
"GateQIR.hpp"
using
namespace
xacc
::
quantum
;
...
...
@@ -70,15 +67,33 @@ BOOST_AUTO_TEST_CASE(checkSerialization) {
auto
qir
=
std
::
make_shared
<
GateQIR
>
();
auto
f
=
std
::
make_shared
<
GateFunction
>
(
"foo"
);
auto
x
=
std
::
make_shared
<
X
>
(
0
);
auto
h
=
std
::
make_shared
<
Hadamard
>
(
1
);
auto
cn1
=
std
::
make_shared
<
CNOT
>
(
1
,
2
);
auto
cn2
=
std
::
make_shared
<
CNOT
>
(
0
,
1
);
auto
h2
=
std
::
make_shared
<
Hadamard
>
(
0
);
auto
m0
=
std
::
make_shared
<
Measure
>
(
0
,
0
);
auto
m1
=
std
::
make_shared
<
Measure
>
(
1
,
1
);
auto
rz
=
std
::
make_shared
<
Rz
>
(
1
,
3.1415
);
auto
cond1
=
std
::
make_shared
<
ConditionalFunction
>
(
0
);
auto
z
=
std
::
make_shared
<
Z
>
(
2
);
cond1
->
addInstruction
(
z
);
auto
cond2
=
std
::
make_shared
<
ConditionalFunction
>
(
1
);
auto
x2
=
std
::
make_shared
<
X
>
(
2
);
cond2
->
addInstruction
(
x2
);
f
->
addInstruction
(
x
);
f
->
addInstruction
(
h
);
f
->
addInstruction
(
cn1
);
f
->
addInstruction
(
cn2
);
f
->
addInstruction
(
h2
);
f
->
addInstruction
(
rz
);
f
->
addInstruction
(
m0
);
f
->
addInstruction
(
m1
);
f
->
addInstruction
(
cond1
);
f
->
addInstruction
(
cond2
);
qir
->
addKernel
(
f
);
...
...
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