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
17c30f48
Commit
17c30f48
authored
Aug 26, 2021
by
Mccaskey, Alex
Browse files
Merge branch 'master' of
https://github.com/eclipse/xacc
parents
858cc950
fcb78ffa
Pipeline
#162780
passed with stage
in 12 minutes and 39 seconds
Changes
4
Pipelines
13
Hide whitespace changes
Inline
Side-by-side
quantum/plugins/algorithms/qaoa/qaoa.cpp
View file @
17c30f48
...
...
@@ -20,7 +20,7 @@
#include
"xacc_observable.hpp"
#include
"CompositeInstruction.hpp"
#include
"AlgorithmGradientStrategy.hpp"
#include
"IRTransformation.hpp"
#include
<cassert>
#include
<iomanip>
...
...
@@ -70,8 +70,21 @@ bool QAOA::initialize(const HeterogeneousMap ¶meters) {
if
(
parameters
.
pointerLikeExists
<
Observable
>
(
"ref-ham"
))
{
m_refHamObs
=
parameters
.
getPointerLike
<
Observable
>
(
"ref-ham"
);
}
m_irTransformation
=
nullptr
;
// This QPU has topology-constraint
if
(
!
m_qpu
->
getConnectivity
().
empty
())
{
if
(
parameters
.
pointerLikeExists
<
xacc
::
IRTransformation
>
(
"placement"
))
{
m_irTransformation
=
xacc
::
as_shared_ptr
(
parameters
.
getPointerLike
<
xacc
::
IRTransformation
>
(
"placement"
));
if
(
m_irTransformation
->
type
()
!=
xacc
::
IRTransformationType
::
Placement
)
{
xacc
::
error
(
m_irTransformation
->
name
()
+
" is not a placement service."
);
}
}
}
}
// Check if an initial composite instruction set has been provided
if
(
parameters
.
pointerLikeExists
<
CompositeInstruction
>
(
"initial-state"
))
{
m_initial_state
=
parameters
.
getPointerLike
<
CompositeInstruction
>
(
"initial-state"
);
...
...
@@ -175,6 +188,12 @@ void QAOA::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
auto
tmpBuffer
=
xacc
::
qalloc
(
buffer
->
size
());
std
::
vector
<
std
::
shared_ptr
<
CompositeInstruction
>>
fsToExec
{
kernels
[
0
]
->
operator
()(
x
)};
if
(
m_irTransformation
)
{
for
(
auto
&
composite
:
fsToExec
)
{
m_irTransformation
->
apply
(
composite
,
xacc
::
as_shared_ptr
<
xacc
::
Accelerator
>
(
m_qpu
));
}
}
m_qpu
->
execute
(
tmpBuffer
,
fsToExec
);
double
energy
=
m_costHamObs
->
postProcess
(
tmpBuffer
);
// We will only have one child buffer for each parameter set.
...
...
@@ -261,6 +280,12 @@ void QAOA::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
}
auto
tmpBuffer
=
xacc
::
qalloc
(
buffer
->
size
());
if
(
m_irTransformation
)
{
for
(
auto
&
composite
:
fsToExec
)
{
m_irTransformation
->
apply
(
composite
,
xacc
::
as_shared_ptr
<
xacc
::
Accelerator
>
(
m_qpu
));
}
}
m_qpu
->
execute
(
tmpBuffer
,
fsToExec
);
auto
buffers
=
tmpBuffer
->
getChildren
();
...
...
@@ -388,6 +413,12 @@ QAOA::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
// just execute the single observed kernel:
std
::
vector
<
std
::
shared_ptr
<
CompositeInstruction
>>
fsToExec
{
kernels
[
0
]
->
operator
()(
x
)};
if
(
m_irTransformation
)
{
for
(
auto
&
composite
:
fsToExec
)
{
m_irTransformation
->
apply
(
composite
,
xacc
::
as_shared_ptr
<
xacc
::
Accelerator
>
(
m_qpu
));
}
}
m_qpu
->
execute
(
buffer
,
fsToExec
);
const
double
finalCost
=
m_costHamObs
->
postProcess
(
buffer
);
// std::cout << "Compute energy from grouping: " << finalCost << "\n";
...
...
@@ -420,6 +451,12 @@ QAOA::execute(const std::shared_ptr<AcceleratorBuffer> buffer,
}
auto
tmpBuffer
=
xacc
::
qalloc
(
buffer
->
size
());
if
(
m_irTransformation
)
{
for
(
auto
&
composite
:
fsToExec
)
{
m_irTransformation
->
apply
(
composite
,
xacc
::
as_shared_ptr
<
xacc
::
Accelerator
>
(
m_qpu
));
}
}
m_qpu
->
execute
(
tmpBuffer
,
fsToExec
);
auto
buffers
=
tmpBuffer
->
getChildren
();
...
...
quantum/plugins/algorithms/qaoa/qaoa.hpp
View file @
17c30f48
...
...
@@ -18,6 +18,8 @@
#include
"AlgorithmGradientStrategy.hpp"
namespace
xacc
{
class
IRTransformation
;
namespace
algorithm
{
class
QAOA
:
public
Algorithm
{
...
...
@@ -42,6 +44,7 @@ private:
bool
m_maximize
=
false
;
CompositeInstruction
*
m_initial_state
=
nullptr
;
bool
m_shuffleTerms
=
false
;
std
::
shared_ptr
<
xacc
::
IRTransformation
>
m_irTransformation
;
};
}
// namespace algorithm
}
// namespace xacc
quantum/plugins/algorithms/qaoa/qaoa_maxcut.cpp
View file @
17c30f48
...
...
@@ -20,7 +20,7 @@
#include
"xacc_observable.hpp"
#include
"CompositeInstruction.hpp"
#include
"AlgorithmGradientStrategy.hpp"
#include
"IRTransformation.hpp"
#include
<cassert>
#include
<iomanip>
#include
<random>
...
...
@@ -241,6 +241,21 @@ namespace algorithm {
if
(
parameters
.
pointerLikeExists
<
Observable
>
(
"ref-ham"
))
{
m_refHamObs
=
parameters
.
getPointerLike
<
Observable
>
(
"ref-ham"
);
}
m_irTransformation
=
nullptr
;
// This QPU has topology-constraint
if
(
!
m_qpu
->
getConnectivity
().
empty
())
{
if
(
parameters
.
pointerLikeExists
<
xacc
::
IRTransformation
>
(
"placement"
))
{
m_irTransformation
=
xacc
::
as_shared_ptr
(
parameters
.
getPointerLike
<
xacc
::
IRTransformation
>
(
"placement"
));
if
(
m_irTransformation
->
type
()
!=
xacc
::
IRTransformationType
::
Placement
)
{
xacc
::
error
(
m_irTransformation
->
name
()
+
" is not a placement service."
);
}
}
}
}
// Check if a parameter initialization routine has been specified
...
...
@@ -285,6 +300,9 @@ namespace algorithm {
}
else
if
(
m_initial_state
){
m
.
insert
(
"initial-state"
,
m_initial_state
);
}
if
(
m_irTransformation
)
{
m
.
insert
(
"placement"
,
m_irTransformation
);
}
// Initialize QAOA
auto
qaoa
=
xacc
::
getAlgorithm
(
"QAOA"
,
m
);
// Allocate some qubits and execute
...
...
@@ -312,6 +330,10 @@ namespace algorithm {
m
.
insert
(
"initial-state"
,
m_initial_state
);
}
if
(
m_irTransformation
)
{
m
.
insert
(
"placement"
,
m_irTransformation
);
}
// Initialize QAOA
auto
qaoa
=
xacc
::
getAlgorithm
(
"QAOA"
,
m
);
// Allocate some qubits and execute
...
...
quantum/plugins/algorithms/qaoa/qaoa_maxcut.hpp
View file @
17c30f48
...
...
@@ -19,6 +19,7 @@
#include
"AlgorithmGradientStrategy.hpp"
namespace
xacc
{
class
IRTransformation
;
namespace
algorithm
{
class
maxcut_qaoa
:
public
Algorithm
{
...
...
@@ -47,6 +48,7 @@ private:
bool
m_maximize
=
false
;
CompositeInstruction
*
m_initial_state
=
nullptr
;
bool
m_shuffleTerms
=
false
;
std
::
shared_ptr
<
xacc
::
IRTransformation
>
m_irTransformation
;
};
}
// namespace algorithm
}
// namespace xacc
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