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
e920d589
Commit
e920d589
authored
Jun 10, 2020
by
Mccaskey, Alex
Browse files
fixing xasm fail when int or double literal is passed to quantum kernel
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
351f6f8b
Changes
3
Hide whitespace changes
Inline
Side-by-side
quantum/plugins/xasm/tests/XASMCompilerTester.cpp
View file @
e920d589
...
...
@@ -22,6 +22,19 @@
#include
"Circuit.hpp"
TEST
(
XASMCompilerTester
,
checkQcorIssue23
)
{
auto
compiler
=
xacc
::
getCompiler
(
"xasm"
);
auto
IR
=
compiler
->
compile
(
R"(__qpu__ void rotate(qbit q, double x) {
Rx(q[0], x);
})"
);
auto
IR2
=
compiler
->
compile
(
R"(__qpu__ void check(qbit q) {
rotate(q, 2.2);
})"
);
std
::
cout
<<
IR2
->
getComposite
(
"check"
)
->
toString
()
<<
"
\n
"
;
}
TEST
(
XASMCompilerTester
,
checkU1
)
{
auto
compiler
=
xacc
::
getCompiler
(
"xasm"
);
...
...
quantum/plugins/xasm/xasm_compiler.cpp
View file @
e920d589
...
...
@@ -39,13 +39,14 @@ bool XASMCompiler::canParse(const std::string &src) {
std
::
stringstream
ss
;
ss
<<
"XASM Cannot parse this source: "
<<
msg
<<
"
\n
"
;
ss
<<
line
<<
": "
<<
charPositionInLine
<<
", offending symbol = "
<<
offendingSymbol
->
getText
()
<<
"
\n
"
;
xacc
::
info
(
ss
.
str
());
//
xacc::info(ss.str());
throw
std
::
runtime_error
(
"Cannot parse this XASM source string."
);
}
};
ANTLRInputStream
input
(
src
);
xasmLexer
lexer
(
&
input
);
lexer
.
removeErrorListeners
();
CommonTokenStream
tokens
(
&
lexer
);
xasmParser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
...
...
@@ -63,6 +64,7 @@ std::shared_ptr<IR> XASMCompiler::compile(const std::string &src,
std
::
shared_ptr
<
Accelerator
>
acc
)
{
ANTLRInputStream
input
(
src
);
xasmLexer
lexer
(
&
input
);
lexer
.
removeErrorListeners
();
CommonTokenStream
tokens
(
&
lexer
);
xasmParser
parser
(
&
tokens
);
parser
.
removeErrorListeners
();
...
...
quantum/plugins/xasm/xasm_listener.cpp
View file @
e920d589
...
...
@@ -484,7 +484,7 @@ void XASMListener::enterParamList(xasmParser::ParamListContext *ctx) {
}
}
void
XASMListener
::
exitInstruction
(
xasmParser
::
InstructionContext
*
ctx
)
{
void
XASMListener
::
exitInstruction
(
xasmParser
::
InstructionContext
*
ctx
)
{
auto
inst
=
irProvider
->
createInstruction
(
currentInstructionName
,
currentBits
,
currentParameters
);
...
...
@@ -591,7 +591,7 @@ void XASMListener::enterOptionsType(xasmParser::OptionsTypeContext *ctx) {
if
(
isConstChar
)
{
currentOptions
.
insert
(
key
,
valStr
.
c_str
());
}
else
{
currentOptions
.
insert
(
key
,
valStr
);
currentOptions
.
insert
(
key
,
valStr
);
}
}
else
{
...
...
@@ -633,6 +633,7 @@ void XASMListener::exitComposite_generator(
auto
composite
=
std
::
dynamic_pointer_cast
<
CompositeInstruction
>
(
tmp
);
for
(
int
i
=
0
;
i
<
currentParameters
.
size
();
i
++
)
{
auto
p
=
currentParameters
[
i
];
auto
arg
=
function
->
getArgument
(
p
.
toString
());
int
vector_mapping
=
0
;
...
...
@@ -648,6 +649,43 @@ void XASMListener::exitComposite_generator(
// give the instruction a mapping from i to vector idx
vector_mapping
=
new_var_to_vector_idx
[
currentParameters
[
i
].
toString
()];
}
else
if
(
p
.
isNumeric
())
{
if
(
!
composite
->
getArguments
().
empty
())
{
std
::
cout
<<
"xasm debug: "
<<
composite
->
getArguments
().
size
()
<<
"
\n
"
;
// This is a literal. Create an argument and add it
auto
tmp_arg
=
composite
->
getArguments
()[
1
];
if
(
tmp_arg
->
type
==
"double"
)
{
tmp_arg
->
runtimeValue
.
insert
(
INTERNAL_ARGUMENT_VALUE_KEY
,
p
.
as
<
double
>
());
}
else
if
(
tmp_arg
->
type
==
"int"
)
{
tmp_arg
->
runtimeValue
.
insert
(
INTERNAL_ARGUMENT_VALUE_KEY
,
p
.
as
<
int
>
());
}
else
{
xacc
::
error
(
"xasm only support double and int literals in kernel calls.
\n
"
);
}
composite
->
applyRuntimeArguments
();
}
else
{
// add an arg for this
// this is probably coming from QCOR
if
(
p
.
which
()
==
0
)
{
// integer
composite
->
addArgument
(
"__xacc__literal_"
,
"int"
);
auto
tmp
=
composite
->
getArgument
(
"__xacc__literal_"
);
tmp
->
runtimeValue
.
insert
(
INTERNAL_ARGUMENT_VALUE_KEY
,
p
.
as
<
int
>
());
}
else
{
// double
composite
->
addArgument
(
"__xacc__literal_"
,
"double"
);
auto
tmp
=
composite
->
getArgument
(
"__xacc__literal_"
);
tmp
->
runtimeValue
.
insert
(
INTERNAL_ARGUMENT_VALUE_KEY
,
p
.
as
<
double
>
());
}
}
continue
;
}
else
{
// throw an error
xacc
::
error
(
...
...
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