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
764ba1da
Commit
764ba1da
authored
Mar 28, 2018
by
Mccaskey, Alex
Browse files
saving work done on removing gate registry, this branch is broken
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
420a6ea4
Changes
80
Hide whitespace changes
Inline
Side-by-side
python/CMakeLists.txt
View file @
764ba1da
...
...
@@ -12,9 +12,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set
(
CMAKE_MACOSX_RPATH ON
)
endif
()
#find_package(PythonLibs)
#if(PythonLibs_FOUND)
set
(
CppMicroServices_DIR
"
${
CPPUS_LIBRARY_DIR
}
/../share/cppmicroservices3/cmake"
)
# Modify our CMAKE_MODULE_PATH
...
...
@@ -53,16 +50,18 @@ if (NOT cppus_has_d_suffix)
endif
()
target_link_libraries
(
pyxacc PRIVATE xacc xacc-quantum-gate xacc-quantum-aqc
${
CppUsLib
}
${
Boost_LIBRARIES
}
cpprest
${
OPENSSL_LIBRARIES
}
)
if
(
APPLE
)
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"@loader_path/lib"
)
else
()
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"$ORIGIN/lib"
)
endif
()
if
(
FROM_SETUP_PY
)
install
(
TARGETS pyxacc DESTINATION
${
CMAKE_INSTALL_PREFIX
}
)
if
(
APPLE
)
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"@loader_path/lib"
)
else
()
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"$ORIGIN/lib"
)
endif
()
install
(
TARGETS pyxacc DESTINATION
${
CMAKE_INSTALL_PREFIX
}
)
else
()
install
(
TARGETS pyxacc DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lib/python
)
if
(
APPLE
)
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"@loader_path/.."
)
else
()
set_target_properties
(
pyxacc PROPERTIES INSTALL_RPATH
"$ORIGIN/.."
)
endif
()
install
(
TARGETS pyxacc DESTINATION
${
CMAKE_INSTALL_PREFIX
}
/lib/python
)
endif
()
#endif()
python/xacc-py.cpp
View file @
764ba1da
...
...
@@ -9,6 +9,7 @@
#include
"GateInstruction.hpp"
#include
"GateFunction.hpp"
#include
"GateQIR.hpp"
#include
"InstructionService.hpp"
namespace
py
=
pybind11
;
using
namespace
xacc
;
...
...
@@ -29,14 +30,12 @@ namespace pybind11 { namespace detail {
};
}}
// namespace pybind11::detail
std
::
shared_ptr
<
GateInstruction
>
create
(
const
std
::
string
&
name
,
std
::
vector
<
int
>
qbits
,
std
::
vector
<
InstructionParameter
>
params
=
std
::
vector
<
InstructionParameter
>
{})
{
auto
g
=
GateInstructionRegistry
::
instance
()
->
create
(
name
,
qbits
);
int
idx
=
0
;
for
(
auto
&
a
:
params
)
{
g
->
setParameter
(
idx
,
a
);
idx
++
;
}
return
g
;
std
::
shared_ptr
<
Instruction
>
create
(
const
std
::
string
&
name
,
std
::
vector
<
int
>
qbits
,
std
::
vector
<
InstructionParameter
>
params
=
std
::
vector
<
InstructionParameter
>
{
})
{
std
::
cout
<<
"HELLO WORLD "
<<
name
<<
"
\n
"
;
auto
service
=
ServiceRegistry
::
instance
()
->
getService
<
InstructionService
>
(
"gate"
);
return
service
->
create
(
name
,
qbits
,
params
);
}
void
setCredentials
(
const
std
::
string
&
accelerator
,
const
std
::
string
&
apiKey
,
const
std
::
string
&
url
=
""
,
const
std
::
string
&
userId
=
""
)
{
...
...
@@ -106,7 +105,7 @@ PYBIND11_MODULE(pyxacc, m) {
// Expose the Instruction interface
py
::
class_
<
xacc
::
Instruction
,
std
::
shared_ptr
<
xacc
::
Instruction
>>
inst
(
m
,
"Instruction"
,
"Instruction wraps the XACC C++ Instruction class -"
" the base for all XACC intermediate representation instructions. Instructions, for example, can be common gates like Hadamard or CNOT."
);
inst
.
def
(
"
getN
ame"
,
&
xacc
::
Instruction
::
getN
ame
,
"Return the name of this Instruction."
);
inst
.
def
(
"
n
ame"
,
&
xacc
::
Instruction
::
n
ame
,
"Return the name of this Instruction."
);
inst
.
def
(
"nParameters"
,
&
xacc
::
Instruction
::
nParameters
,
"Return the number of parameters this Instruction has."
);
// Expose the Function interface
...
...
@@ -217,6 +216,7 @@ PYBIND11_MODULE(pyxacc, m) {
m
.
def
(
"optionExists"
,
&
xacc
::
optionExists
,
"Set an XACC framework option."
);
// m.def("translate", &xacc::translate, "Translate one language quantum kernel to another");
// m.def("translateWithVisitor", &xacc::translateWithVisitor, "Translate one language quantum kernel to another");
m
.
def
(
"getInstructionService"
,
&
xacc
::
getService
<
InstructionService
>
,
""
);
m
.
def
(
"Finalize"
,
&
xacc
::
Finalize
,
"Finalize the framework"
);
py
::
module
gatesub
=
m
.
def_submodule
(
"gate"
,
"Gate model quantum computing data structures."
);
...
...
@@ -225,7 +225,7 @@ PYBIND11_MODULE(pyxacc, m) {
std
::
shared_ptr
<
xacc
::
quantum
::
GateInstruction
>>
gateinst
(
gatesub
,
"GateInstruction"
,
"GateInstruction models gate model quantum computing instructions."
);
gateinst
.
def
(
"
getN
ame"
,
&
xacc
::
quantum
::
GateInstruction
::
getN
ame
,
"Return the name of this Instruction."
);
gateinst
.
def
(
"
n
ame"
,
&
xacc
::
quantum
::
GateInstruction
::
n
ame
,
"Return the name of this Instruction."
);
gateinst
.
def
(
"bits"
,
&
xacc
::
quantum
::
GateInstruction
::
bits
,
"Return the qubits this gate operates on"
);
gateinst
.
def
(
"nParameters"
,
&
xacc
::
quantum
::
GateInstruction
::
nParameters
,
"Return the number of parameters this gate requires."
);
gateinst
.
def
(
"getParameter"
,
&
xacc
::
quantum
::
GateInstruction
::
getParameter
,
"Return the parameter at the given index"
);
...
...
@@ -238,7 +238,7 @@ PYBIND11_MODULE(pyxacc, m) {
"GateFunction description, fill this in later"
);
gatefunction
.
def
(
py
::
init
<
const
std
::
string
&>
(),
"The constructor"
);
gatefunction
.
def
(
py
::
init
<
const
std
::
string
&
,
std
::
vector
<
xacc
::
InstructionParameter
>>
(),
"The constructor"
);
gatefunction
.
def
(
"
getN
ame"
,
&
xacc
::
quantum
::
GateFunction
::
getN
ame
,
"Return the name of this Instruction."
);
gatefunction
.
def
(
"
n
ame"
,
&
xacc
::
quantum
::
GateFunction
::
n
ame
,
"Return the name of this Instruction."
);
gatefunction
.
def
(
"add"
,
&
xacc
::
quantum
::
GateFunction
::
addInstruction
,
"Add an Instruction to this function."
);
gatefunction
.
def
(
"toString"
,
&
xacc
::
quantum
::
GateFunction
::
toString
,
"Return the function as a string representation."
);
...
...
python/xacc.egg-info/PKG-INFO
0 → 100644
View file @
764ba1da
Metadata-Version: 1.0
Name: xacc
Version: 0.1.0
Summary: Hardware-agnostic quantum programming framework
Home-page: UNKNOWN
Author: Alex McCaskey
Author-email: xacc-dev@eclipse.org
License: UNKNOWN
Description: XACC provides a language and hardware agnostic programming framework for hybrid classical-quantum applications.
Platform: UNKNOWN
python/xacc.egg-info/SOURCES.txt
0 → 100644
View file @
764ba1da
README.md
setup.py
python/xacc.egg-info/PKG-INFO
python/xacc.egg-info/SOURCES.txt
python/xacc.egg-info/dependency_links.txt
python/xacc.egg-info/not-zip-safe
python/xacc.egg-info/top_level.txt
tools/framework/xacc-framework
\ No newline at end of file
python/xacc.egg-info/dependency_links.txt
0 → 100644
View file @
764ba1da
python/xacc.egg-info/not-zip-safe
0 → 100644
View file @
764ba1da
python/xacc.egg-info/top_level.txt
0 → 100644
View file @
764ba1da
pyxacc
quantum/aqc/ir/DWIR.hpp
View file @
764ba1da
...
...
@@ -62,12 +62,12 @@ public:
virtual
bool
kernelExists
(
const
std
::
string
&
name
)
{
return
std
::
any_of
(
kernels
.
cbegin
(),
kernels
.
cend
(),
[
=
](
std
::
shared_ptr
<
Function
>
i
)
{
return
i
->
getN
ame
()
==
name
;});
[
=
](
std
::
shared_ptr
<
Function
>
i
)
{
return
i
->
n
ame
()
==
name
;});
}
virtual
std
::
shared_ptr
<
Function
>
getKernel
(
const
std
::
string
&
name
)
{
for
(
auto
f
:
kernels
)
{
if
(
f
->
getN
ame
()
==
name
)
{
if
(
f
->
n
ame
()
==
name
)
{
return
f
;
}
}
...
...
quantum/aqc/ir/DWKernel.hpp
View file @
764ba1da
...
...
@@ -30,7 +30,7 @@ protected:
std
::
list
<
InstPtr
>
instructions
;
std
::
string
name
;
std
::
string
_
name
;
public:
...
...
@@ -41,7 +41,7 @@ public:
* @param id
* @param name
*/
DWKernel
(
std
::
string
kernelName
)
:
name
(
kernelName
)
{
DWKernel
(
std
::
string
kernelName
)
:
_
name
(
kernelName
)
{
}
virtual
const
int
nInstructions
()
{
...
...
@@ -104,8 +104,12 @@ public:
* Return the name of this function
* @return
*/
virtual
const
std
::
string
getName
()
{
return
name
;
virtual
const
std
::
string
name
()
const
{
return
_name
;
}
virtual
const
std
::
string
description
()
const
{
return
""
;
}
/**
...
...
quantum/aqc/ir/DWQMI.hpp
View file @
764ba1da
...
...
@@ -95,10 +95,12 @@ public:
*
* @return name The name of this Instruction
*/
virtual
const
std
::
string
getN
ame
()
{
virtual
const
std
::
string
n
ame
()
const
{
return
"dw-qmi"
;
}
virtual
const
std
::
string
description
()
const
{
return
""
;
}
virtual
const
std
::
string
getTag
()
{
return
""
;
}
...
...
quantum/aqc/ir/tests/DWKernelTester.cpp
View file @
764ba1da
...
...
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(checkDWKernelConstruction) {
kernel
.
addInstruction
(
qmi3
);
BOOST_VERIFY
(
kernel
.
nInstructions
()
==
3
);
BOOST_VERIFY
(
kernel
.
getN
ame
()
==
"foo"
);
BOOST_VERIFY
(
kernel
.
n
ame
()
==
"foo"
);
BOOST_VERIFY
(
kernel
.
getInstruction
(
0
)
==
qmi
);
BOOST_VERIFY
(
kernel
.
getInstruction
(
1
)
==
qmi2
);
BOOST_VERIFY
(
kernel
.
getInstruction
(
2
)
==
qmi3
);
...
...
quantum/gate/CMakeLists.txt
View file @
764ba1da
...
...
@@ -57,7 +57,6 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
)
link_directories
(
${
Boost_LIBRARY_DIR
}
)
set
(
CppUsLib CppMicroServicesd
)
link_directories
(
${
CPPUS_LIBRARY_DIR
}
)
...
...
quantum/gate/GateQuantumActivator.cpp
View file @
764ba1da
...
...
@@ -19,6 +19,22 @@
#include
"cppmicroservices/BundleContext.h"
#include
"cppmicroservices/ServiceProperties.h"
#include
"GateInstructionService.hpp"
#include
"Hadamard.hpp"
#include
"CNOT.hpp"
#include
"X.hpp"
#include
"Y.hpp"
#include
"Z.hpp"
#include
"ConditionalFunction.hpp"
#include
"Rz.hpp"
#include
"Rx.hpp"
#include
"Ry.hpp"
#include
"CPhase.hpp"
#include
"Swap.hpp"
#include
"Measure.hpp"
#include
"Identity.hpp"
#include
"CZ.hpp"
#include
<memory>
#include
<set>
...
...
@@ -46,6 +62,9 @@ public:
auto
readout
=
std
::
make_shared
<
xacc
::
quantum
::
ReadoutErrorIRPreprocessor
>
();
auto
qbitmap
=
std
::
make_shared
<
xacc
::
quantum
::
QubitMapIRPreprocessor
>
();
auto
giservice
=
std
::
make_shared
<
xacc
::
quantum
::
GateInstructionService
>
();
context
.
RegisterService
<
xacc
::
InstructionService
>
(
giservice
);
context
.
RegisterService
<
xacc
::
Preprocessor
>
(
kp
);
context
.
RegisterService
<
xacc
::
IRGenerator
>
(
iqft
);
context
.
RegisterService
<
xacc
::
IRGenerator
>
(
qft
);
...
...
@@ -53,6 +72,34 @@ public:
context
.
RegisterService
<
xacc
::
IRPreprocessor
>
(
readout
);
context
.
RegisterService
<
xacc
::
IRPreprocessor
>
(
qbitmap
);
auto
h
=
std
::
make_shared
<
xacc
::
quantum
::
Hadamard
>
();
auto
cn
=
std
::
make_shared
<
xacc
::
quantum
::
CNOT
>
();
auto
cp
=
std
::
make_shared
<
xacc
::
quantum
::
CPhase
>
();
auto
cz
=
std
::
make_shared
<
xacc
::
quantum
::
CZ
>
();
auto
id
=
std
::
make_shared
<
xacc
::
quantum
::
Identity
>
();
auto
m
=
std
::
make_shared
<
xacc
::
quantum
::
Measure
>
();
auto
rx
=
std
::
make_shared
<
xacc
::
quantum
::
Rx
>
();
auto
ry
=
std
::
make_shared
<
xacc
::
quantum
::
Ry
>
();
auto
rz
=
std
::
make_shared
<
xacc
::
quantum
::
Rz
>
();
auto
x
=
std
::
make_shared
<
xacc
::
quantum
::
X
>
();
auto
y
=
std
::
make_shared
<
xacc
::
quantum
::
Y
>
();
auto
z
=
std
::
make_shared
<
xacc
::
quantum
::
Z
>
();
auto
sw
=
std
::
make_shared
<
xacc
::
quantum
::
Swap
>
();
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
h
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
cn
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
cp
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
cz
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
id
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
m
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
rx
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
ry
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
rz
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
x
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
y
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
z
);
context
.
RegisterService
<
xacc
::
quantum
::
GateInstruction
>
(
sw
);
}
/**
...
...
quantum/gate/accelerator/ReadoutErrorAcceleratorBufferPostprocessor.cpp
View file @
764ba1da
...
...
@@ -77,7 +77,7 @@ std::vector<std::shared_ptr<AcceleratorBuffer>> ReadoutErrorAcceleratorBufferPos
first
=
true
;
}
xacc
::
info
(
kernel
->
getN
ame
()
+
" - Computing measurement probability for bit string = "
+
localBitStr
);
xacc
::
info
(
kernel
->
n
ame
()
+
" - Computing measurement probability for bit string = "
+
localBitStr
);
probs
.
push_back
(
subList
[
i
]
->
computeMeasurementProbability
(
localBitStr
));
counter
++
;
...
...
quantum/gate/accelerator/tests/ReadoutErrorAcceleratorBufferPostprocessorTester.cpp
View file @
764ba1da
...
...
@@ -20,6 +20,7 @@
#include
"XACC.hpp"
#include
"GateFunction.hpp"
#include
"GateInstruction.hpp"
#include
"GateInstructionService.hpp"
using
namespace
xacc
;
...
...
@@ -33,6 +34,8 @@ std::shared_ptr<IR> createXACCIR(std::unordered_map<std::string, Term> terms) {
int
counter
=
0
;
auto
pi
=
boost
::
math
::
constants
::
pi
<
double
>
();
GateInstructionService
gateRegistry
;
// Populate GateQIR now...
for
(
auto
&
inst
:
terms
)
{
...
...
@@ -46,7 +49,7 @@ std::shared_ptr<IR> createXACCIR(std::unordered_map<std::string, Term> terms) {
// Loop over all terms in the Spin Instruction
// and create instructions to run on the Gate QPU.
std
::
vector
<
std
::
shared_ptr
<
xacc
::
quantum
::
Gate
Instruction
>>
measurements
;
std
::
vector
<
std
::
shared_ptr
<
xacc
::
Instruction
>>
measurements
;
std
::
vector
<
std
::
pair
<
int
,
std
::
string
>>
terms
;
for
(
auto
&
kv
:
spinInst
)
{
...
...
@@ -58,20 +61,18 @@ std::shared_ptr<IR> createXACCIR(std::unordered_map<std::string, Term> terms) {
for
(
int
i
=
terms
.
size
()
-
1
;
i
>=
0
;
i
--
)
{
auto
qbit
=
terms
[
i
].
first
;
auto
gateName
=
terms
[
i
].
second
;
auto
gateRegistry
=
xacc
::
quantum
::
GateInstructionRegistry
::
instance
();
auto
meas
=
gateRegistry
->
create
(
"Measure"
,
auto
meas
=
gateRegistry
.
create
(
"Measure"
,
std
::
vector
<
int
>
{
qbit
});
xacc
::
InstructionParameter
classicalIdx
(
qbit
);
meas
->
setParameter
(
0
,
classicalIdx
);
measurements
.
push_back
(
meas
);
if
(
gateName
==
"X"
)
{
auto
hadamard
=
gateRegistry
->
create
(
"H"
,
std
::
vector
<
int
>
{
auto
hadamard
=
gateRegistry
.
create
(
"H"
,
std
::
vector
<
int
>
{
qbit
});
gateFunction
->
addInstruction
(
hadamard
);
}
else
if
(
gateName
==
"Y"
)
{
auto
rx
=
gateRegistry
->
create
(
"Rx"
,
std
::
vector
<
int
>
{
qbit
});
auto
rx
=
gateRegistry
.
create
(
"Rx"
,
std
::
vector
<
int
>
{
qbit
});
InstructionParameter
p
(
pi
/
2.0
);
rx
->
setParameter
(
0
,
p
);
gateFunction
->
addInstruction
(
rx
);
...
...
@@ -115,10 +116,11 @@ public:
BOOST_AUTO_TEST_CASE
(
checkSimple
)
{
xacc
::
Initialize
();
// Simple example H = X0
std
::
vector
<
std
::
string
>
orderedTerms
{
"Z0"
};
auto
gateRegistry
=
GateInstructionRegistry
::
instance
(
);
auto
gateRegistry
=
xacc
::
getService
<
InstructionService
>
(
"gate"
);
// Construct IR for this
auto
ir
=
createXACCIR
(
{
{
"Z0"
,
Term
{
{
0
,
"Z"
}
}
}
});
...
...
@@ -158,6 +160,7 @@ BOOST_AUTO_TEST_CASE(checkSimple) {
std
::
cout
<<
"HELLO: "
<<
fixed
[
0
]
->
getExpectationValueZ
()
<<
"
\n
"
;
xacc
::
Finalize
();
// BOOST_VERIFY(std::fabs(fixed[0]->getExpectationValueZ() - .911111) < 1e-6);
}
quantum/gate/compiler/KernelReplacementPreprocessor.hpp
View file @
764ba1da
...
...
@@ -54,14 +54,6 @@ public:
std
::
shared_ptr
<
Compiler
>
compiler
,
std
::
shared_ptr
<
Accelerator
>
accelerator
);
/**
* Return the name of this Preprocessor
* @return name Preprocessor name
*/
virtual
const
std
::
string
getName
()
{
return
"kernel-replacement"
;
}
virtual
const
std
::
string
name
()
const
{
return
"kernel-replacement"
;
}
...
...
quantum/gate/compiler/tests/KernelReplacementPreprocessorTester.cpp
View file @
764ba1da
...
...
@@ -68,10 +68,6 @@ public:
return
translated
;
}
virtual
const
std
::
string
getName
()
{
return
"Dummy"
;
}
virtual
const
std
::
string
name
()
const
{
return
""
;
}
...
...
quantum/gate/ir/GateFunction.hpp
View file @
764ba1da
...
...
@@ -13,7 +13,6 @@
#ifndef QUANTUM_GATEQIR_QFUNCTION_HPP_
#define QUANTUM_GATEQIR_QFUNCTION_HPP_
#include
"Registry.hpp"
#include
"Function.hpp"
#include
"XACC.hpp"
...
...
@@ -138,10 +137,18 @@ public:
* Return the name of this function
* @return
*/
virtual
const
std
::
string
getN
ame
()
{
virtual
const
std
::
string
n
ame
()
const
{
return
functionName
;
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual
const
std
::
string
description
()
const
{
return
""
;
}
/**
* Return the qubits this function acts on.
* @return
...
...
@@ -230,7 +237,7 @@ public:
if
(
inst
->
isComposite
())
{
std
::
dynamic_pointer_cast
<
Function
>
(
inst
)
->
evaluateVariableParameters
(
runtimeParameters
);
}
else
if
(
inst
->
isParameterized
()
&&
inst
->
getN
ame
()
!=
"Measure"
)
{
}
else
if
(
inst
->
isParameterized
()
&&
inst
->
n
ame
()
!=
"Measure"
)
{
for
(
int
j
=
0
;
j
<
inst
->
nParameters
();
++
j
)
{
auto
instParam
=
inst
->
getParameter
(
j
);
...
...
quantum/gate/ir/GateInstruction.hpp
View file @
764ba1da
...
...
@@ -14,18 +14,22 @@
#define QUANTUM_GATE_GATEQIR_GATEINSTRUCTION_HPP_
#include
"Instruction.hpp"
#include
"Registry.hpp"
#include
<boost/lexical_cast.hpp>
#include
"Cloneable.hpp"
namespace
xacc
{
namespace
quantum
{
class
GateInstructionService
;
/**
*/
class
GateInstruction
:
public
virtual
Instruction
{
class
GateInstruction
:
public
virtual
Instruction
,
public
Cloneable
<
GateInstruction
>
{
protected:
friend
class
GateInstructionService
;
/**
* Reference to this instructions name
*/
...
...
@@ -40,9 +44,16 @@ protected:
std
::
vector
<
InstructionParameter
>
parameters
;
virtual
void
setBits
(
std
::
vector
<
int
>
bits
)
{
qbits
=
bits
;
}
public:
GateInstruction
()
=
delete
;
GateInstruction
()
{}
GateInstruction
(
std
::
string
name
)
:
gateName
(
name
)
{}
GateInstruction
(
std
::
string
name
,
std
::
vector
<
InstructionParameter
>
params
)
:
gateName
(
name
),
parameters
(
params
)
{}
GateInstruction
(
std
::
vector
<
int
>
qubts
)
:
gateName
(
"UNKNOWN"
),
qbits
(
qubts
),
parameters
(
std
::
vector
<
InstructionParameter
>
{})
{
...
...
@@ -75,10 +86,13 @@ public:
* Return the instruction name.
* @return
*/
virtual
const
std
::
string
getN
ame
()
{
virtual
const
std
::
string
n
ame
()
const
{
return
gateName
;
}
virtual
const
std
::
string
description
()
const
{
return
""
;
}
/**
* Return the list of qubits this instruction acts on.
* @return
...
...
@@ -176,27 +190,6 @@ public:
}
};
/**
*/
using
GateInstructionRegistry
=
Registry
<
GateInstruction
,
std
::
vector
<
int
>>
;
/**
*/
template
<
typename
T
>
class
RegisterGateInstruction
{
public:
RegisterGateInstruction
(
const
std
::
string
&
name
)
{
GateInstructionRegistry
::
CreatorFunctionPtr
f
=
std
::
make_shared
<
GateInstructionRegistry
::
CreatorFunction
>
(
[](
std
::
vector
<
int
>
qubits
)
{
return
std
::
make_shared
<
T
>
(
qubits
);
});
GateInstructionRegistry
::
instance
()
->
add
(
name
,
f
);
}
};
}
}
...
...
quantum/gate/ir/GateInstructionService.hpp
0 → 100644
View file @
764ba1da
#ifndef QUANTUM_GATE_GATEINSTRUCTIONSERVICE_HPP_
#define QUANTUM_GATE_GATEINSTRUCTIONSERVICE_HPP_
#include
"XACC.hpp"
#include
"Identifiable.hpp"
#include
"GateInstruction.hpp"
#include
"InstructionService.hpp"
namespace
xacc
{
namespace
quantum
{
class
GateInstructionService
:
public
InstructionService
{
public:
virtual
std
::
shared_ptr
<
Instruction
>
create
(
const
std
::
string
name
,
std
::
vector
<
int
>
bits
,
std
::
vector
<
InstructionParameter
>
parameters
=
std
::
vector
<
InstructionParameter
>
{
})
{
std
::
shared_ptr
<
GateInstruction
>
inst
=
ServiceRegistry
::
instance
()
->
getService
<
GateInstruction
>
(
name
);
inst
->
setBits
(
bits
);
int
idx
=
0
;
for
(
auto
&
a
:
parameters
)
{
inst
->
setParameter
(
idx
,
a
);
idx
++
;
}
return
inst
;
}
virtual
std
::
vector
<
std
::
string
>
getInstructions
()
{
std
::
vector
<
std
::
string
>
ret
;
for
(
auto
i
:
ServiceRegistry
::
instance
()
->
getRegisteredIds
<
GateInstruction
>
())
{
ret
.
push_back
(
i
);
}
return
ret
;
}
/**
* Return the name of this instance.
*
* @return name The string name
*/
virtual
const
std
::
string
name
()
const
{
return
"gate"
;
}
/**
* Return the description of this instance
* @return description The description of this object.
*/
virtual
const
std
::
string
description
()
const
{
return
""
;
}
};
}
}
#endif
Prev
1
2
3
4
Next
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