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
cfdfed47
Commit
cfdfed47
authored
Jan 15, 2019
by
Zachary Parks
Browse files
Renaming DWKernel -> DWFunction, changing addInstruction() to add parameters automatically
Signed-off-by:
Zachary Parks
<
1zp@ornl.gov
>
parent
67456992
Changes
6
Hide whitespace changes
Inline
Side-by-side
quantum/aqc/CMakeLists.txt
View file @
cfdfed47
...
...
@@ -2,13 +2,13 @@
# Copyright (c) 2017 UT-Battelle, LLC.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# and Eclipse Distribution License v.10 which accompany this distribution.
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# and Eclipse Distribution License v.10 which accompany this distribution.
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# https://eclipse.org/org/documents/edl-v10.php
#
# Contributors:
# Alexander J. McCaskey - initial API and implementation
# Alexander J. McCaskey - initial API and implementation
# *******************************************************************************/
set
(
LIBRARY_NAME xacc-quantum-aqc
)
...
...
@@ -51,7 +51,7 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
manifest.json
)
target_link_libraries
(
${
LIBRARY_NAME
}
PUBLIC xacc
)
target_link_libraries
(
${
LIBRARY_NAME
}
PUBLIC xacc
)
if
(
APPLE
)
set_target_properties
(
xacc-quantum-aqc PROPERTIES INSTALL_RPATH
"@loader_path"
)
...
...
quantum/aqc/ir/DW
Kernel
.hpp
→
quantum/aqc/ir/DW
Function
.hpp
View file @
cfdfed47
...
...
@@ -10,8 +10,8 @@
* Contributors:
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#ifndef QUANTUM_AQC_DW
KERNEL
_HPP_
#define QUANTUM_AQC_DW
KERNEL
_HPP_
#ifndef QUANTUM_AQC_DW
FUNCTION
_HPP_
#define QUANTUM_AQC_DW
FUNCTION
_HPP_
#include
"Function.hpp"
#include
"DWQMI.hpp"
...
...
@@ -30,9 +30,9 @@ using parser_t = exprtk::parser<double>;
namespace
xacc
{
namespace
quantum
{
class
DW
Kernel
:
public
Function
,
class
DW
Function
:
public
Function
,
public
GraphProvider
<
DWVertex
>
,
public
std
::
enable_shared_from_this
<
DW
Kernel
>
{
public
std
::
enable_shared_from_this
<
DW
Function
>
{
protected:
std
::
list
<
InstPtr
>
instructions
;
...
...
@@ -49,14 +49,14 @@ public:
* @param id
* @param name
*/
DW
Kernel
(
std
::
string
kernelName
)
DW
Function
(
std
::
string
kernelName
)
:
_name
(
kernelName
),
parameters
(
std
::
vector
<
InstructionParameter
>
{})
{}
DW
Kernel
(
std
::
string
kernelName
,
std
::
vector
<
InstructionParameter
>
p
)
DW
Function
(
std
::
string
kernelName
,
std
::
vector
<
InstructionParameter
>
p
)
:
_name
(
kernelName
),
parameters
(
p
)
{}
std
::
shared_ptr
<
Function
>
enabledView
()
override
{
auto
newF
=
std
::
make_shared
<
DW
Kernel
>
(
_name
,
parameters
);
auto
newF
=
std
::
make_shared
<
DW
Function
>
(
_name
,
parameters
);
for
(
int
i
=
0
;
i
<
nInstructions
();
i
++
)
{
auto
inst
=
getInstruction
(
i
);
if
(
inst
->
isEnabled
())
{
...
...
@@ -73,7 +73,7 @@ public:
if
(
instructions
.
size
()
>
idx
)
{
i
=
*
std
::
next
(
instructions
.
begin
(),
idx
);
}
else
{
xacc
::
error
(
"DW
Kernel
getInstruction invalid instruction index - "
+
xacc
::
error
(
"DW
Function
getInstruction invalid instruction index - "
+
std
::
to_string
(
idx
)
+
"."
);
}
return
i
;
...
...
@@ -86,11 +86,11 @@ public:
}
void
mapBits
(
std
::
vector
<
int
>
bitMap
)
override
{
xacc
::
error
(
"DW
Kernel
.mapBits not implemented"
);
xacc
::
error
(
"DW
Function
.mapBits not implemented"
);
}
const
int
nRequiredBits
()
const
override
{
XACCLogger
::
instance
()
->
error
(
"DW
Kernel
nRequiredBits() not implemented."
);
XACCLogger
::
instance
()
->
error
(
"DW
Function
nRequiredBits() not implemented."
);
return
0
;
}
/**
...
...
@@ -100,11 +100,21 @@ const int nRequiredBits() const override {
* @param instruction
*/
void
addInstruction
(
InstPtr
instruction
)
override
{
xacc
::
InstructionParameter
param
=
instruction
->
getParameter
(
0
);
bool
dupParam
=
false
;
for
(
auto
p
:
parameters
)
{
if
(
p
.
as
<
std
::
string
>
()
==
param
.
as
<
std
::
string
>
())
{
dupParam
=
true
;
}
}
if
(
!
dupParam
)
{
parameters
.
push_back
(
param
);
}
instructions
.
push_back
(
instruction
);
}
const
int
depth
()
override
{
xacc
::
error
(
"DW
Kernel
graph is undirected, cannot compute depth."
);
xacc
::
error
(
"DW
Function
graph is undirected, cannot compute depth."
);
return
0
;
}
...
...
@@ -174,7 +184,7 @@ const int nRequiredBits() const override {
const
std
::
string
toString
()
override
{
return
toString
(
""
);
}
/**
* Return the number of logical qubits.
*
...
...
@@ -185,14 +195,14 @@ const int nRequiredBits() const override {
}
/**
* Return the number of physical qubits.
*
* Return the number of physical qubits.
*
* @return nPhysical The number of physical qubits.
*/
const
int
nPhysicalBits
()
override
{
return
0
;
}
std
::
vector
<
double
>
getAllBiases
()
{
std
::
vector
<
double
>
biases
;
for
(
auto
i
:
instructions
)
{
...
...
@@ -222,7 +232,7 @@ const int nRequiredBits() const override {
void
setParameter
(
const
int
idx
,
InstructionParameter
&
p
)
override
{
if
(
idx
+
1
>
parameters
.
size
())
{
XACCLogger
::
instance
()
->
error
(
"DW
Kernel
.setParameter: Invalid Parameter requested."
);
"DW
Function
.setParameter: Invalid Parameter requested."
);
}
parameters
[
idx
]
=
p
;
...
...
@@ -242,7 +252,7 @@ const int nRequiredBits() const override {
std
::
shared_ptr
<
Function
>
operator
()(
const
Eigen
::
VectorXd
&
params
)
override
{
if
(
params
.
size
()
!=
nParameters
())
{
xacc
::
error
(
"Invalid DW
Kernel
evaluation: number "
xacc
::
error
(
"Invalid DW
Function
evaluation: number "
"of parameters don't match. "
+
std
::
to_string
(
params
.
size
())
+
", "
+
std
::
to_string
(
nParameters
()));
...
...
@@ -268,7 +278,7 @@ const int nRequiredBits() const override {
return
expr
.
value
();
};
auto
evaluatedFunction
=
std
::
make_shared
<
DW
Kernel
>
(
"evaled_"
+
name
());
auto
evaluatedFunction
=
std
::
make_shared
<
DW
Function
>
(
"evaled_"
+
name
());
for
(
auto
inst
:
getInstructions
())
{
if
(
inst
->
isComposite
())
{
// If a Function, call this method recursively
...
...
@@ -333,10 +343,10 @@ const int nRequiredBits() const override {
*/
void
setOption
(
const
std
::
string
optName
,
InstructionParameter
option
)
override
{
XACCLogger
::
instance
()
->
error
(
"setOption not implemented for DW
Kernel
."
);
return
;
XACCLogger
::
instance
()
->
error
(
"setOption not implemented for DW
Function
."
);
return
;
}
/**
* Get the value of an option with the given name.
*
...
...
@@ -344,8 +354,8 @@ const int nRequiredBits() const override {
* @return option The value of the option.
*/
InstructionParameter
getOption
(
const
std
::
string
optName
)
override
{
XACCLogger
::
instance
()
->
error
(
"getOption not implemented for DW
Kernel
."
);
return
InstructionParameter
(
0
);
XACCLogger
::
instance
()
->
error
(
"getOption not implemented for DW
Function
."
);
return
InstructionParameter
(
0
);
}
/**
...
...
@@ -354,8 +364,8 @@ const int nRequiredBits() const override {
* @return optMap The options map.
*/
std
::
map
<
std
::
string
,
InstructionParameter
>
getOptions
()
override
{
XACCLogger
::
instance
()
->
error
(
"getOptions not implemented for DW
Kernel
."
);
return
std
::
map
<
std
::
string
,
InstructionParameter
>
();
XACCLogger
::
instance
()
->
error
(
"getOptions not implemented for DW
Function
."
);
return
std
::
map
<
std
::
string
,
InstructionParameter
>
();
}
EMPTY_DEFINE_VISITABLE
()
};
...
...
quantum/aqc/ir/DWIRProvider.cpp
View file @
cfdfed47
...
...
@@ -13,7 +13,7 @@ DWIRProvider::createInstruction(const std::string name, std::vector<int> bits,
std
::
shared_ptr
<
Function
>
DWIRProvider
::
createFunction
(
const
std
::
string
name
,
std
::
vector
<
int
>
bits
,
std
::
vector
<
InstructionParameter
>
parameters
)
{
return
std
::
make_shared
<
DW
Kernel
>
(
name
,
parameters
);
return
std
::
make_shared
<
DW
Function
>
(
name
,
parameters
);
}
std
::
shared_ptr
<
IR
>
DWIRProvider
::
createIR
()
{
...
...
quantum/aqc/ir/DWIRProvider.hpp
View file @
cfdfed47
...
...
@@ -4,7 +4,7 @@
#include
"XACC.hpp"
#include
"Identifiable.hpp"
#include
"DWQMI.hpp"
#include
"DW
Kernel
.hpp"
#include
"DW
Function
.hpp"
#include
"IRProvider.hpp"
namespace
xacc
{
...
...
quantum/aqc/ir/tests/CMakeLists.txt
View file @
cfdfed47
add_xacc_test
(
DW
Kernel
)
add_xacc_test
(
DW
Function
)
add_xacc_test
(
DWQMI
)
quantum/aqc/ir/tests/DW
Kernel
Tester.cpp
→
quantum/aqc/ir/tests/DW
Function
Tester.cpp
View file @
cfdfed47
...
...
@@ -11,17 +11,17 @@
* Alexander J. McCaskey - initial API and implementation
*******************************************************************************/
#include
<gtest/gtest.h>
#include
"DW
Kernel
.hpp"
#include
"DW
Function
.hpp"
using
namespace
xacc
::
quantum
;
TEST
(
DW
Kernel
Tester
,
checkDWKernelConstruction
)
{
TEST
(
DW
Function
Tester
,
checkDWKernelConstruction
)
{
auto
qmi
=
std
::
make_shared
<
DWQMI
>
(
0
,
1
,
2.2
);
auto
qmi2
=
std
::
make_shared
<
DWQMI
>
(
0
);
auto
qmi3
=
std
::
make_shared
<
DWQMI
>
(
22
,
3.3
);
DW
Kernel
kernel
(
"foo"
);
DW
Function
kernel
(
"foo"
);
kernel
.
addInstruction
(
qmi
);
kernel
.
addInstruction
(
qmi2
);
kernel
.
addInstruction
(
qmi3
);
...
...
@@ -37,13 +37,13 @@ TEST(DWKernelTester, checkDWKernelConstruction) {
EXPECT_TRUE
(
kernel
.
toString
(
""
)
==
expected
);
}
TEST
(
DW
Kernel
Tester
,
checkGraph
)
{
TEST
(
DW
Function
Tester
,
checkGraph
)
{
auto
qmi
=
std
::
make_shared
<
DWQMI
>
(
0
,
1
,
2.2
);
auto
qmi2
=
std
::
make_shared
<
DWQMI
>
(
0
,
1.2
);
auto
qmi3
=
std
::
make_shared
<
DWQMI
>
(
1
,
3.3
);
DW
Kernel
kernel
(
"foo"
);
DW
Function
kernel
(
"foo"
);
kernel
.
addInstruction
(
qmi
);
kernel
.
addInstruction
(
qmi2
);
kernel
.
addInstruction
(
qmi3
);
...
...
@@ -52,6 +52,42 @@ TEST(DWKernelTester, checkGraph) {
graph
.
write
(
std
::
cout
);
}
TEST
(
DWFunctionTester
,
checkVariableParameterEval
)
{
auto
param1
=
xacc
::
InstructionParameter
(
"param1"
);
auto
param2
=
xacc
::
InstructionParameter
(
"param1"
);
auto
param3
=
xacc
::
InstructionParameter
(
"param2"
);
auto
qmi
=
std
::
make_shared
<
DWQMI
>
(
0
,
1
,
param1
);
auto
qmi2
=
std
::
make_shared
<
DWQMI
>
(
2
,
3
,
param1
);
auto
qmi3
=
std
::
make_shared
<
DWQMI
>
(
3
,
4
,
param3
);
DWFunction
kernel
(
"foo"
);
kernel
.
addInstruction
(
qmi
);
kernel
.
addInstruction
(
qmi2
);
kernel
.
addInstruction
(
qmi3
);
std
::
cout
<<
kernel
.
nParameters
()
<<
std
::
endl
;
for
(
auto
param
:
kernel
.
getParameters
())
{
std
::
cout
<<
boost
::
get
<
std
::
string
>
(
param
)
<<
std
::
endl
;
}
EXPECT_TRUE
(
kernel
.
nParameters
()
==
2
);
EXPECT_TRUE
(
kernel
.
nInstructions
()
==
3
);
EXPECT_TRUE
(
kernel
.
name
()
==
"foo"
);
EXPECT_TRUE
(
kernel
.
getInstruction
(
0
)
==
qmi
);
EXPECT_TRUE
(
kernel
.
getInstruction
(
1
)
==
qmi2
);
EXPECT_TRUE
(
kernel
.
getInstruction
(
2
)
==
qmi3
);
const
std
::
string
expected
=
"0 1 param1;
\n
2 3 param1;
\n
3 4 param2;
\n
"
;
EXPECT_TRUE
(
kernel
.
toString
(
""
)
==
expected
);
Eigen
::
VectorXd
pars
(
2
);
pars
(
0
)
=
3.4
;
pars
(
1
)
=
4.5
;
auto
evaled
=
kernel
(
pars
);
std
::
cout
<<
evaled
->
toString
(
""
)
<<
std
::
endl
;
}
int
main
(
int
argc
,
char
**
argv
)
{
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
...
...
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