Skip to content
GitLab
Menu
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
17ee51c4
Commit
17ee51c4
authored
Aug 07, 2019
by
Mccaskey, Alex
Browse files
adding Compiler to contributable services
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
c56c10fd
Pipeline
#66119
passed with stage
in 6 minutes and 23 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
python/examples/contribute_ir_generator.py
View file @
17ee51c4
...
...
@@ -25,7 +25,7 @@ buffer = xacc.qalloc(2)
irg2
=
xacc
.
getIRGenerator
(
'bell'
)
@
xacc
.
qpu
(
accelerator
=
qpu
)
@
xacc
.
qpu
(
accelerator
=
qpu
)
def
function
(
buffer
):
bell
()
...
...
python/xacc-py.cpp
View file @
17ee51c4
...
...
@@ -133,6 +133,31 @@ public:
std
::
vector
<
InstructionParameter
>
{})
override
{
return
nullptr
;}
};
class
PyCompiler
:
public
xacc
::
Compiler
{
public:
/* Inherit the constructors */
using
Compiler
::
Compiler
;
const
std
::
string
name
()
const
override
{
PYBIND11_OVERLOAD_PURE
(
const
std
::
string
,
xacc
::
Compiler
,
name
);
}
const
std
::
string
description
()
const
override
{
return
""
;
}
std
::
shared_ptr
<
IR
>
compile
(
const
std
::
string
&
src
,
std
::
shared_ptr
<
Accelerator
>
acc
)
{
PYBIND11_OVERLOAD_PURE
(
std
::
shared_ptr
<
IR
>
,
xacc
::
Compiler
,
compile
,
src
,
acc
);
}
std
::
shared_ptr
<
IR
>
compile
(
const
std
::
string
&
src
)
override
{
return
compile
(
src
,
nullptr
);
}
const
std
::
string
translate
(
const
std
::
string
&
bufferVariable
,
std
::
shared_ptr
<
Function
>
function
)
override
{
return
""
;
}
};
PYBIND11_MODULE
(
_pyxacc
,
m
)
{
m
.
doc
()
=
"Python bindings for XACC. XACC provides a plugin infrastructure for "
...
...
@@ -353,10 +378,11 @@ PYBIND11_MODULE(_pyxacc, m) {
""
);
// Expose the Compiler
py
::
class_
<
xacc
::
Compiler
,
std
::
shared_ptr
<
xacc
::
Compiler
>>
(
py
::
class_
<
xacc
::
Compiler
,
std
::
shared_ptr
<
xacc
::
Compiler
>
,
PyCompiler
>
(
m
,
"Compiler"
,
"The XACC Compiler takes as input quantum kernel source code, "
"and compiles it to the XACC intermediate representation."
)
.
def
(
py
::
init
<>
(),
""
)
.
def
(
"name"
,
&
xacc
::
Compiler
::
name
,
"Return the name of this Compiler."
)
.
def
(
"compile"
,
(
std
::
shared_ptr
<
xacc
::
IR
>
(
xacc
::
Compiler
::*
)(
...
...
xacc/XACC.cpp
View file @
17ee51c4
...
...
@@ -269,9 +269,13 @@ std::shared_ptr<Compiler> getCompiler(const std::string &name) {
error
(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API."
);
}
auto
c
=
xacc
::
getService
<
Compiler
>
(
name
);
auto
c
=
xacc
::
getService
<
Compiler
>
(
name
,
false
);
if
(
!
c
)
{
error
(
"Invalid Compiler. Could not find "
+
name
+
" in Service Registry."
);
if
(
xacc
::
hasContributedService
<
Compiler
>
(
name
))
{
c
=
xacc
::
getContributedService
<
Compiler
>
(
name
);
}
else
{
error
(
"Invalid Compiler. Could not find "
+
name
+
" in Service Registry."
);
}
}
return
c
;
}
...
...
xacc/service/ServiceRegistry.hpp
View file @
17ee51c4
...
...
@@ -40,8 +40,7 @@ using namespace cppmicroservices;
namespace
xacc
{
using
ContributableService
=
Variant
<
std
::
shared_ptr
<
IRGenerator
>
,
std
::
shared_ptr
<
Accelerator
>>
;
//,
// std::shared_ptr<Compiler>, std::shared_ptr<Algorithm>,
Variant
<
std
::
shared_ptr
<
IRGenerator
>
,
std
::
shared_ptr
<
Accelerator
>
,
std
::
shared_ptr
<
Compiler
>>
;
//, std::shared_ptr<Algorithm>,
// std::shared_ptr<Optimizer>, std::shared_ptr<IRProvider>>;
/**
* The ServiceRegistry provides the plugin infrastructure for XACC.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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