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
7f3f4fb8
Commit
7f3f4fb8
authored
Jul 14, 2019
by
Mccaskey, Alex
Browse files
deleting pointers to error listeners in compilers
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
1da60b21
Pipeline
#63209
passed with stages
in 10 minutes and 33 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
python/compiler/PyXACCCompiler.cpp
View file @
7f3f4fb8
...
...
@@ -27,16 +27,19 @@ namespace quantum {
std
::
shared_ptr
<
IR
>
PyXACCCompiler
::
compile
(
const
std
::
string
&
src
,
std
::
shared_ptr
<
Accelerator
>
acc
)
{
auto
e1
=
new
PyXACCErrorListener
();
auto
e2
=
new
PyXACCErrorListener
();
// Setup the Antlr Parser
ANTLRInputStream
input
(
src
);
PyXACCIRLexer
lexer
(
&
input
);
lexer
.
removeErrorListeners
();
lexer
.
addErrorListener
(
new
PyXACCErrorListener
()
);
lexer
.
addErrorListener
(
e1
);
CommonTokenStream
tokens
(
&
lexer
);
PyXACCIRParser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
parser
.
addErrorListener
(
new
PyXACCErrorListener
()
);
parser
.
addErrorListener
(
e2
);
// Walk the Abstract Syntax Tree
tree
::
ParseTree
*
tree
=
parser
.
xaccsrc
();
...
...
@@ -51,6 +54,9 @@ std::shared_ptr<IR> PyXACCCompiler::compile(const std::string &src,
auto
ir
=
std
::
make_shared
<
GateIR
>
();
ir
->
addKernel
(
listener
.
getKernel
());
delete
e1
;
delete
e2
;
return
ir
;
}
...
...
quantum/plugins/dwave/compiler/DWQMICompiler.cpp
View file @
7f3f4fb8
...
...
@@ -46,29 +46,30 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string &src,
std
::
shared_ptr
<
Accelerator
>
acc
)
{
auto
hardwareconnections
=
acc
->
getAcceleratorConnectivity
();
std
::
set
<
int
>
nUniqueBits
;
for
(
auto
&
edge
:
hardwareconnections
)
{
nUniqueBits
.
insert
(
edge
.
first
);
nUniqueBits
.
insert
(
edge
.
second
);
}
int
nBits
=
*
std
::
max_element
(
nUniqueBits
.
begin
(),
nUniqueBits
.
end
())
+
1
;
auto
hardwareGraph
=
xacc
::
getService
<
Graph
>
(
"boost-ugraph"
);
for
(
int
i
=
0
;
i
<
nBits
;
i
++
)
{
std
::
map
<
std
::
string
,
InstructionParameter
>
m
{{
"bias"
,
1.0
}};
hardwareGraph
->
addVertex
(
m
);
}
for
(
auto
&
edge
:
hardwareconnections
)
{
hardwareGraph
->
addEdge
(
edge
.
first
,
edge
.
second
);
}
std
::
set
<
int
>
nUniqueBits
;
for
(
auto
&
edge
:
hardwareconnections
)
{
nUniqueBits
.
insert
(
edge
.
first
);
nUniqueBits
.
insert
(
edge
.
second
);
}
int
nBits
=
*
std
::
max_element
(
nUniqueBits
.
begin
(),
nUniqueBits
.
end
())
+
1
;
auto
hardwareGraph
=
xacc
::
getService
<
Graph
>
(
"boost-ugraph"
);
for
(
int
i
=
0
;
i
<
nBits
;
i
++
)
{
std
::
map
<
std
::
string
,
InstructionParameter
>
m
{{
"bias"
,
1.0
}};
hardwareGraph
->
addVertex
(
m
);
}
for
(
auto
&
edge
:
hardwareconnections
)
{
hardwareGraph
->
addEdge
(
edge
.
first
,
edge
.
second
);
}
auto
e
=
new
DWQMIErrorListener
();
ANTLRInputStream
input
(
src
);
DWQMILexer
lexer
(
&
input
);
CommonTokenStream
tokens
(
&
lexer
);
DWQMIParser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
parser
.
addErrorListener
(
new
DWQMIErrorListener
()
);
parser
.
addErrorListener
(
e
);
auto
ir
(
std
::
make_shared
<
DWIR
>
());
...
...
@@ -76,17 +77,13 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string &src,
// of qubits for the D-Wave -- all of them.
auto
bufName
=
acc
->
getAllocatedBufferNames
()[
0
];
auto
buffer
=
acc
->
getBuffer
(
bufName
);
// std::shared_ptr<AQCAcceleratorBuffer> aqcBuffer =
// std::dynamic_pointer_cast<AQCAcceleratorBuffer>(buffer);
// if (!aqcBuffer) {
// xacc::error("Invalid AcceleratorBuffer passed to DW QMI Compiler. Must be "
// "an AQCAcceleratorBuffer.");
// }
tree
::
ParseTree
*
tree
=
parser
.
xaccsrc
();
DWQMIListener
listener
(
ir
,
hardwareGraph
,
buffer
);
tree
::
ParseTreeWalker
::
DEFAULT
.
walk
(
&
listener
,
tree
);
delete
e
;
return
ir
;
}
...
...
@@ -117,8 +114,7 @@ const std::string DWQMICompiler::translate(const std::string &bufferVariable,
auto
bits
=
inst
->
bits
();
auto
param
=
inst
->
getParameter
(
0
);
std
::
stringstream
s
;
s
<<
" "
<<
bits
[
0
]
<<
" "
<<
bits
[
1
]
<<
" "
<<
param
.
toString
()
<<
";
\n
"
;
s
<<
" "
<<
bits
[
0
]
<<
" "
<<
bits
[
1
]
<<
" "
<<
param
.
toString
()
<<
";
\n
"
;
src
+=
s
.
str
();
}
src
+=
"}"
;
...
...
quantum/plugins/dwave/compiler/DWQMICompiler.hpp
View file @
7f3f4fb8
...
...
@@ -101,19 +101,19 @@ public:
*
* @return options Description of command line options.
*/
OptionPairs
getOptions
()
override
{
OptionPairs
desc
{
{
"dwave-embedding"
,
"Provide the name of the Embedding Algorithm to use "
"during compilation."
},{
"d
wave-parameter-setter"
,
"Provide the name of the "
"P
arameterSetter to map logical parameters to physical parameters."
},{
"dwave-load-embedding"
,
"Use the embedding in the given file."
},
{
"dwave-persist-embedding"
,
"Persist the computed embedding to the given file name."
},
{
"dwave-list-embedding-algorithms"
,
"List all available embedding algorithms."
}};
OptionPairs
getOptions
()
override
{
OptionPairs
desc
{
{
"dwave-embedding"
,
"Provide the name of the Embedding Algorithm to use "
"d
uring compilation."
}
,
{
"dwave-parameter-setter"
,
"P
rovide the name of the "
"ParameterSetter to map logical parameters to physical parameters."
}
,
{
"dwave-load-embedding"
,
"Use the embedding in the given file."
},
{
"dwave-persist-embedding"
,
"Persist the computed embedding to the given file name."
},
{
"dwave-list-embedding-algorithms"
,
"List all available embedding algorithms."
}};
return
desc
;
}
...
...
quantum/plugins/ibm/compiler/OQASMCompiler.cpp
View file @
7f3f4fb8
...
...
@@ -61,7 +61,8 @@ std::shared_ptr<IR> OQASMCompiler::compile(const std::string &src) {
CommonTokenStream
tokens
(
&
lexer
);
OQASM2Parser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
parser
.
addErrorListener
(
new
OQASMErrorListener
());
auto
e
=
new
OQASMErrorListener
;
parser
.
addErrorListener
(
e
);
auto
ir
=
xacc
::
getService
<
IRProvider
>
(
"gate"
)
->
createIR
();
...
...
@@ -69,6 +70,7 @@ std::shared_ptr<IR> OQASMCompiler::compile(const std::string &src) {
OQASMToXACCListener
listener
(
ir
);
tree
::
ParseTreeWalker
::
DEFAULT
.
walk
(
&
listener
,
tree
);
delete
e
;
return
ir
;
}
...
...
quantum/plugins/rigetti/compiler/QuilCompiler.cpp
View file @
7f3f4fb8
...
...
@@ -60,7 +60,8 @@ std::shared_ptr<IR> QuilCompiler::compile(const std::string &src) {
CommonTokenStream
tokens
(
&
lexer
);
QuilParser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
parser
.
addErrorListener
(
new
QuilErrorListener
());
auto
e
=
new
QuilErrorListener
();
parser
.
addErrorListener
(
e
);
auto
ir
=
xacc
::
getService
<
IRProvider
>
(
"gate"
)
->
createIR
();
...
...
@@ -68,6 +69,7 @@ std::shared_ptr<IR> QuilCompiler::compile(const std::string &src) {
QuilToXACCListener
listener
(
ir
);
tree
::
ParseTreeWalker
::
DEFAULT
.
walk
(
&
listener
,
tree
);
delete
e
;
return
ir
;
}
...
...
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