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
d21fec2b
Commit
d21fec2b
authored
Jul 17, 2017
by
Mccaskey, Alex
Browse files
Adding AQCAcceleratorBuffer, minor clean up
parent
92244eb1
Changes
9
Hide whitespace changes
Inline
Side-by-side
impls/dwave/CMakeLists.txt
View file @
d21fec2b
...
...
@@ -34,6 +34,7 @@ find_package(OpenSSL)
if
(
OPENSSL_FOUND
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/quantum/aqc/ir
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/quantum/aqc/compiler
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/quantum/aqc/accelerator
)
include_directories
(
${
CMAKE_SOURCE_DIR
}
/tpls/rapidjson/include
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
)
...
...
impls/dwave/DWQMICompiler.cpp
View file @
d21fec2b
...
...
@@ -33,6 +33,7 @@
#include
"DWQMICompiler.hpp"
#include
"DWKernel.hpp"
#include
"RuntimeOptions.hpp"
#include
"AQCAcceleratorBuffer.hpp"
namespace
xacc
{
...
...
@@ -53,6 +54,14 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
// Set the Kernel Source code
kernelSource
=
src
;
// Here we assume, there is just one allocation
// of qubits for the D-Wave -- all of them.
// auto bufName = acc->getAllocatedBufferNames()[0];
// auto buffer = acc->getBuffer(bufName);
// auto aqcBuffer = std::dynamic_pointer_cast<AQCAcceleratorBuffer>(buffer);
// if (!aqcBuffer) {
// XACCError("Invalid AcceleratorBuffer passed to DW QMI Compiler. Must be an AQCAcceleratorBuffer.");
// }
// Here we expect we have a kernel, only one kernel,
// and that it is just machine level instructions
...
...
@@ -119,6 +128,9 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
// Compute the minor graph embedding
auto
embedding
=
embeddingAlgorithm
->
embed
(
problemGraph
,
hardwareGraph
);
// Add the embedding to the AcceleratorBuffer
// aqcBuffer->setEmbedding(embedding);
auto
countEdgesBetweenSubTrees
=
[
&
](
std
::
list
<
int
>
Ti
,
std
::
list
<
int
>
Tj
)
->
int
{
int
nEdges
=
0
;
for
(
auto
i
:
Ti
)
{
...
...
impls/dwave/tests/DWQMICompilerTester.cpp
View file @
d21fec2b
...
...
@@ -35,6 +35,7 @@
#include
<boost/test/included/unit_test.hpp>
#include
"DWQMICompiler.hpp"
#include
"XACC.hpp"
#include
"AQCAcceleratorBuffer.hpp"
using
namespace
xacc
::
quantum
;
...
...
@@ -59,6 +60,8 @@ public:
virtual
std
::
shared_ptr
<
xacc
::
AcceleratorBuffer
>
createBuffer
(
const
std
::
string
&
varId
)
{
auto
b
=
std
::
make_shared
<
AQCAcceleratorBuffer
>
(
varId
,
1
);
storeBuffer
(
varId
,
b
);
}
virtual
void
initialize
()
{
...
...
@@ -86,6 +89,7 @@ public:
*/
virtual
std
::
shared_ptr
<
xacc
::
AcceleratorBuffer
>
createBuffer
(
const
std
::
string
&
varId
,
const
int
size
)
{
auto
b
=
std
::
make_shared
<
AQCAcceleratorBuffer
>
(
varId
,
size
);
}
};
...
...
@@ -114,7 +118,7 @@ public:
};
class
Shor
15FakeEmbedding
:
public
EmbeddingAlgorithm
{
class
Factoring
15FakeEmbedding
:
public
EmbeddingAlgorithm
{
public:
virtual
std
::
map
<
int
,
std
::
list
<
int
>>
embed
(
...
...
@@ -184,13 +188,13 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
BOOST_AUTO_TEST_CASE
(
checkShor15OneToOneMapping
)
{
EmbeddingAlgorithmRegistry
::
instance
()
->
add
(
Shor
15FakeEmbedding
().
name
(),
std
::
make_shared
<
EmbeddingAlgorithmRegistry
::
CreatorFunction
>
([]()
{
return
std
::
make_shared
<
Shor
15FakeEmbedding
>
();}));
EmbeddingAlgorithmRegistry
::
instance
()
->
add
(
Factoring
15FakeEmbedding
().
name
(),
std
::
make_shared
<
EmbeddingAlgorithmRegistry
::
CreatorFunction
>
([]()
{
return
std
::
make_shared
<
Factoring
15FakeEmbedding
>
();}));
auto
compiler
=
std
::
make_shared
<
DWQMICompiler
>
();
const
std
::
string
shor15QMI
=
"__qpu__
sh
or15() {
\n
"
"__qpu__
fact
or15() {
\n
"
" 0 0 20
\n
"
" 1 1 50
\n
"
" 2 2 60
\n
"
...
...
@@ -215,10 +219,11 @@ BOOST_AUTO_TEST_CASE(checkShor15OneToOneMapping) {
}
auto
acc
=
std
::
make_shared
<
FakeDWAcc
>
();
acc
->
createBuffer
(
"hello"
);
auto
ir
=
compiler
->
compile
(
shor15QMI
,
acc
);
auto
qmi
=
ir
->
getKernel
(
"
sh
or15"
)
->
toString
(
""
);
auto
qmi
=
ir
->
getKernel
(
"
fact
or15"
)
->
toString
(
""
);
std
::
cout
<<
qmi
<<
"
\n
"
;
...
...
quantum/aqc/CMakeLists.txt
View file @
d21fec2b
...
...
@@ -35,9 +35,10 @@ set (LIBRARY_NAME xacc-quantum-aqc)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/ir
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/compiler
)
include_directories
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/compiler/trivial
)
file
(
GLOB_RECURSE HEADERS *.hpp
)
file
(
GLOB SRC compiler/TrivialEmbeddingAlgorithm.cpp
)
file
(
GLOB SRC compiler/
trivial/
TrivialEmbeddingAlgorithm.cpp
)
# compiler/cmr/*.cpp)
add_library
(
${
LIBRARY_NAME
}
SHARED
${
SRC
}
)
...
...
quantum/aqc/accelerator/AQCAcceleratorBuffer.hpp
0 → 100644
View file @
d21fec2b
#ifndef QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#define QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#include
"AcceleratorBuffer.hpp"
namespace
xacc
{
namespace
quantum
{
class
AQCAcceleratorBuffer
:
public
AcceleratorBuffer
{
protected:
std
::
map
<
int
,
std
::
list
<
int
>>
embedding
;
std
::
vector
<
double
>
energies
;
public:
AQCAcceleratorBuffer
(
const
std
::
string
&
str
,
const
int
N
)
:
AcceleratorBuffer
(
str
,
N
)
{
}
template
<
typename
...
Indices
>
AQCAcceleratorBuffer
(
const
std
::
string
&
str
,
int
firstIndex
,
Indices
...
indices
)
:
AcceleratorBuffer
(
str
,
firstIndex
,
indices
...)
{
}
void
setEmbedding
(
std
::
map
<
int
,
std
::
list
<
int
>>
emb
)
{
embedding
=
emb
;
}
std
::
map
<
int
,
std
::
list
<
int
>>
getEmbedding
()
{
return
embedding
;
}
};
}
}
#endif
/* QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_ */
quantum/aqc/compiler/HUBO.hpp
View file @
d21fec2b
...
...
@@ -5,12 +5,14 @@
namespace
xacc
{
namespace
quantum
{
template
<
typename
ResultType
>
class
HUBO
{
public:
virtual
std
::
shared_ptr
<
xacc
::
quantum
::
DWGraph
>
reduceToQubo
(
std
::
vector
<
InstructionParameter
>
parameters
)
=
0
;
virtual
void
mapResults
(
std
::
shared_ptr
<
AcceleratorBuffer
>
resultBuffer
)
=
0
;
virtual
ResultType
mapResults
(
std
::
shared_ptr
<
AcceleratorBuffer
>
resultBuffer
)
=
0
;
virtual
~
HUBO
()
{}
};
...
...
quantum/aqc/compiler/TrivialEmbeddingAlgorithm.cpp
→
quantum/aqc/compiler/
trivial/
TrivialEmbeddingAlgorithm.cpp
View file @
d21fec2b
File moved
quantum/aqc/compiler/TrivialEmbeddingAlgorithm.hpp
→
quantum/aqc/compiler/
trivial/
TrivialEmbeddingAlgorithm.hpp
View file @
d21fec2b
File moved
xacc/utils/Graph.hpp
View file @
d21fec2b
...
...
@@ -249,6 +249,12 @@ public:
vertex
(
tgtIndex
,
*
_graph
.
get
()),
*
_graph
.
get
());
}
void
removeEdge
(
const
int
srcIndex
,
const
int
tgtIndex
)
{
auto
v
=
vertex
(
srcIndex
,
*
_graph
.
get
());
auto
u
=
vertex
(
tgtIndex
,
*
_graph
.
get
());
remove_edge
(
v
,
u
,
*
_graph
.
get
());
}
/**
* Add a vertex to this Graph.
*/
...
...
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