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
4925b994
Commit
4925b994
authored
Jan 25, 2017
by
Mccaskey, Alex
Browse files
Adding first example code for XACC API usage - teleportation
parent
7eed6f0e
Changes
14
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
4925b994
/***********************************************************************************
*
Copyright
(
c
)
2016, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS"
AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*
(
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION
)
HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*
(
INCLUDING NEGLIGENCE OR OTHERWISE
)
ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
project
(
XACC CXX
)
cmake_minimum_required
(
VERSION 2.8
)
set
(
CMAKE_DISABLE_IN_SOURCE_BUILDS ON
)
...
...
@@ -37,6 +67,7 @@ include_directories("${CMAKE_SOURCE_DIR}/xacc")
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/xacc/compiler"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/xacc/program"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/xacc/accelerator"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/xacc/utils"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/tpls/common/factory"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/tpls/common/graph"
)
include_directories
(
"
${
CMAKE_SOURCE_DIR
}
/tpls/common/exception"
)
...
...
@@ -44,3 +75,4 @@ include_directories("${CMAKE_SOURCE_DIR}/tpls/common/exception")
add_subdirectory
(
tpls
)
add_subdirectory
(
xacc
)
add_subdirectory
(
quantum
)
add_subdirectory
(
examples
)
examples/CMakeLists.txt
0 → 100644
View file @
4925b994
add_subdirectory
(
quantum
)
examples/quantum/CMakeLists.txt
0 → 100644
View file @
4925b994
add_subdirectory
(
gate
)
examples/quantum/gate/CMakeLists.txt
0 → 100644
View file @
4925b994
/***********************************************************************************
*
Copyright
(
c
)
2016, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS"
AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*
(
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION
)
HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*
(
INCLUDING NEGLIGENCE OR OTHERWISE
)
ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
add_executable
(
teleport_scaffold teleport_scaffold.cpp
)
target_link_libraries
(
teleport_scaffold xacc-scaffold
${
Boost_LIBRARIES
}
)
\ No newline at end of file
examples/quantum/gate/teleport_scaffold.cpp
0 → 100644
View file @
4925b994
/***********************************************************************************
* Copyright (c) 2016, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
#include
"Program.hpp"
/**
* FIXME For now, create a fake accelerator
* This will later come from QVM
*/
class
IBM5Qubit
:
public
xacc
::
Accelerator
{
public:
virtual
AcceleratorType
getType
()
{
return
AcceleratorType
::
qpu_gate
;
}
virtual
std
::
vector
<
xacc
::
IRTransformation
>
getIRTransformations
()
{
std
::
vector
<
xacc
::
IRTransformation
>
v
;
return
v
;
}
virtual
~
IBM5Qubit
()
{
}
};
// Quantum Kernel executing teleportation of
// qubit state to another.
const
std
::
string
src
(
"__qpu__ teleport () {
\n
"
" qbit q[3];
\n
"
" cbit c[2];
\n
"
" H(q[1]);
\n
"
" CNOT(q[1],q[2]);
\n
"
" CNOT(q[0],q[1]);
\n
"
" H(q[0]);
\n
"
" MeasZ(q[0]);
\n
"
" MeasZ(q[1]);
\n
"
" // cZ
\n
"
" H(q[2]);
\n
"
" CNOT(q[2], q[1]);
\n
"
" H(q[2]);
\n
"
" // cX = CNOT
\n
"
" CNOT(q[2], q[0]);
\n
"
"}
\n
"
);
int
main
(
int
argc
,
char
**
argv
)
{
auto
ibm_qpu
=
std
::
make_shared
<
IBM5Qubit
>
();
xacc
::
Program
quantumProgram
(
ibm_qpu
,
src
);
quantumProgram
.
build
(
"--compiler scaffold --writeIR teleport.xaccir"
);
// FIXME Get Kernel, execute, get result
return
0
;
}
quantum/gate/scaffold/CMakeLists.txt
View file @
4925b994
/***********************************************************************************
*
Copyright
(
c
)
2016, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the xacc nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS"
AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*
(
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION
)
HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*
(
INCLUDING NEGLIGENCE OR OTHERWISE
)
ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Contributors:
* Initial API and implementation - Alex McCaskey
*
**********************************************************************************/
set
(
PACKAGE_NAME
"Scaffold XACC Runtime"
)
set
(
PACKAGE_DESCIPTION
"Scaffold XACC Programming Framework"
)
set
(
LIBRARY_NAME xacc-scaffold
)
...
...
quantum/gate/scaffold/tests/ScaffoldCompilerTester.cpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
quantum/gate/utils/QasmToGraph.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
@@ -46,7 +46,9 @@ using boost::assign::map_list_of;
* Enumeration of gates we support
*/
enum
SupportedGates
{
H
,
CNot
,
C_Z
,
C_X
,
Measure
,
X
,
Y
,
Z
,
T
,
S
,
ZZ
,
SS
,
Swap
,
Toffoli
,
InitialState
,
FinalState
H
,
CNot
,
C_Z
,
C_X
,
Measure
,
X
,
Y
,
Z
,
T
,
S
,
ZZ
,
SS
,
Swap
,
Toffoli
,
InitialState
,
FinalState
};
/**
...
...
xacc/accelerator/Accelerator.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
@@ -50,6 +50,7 @@ public:
}
virtual
~
Accelerator
()
{}
};
}
#endif
xacc/compiler/Compiler.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
@@ -41,14 +41,6 @@ using namespace qci::common;
namespace
xacc
{
template
<
typename
T
>
class
Type
{
public:
void
*
allocate
()
{
return
new
T
;
}
T
*
cast
(
void
*
obj
)
{
return
static_cast
<
T
*>
(
obj
);
}
};
/**
* The ICompiler provides an interface for clients to realize to
* provide a mechanism for compiling a provided source string to
...
...
@@ -101,7 +93,6 @@ public:
// amenable to their specific compilation.
modifySource
();
// Unpack args into Types and values
return
getAsDerived
().
compile
();
}
...
...
xacc/compiler/GraphIR.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
xacc/compiler/IR.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
@@ -32,7 +32,7 @@
#define XACC_COMPILER_IR_HPP_
#include
"AbstractFactory.hpp"
#include
<ostream>
#include
<
i
ostream>
namespace
xacc
{
...
...
@@ -43,6 +43,7 @@ class IR {
public:
virtual
std
::
string
toString
()
=
0
;
virtual
void
persist
(
std
::
ostream
&
outStream
)
=
0
;
virtual
void
read
(
std
::
istream
&
inStream
)
=
0
;
virtual
~
IR
()
{}
};
...
...
xacc/program/Program.hpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
@@ -43,6 +43,7 @@
#include
"QCIError.hpp"
#include
"XaccUtils.hpp"
#include
"XACC.hpp"
#include
<fstream>
using
namespace
boost
::
program_options
;
using
namespace
qci
::
common
;
...
...
@@ -50,20 +51,44 @@ using namespace qci::common;
namespace
xacc
{
/**
*
* The Program is the main entrypoint for the XACC
* API. Users with accelerator kernels must construct a
* valid Program to be compiled and executed on the
* attached accelerator. Programs must be given the
* Accelerator reference to be used and kernel source
* code at construction time.
*/
class
Program
{
protected:
/**
* Reference to the source accelerator
* kernel code to be compiled and executed
*/
std
::
string
src
;
/**
* Reference to the attached Accelerator to
* use in this compilation and execution
*/
std
::
shared_ptr
<
Accelerator
>
accelerator
;
/**
* Reference to a set of compiler command
* line options.
*/
std
::
shared_ptr
<
options_description
>
compilerOptions
;
public:
/**
* The Constructor, takes the Accelerator
* to execute on, and the source to compile and execute
*
* @param acc Attached Accelerator to execute
* @param sourceFile The kernel source code
*/
Program
(
std
::
shared_ptr
<
Accelerator
>
acc
,
const
std
::
string
&
sourceFile
)
:
src
(
sourceFile
)
{
accelerator
=
std
::
move
(
acc
);
...
...
@@ -71,9 +96,18 @@ public:
"XACC Compiler Options"
);
compilerOptions
->
add_options
()(
"help"
,
"Help Message"
)(
"compiler"
,
value
<
std
::
string
>
()
->
default_value
(
"scaffold"
),
"Indicate the compiler to be used."
);
"Indicate the compiler to be used."
)
(
"writeIR"
,
value
<
std
::
string
>
(),
"Persist generated IR to provided file name."
);
}
/**
* Execute the compilation mechanism on the provided program
* source kernel code to produce XACC IR that can be executed
* on the attached Accelerator.
*
* @param compilerArgStr Arguments for the compiler's execution
* @param runtimeArgs Runtime values for kernel arguments
*/
template
<
typename
...
RuntimeArgs
>
void
build
(
const
std
::
string
&
compilerArgStr
,
RuntimeArgs
...
runtimeArgs
)
{
...
...
@@ -104,21 +138,26 @@ public:
QCIError
(
"Bad source string or something.
\n
"
);
}
// Write the IR to file if the user requests it
if
(
compileParameters
.
count
(
"writeIR"
))
{
auto
fileStr
=
compileParameters
[
"writeIR"
].
as
<
std
::
string
>
();
std
::
ofstream
ostr
(
fileStr
);
ir
->
persist
(
ostr
);
}
// Execute IR Translations and Optimizations
// FIXME GET LIST OF TRANSFORMATION FROM
auto
acceleratorType
=
accelerator
->
getType
();
auto
defaultTransforms
=
getAcceleratorIndependentTransformations
(
acceleratorType
);
auto
accDepTransforms
=
accelerator
->
getIRTransformations
();
for
(
IRTransformation
&
t
:
defaultTransforms
)
{
t
.
transform
(
*
ir
.
get
());
}
for
(
IRTransformation
&
t
:
accDepTransforms
)
{
t
.
transform
(
*
ir
.
get
());
}
// Create Kernel from IR
//
FIXME
Create Kernel from IR
return
;
}
...
...
xacc/tests/ProgramTester.cpp
View file @
4925b994
...
...
@@ -9,7 +9,7 @@
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the
<organization>
nor the
* * Neither the name of the
xacc
nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
...
...
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