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
da9dad1e
Commit
da9dad1e
authored
Jun 23, 2017
by
Mccaskey, Alex
Browse files
Adding Y, Rx, Ry gates, updating simple accelerator
parent
346e62f9
Changes
13
Hide whitespace changes
Inline
Side-by-side
impls/simple-simulator/FunctionalGateInstructionVisitor.hpp
View file @
da9dad1e
...
...
@@ -31,43 +31,32 @@
#ifndef FUNCTIONALGATEINSTRUCTIONVISITOR_HPP_
#define FUNCTIONALGATEINSTRUCTIONVISITOR_HPP_
#include
"Hadamard.hpp"
#include
"Measure.hpp"
#include
"CNOT.hpp"
#include
"Rz.hpp"
#include
"Z.hpp"
#include
"X.hpp"
#include
"ConditionalFunction.hpp"
#include
"Z.hpp"
#include
"AllGateVisitor.hpp"
using
namespace
xacc
;
namespace
xacc
{
namespace
quantum
{
class
FunctionalGateInstructionVisitor
:
public
BaseInstructionVisitor
,
public
InstructionVisitor
<
CNOT
>
,
public
InstructionVisitor
<
Hadamard
>
,
public
InstructionVisitor
<
X
>
,
public
InstructionVisitor
<
Z
>
,
public
InstructionVisitor
<
Measure
>
,
public
InstructionVisitor
<
ConditionalFunction
>
,
public
InstructionVisitor
<
Rz
>
{
class
FunctionalGateInstructionVisitor
:
public
AllGateVisitor
{
protected:
std
::
function
<
void
(
Hadamard
&
)
>
hAction
;
std
::
function
<
void
(
CNOT
&
)
>
cnotAction
;
std
::
function
<
void
(
X
&
)
>
xAction
;
std
::
function
<
void
(
Y
&
)
>
yAction
;
std
::
function
<
void
(
Z
&
)
>
zAction
;
std
::
function
<
void
(
Measure
&
)
>
measureAction
;
std
::
function
<
void
(
ConditionalFunction
&
)
>
condAction
;
std
::
function
<
void
(
Rx
&
)
>
rxAction
;
std
::
function
<
void
(
Ry
&
)
>
ryAction
;
std
::
function
<
void
(
Rz
&
)
>
rzAction
;
public:
template
<
typename
HF
,
typename
CNF
,
typename
XF
,
typename
M
F
,
typename
ZF
,
typename
CF
,
typename
RZ
F
>
FunctionalGateInstructionVisitor
(
HF
h
,
CNF
cn
,
XF
x
,
M
F
m
,
ZF
z
,
CF
c
,
RZF
rz
)
:
hAction
(
h
),
cnotAction
(
cn
),
xAction
(
x
),
zAction
(
z
),
measureAction
(
m
),
condAction
(
c
),
rzAction
(
rz
)
{
template
<
typename
HF
,
typename
CNF
,
typename
XF
,
typename
Y
F
,
typename
ZF
,
typename
RXF
,
typename
RYF
,
typename
RZF
,
typename
MF
,
typename
C
F
>
FunctionalGateInstructionVisitor
(
HF
h
,
CNF
cn
,
XF
x
,
Y
F
y
,
ZF
z
,
RXF
rx
,
RYF
ry
,
RZF
rz
,
MF
m
,
CF
c
)
:
hAction
(
h
),
cnotAction
(
cn
),
xAction
(
x
),
yAction
(
y
),
zAction
(
z
),
measureAction
(
m
),
condAction
(
c
),
rxAction
(
rx
),
ryAction
(
ry
),
rzAction
(
rz
)
{
}
void
visit
(
Hadamard
&
h
)
{
...
...
@@ -79,6 +68,11 @@ public:
void
visit
(
X
&
x
)
{
xAction
(
x
);
}
void
visit
(
Y
&
y
)
{
yAction
(
y
);
}
void
visit
(
Z
&
z
)
{
zAction
(
z
);
}
...
...
@@ -89,10 +83,20 @@ public:
condAction
(
c
);
}
void
visit
(
Rx
&
rx
)
{
rxAction
(
rx
);
}
void
visit
(
Ry
&
ry
)
{
ryAction
(
ry
);
}
void
visit
(
Rz
&
rz
)
{
rzAction
(
rz
);
}
void
visit
(
GateFunction
&
f
)
{
return
;
}
virtual
~
FunctionalGateInstructionVisitor
()
{}
};
...
...
impls/simple-simulator/SimpleAccelerator.cpp
View file @
da9dad1e
...
...
@@ -139,6 +139,27 @@ void SimpleAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
qubits
->
applyUnitary
(
localU
);
};
auto
y
=
[
&
]
(
Y
&
yGate
)
{
ComplexTensor
y
(
2
,
2
),
I
(
2
,
2
);
I
.
setValues
(
{
{
1
,
0
},
{
0
,
1
}
});
y
.
setValues
(
{
{
0
,
1
},
{
1
,
0
}
});
auto
actingQubits
=
yGate
.
bits
();
ProductList
productList
;
for
(
int
j
=
0
;
j
<
qubits
->
size
();
j
++
)
{
productList
.
push_back
(
I
);
}
// If this is a one qubit gate, just replace
// the currect I in the list with the gate
productList
.
at
(
actingQubits
[
0
])
=
y
;
// Create a total unitary for this layer of the circuit
ComplexTensor
localU
=
productList
.
at
(
0
);
for
(
int
j
=
1
;
j
<
productList
.
size
();
j
++
)
{
localU
=
localU
.
kronProd
(
productList
.
at
(
j
));
}
qubits
->
applyUnitary
(
localU
);
};
auto
z
=
[
&
]
(
Z
&
zGate
)
{
ComplexTensor
z
(
2
,
2
),
I
(
2
,
2
);
I
.
setValues
(
{
{
1
,
0
},
{
0
,
1
}
});
...
...
@@ -221,13 +242,74 @@ void SimpleAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
std
::
to_string
(
bufResultAsInt
));
};
auto
rx
=
[
&
]
(
Rx
&
rXGate
)
{
const
std
::
complex
<
double
>
i
(
0
,
1
);
double
angle
=
boost
::
get
<
double
>
(
rXGate
.
getParameter
(
0
));
auto
mat11
=
std
::
cos
(
angle
/
2.0
);
auto
mat22
=
mat11
;
auto
mat12
=
-
1.0
*
i
*
std
::
sin
(
angle
/
2.0
);
auto
mat21
=
mat12
;
ComplexTensor
rx
(
2
,
2
),
I
(
2
,
2
);
I
.
setValues
(
{
{
1
,
0
},
{
0
,
1
}});
rx
.
setValues
(
{
{
mat11
,
mat12
},
{
mat21
,
mat22
}});
auto
actingQubits
=
rXGate
.
bits
();
ProductList
productList
;
for
(
int
j
=
0
;
j
<
qubits
->
size
();
j
++
)
{
productList
.
push_back
(
I
);
}
// If this is a one qubit gate, just replace
// the currect I in the list with the gate
productList
.
at
(
actingQubits
[
0
])
=
rx
;
// Create a total unitary for this layer of the circuit
ComplexTensor
localU
=
productList
.
at
(
0
);
for
(
int
j
=
1
;
j
<
productList
.
size
();
j
++
)
{
localU
=
localU
.
kronProd
(
productList
.
at
(
j
));
}
qubits
->
applyUnitary
(
localU
);
};
auto
ry
=
[
&
]
(
Ry
&
rYGate
)
{
const
std
::
complex
<
double
>
i
(
0
,
1
);
double
angle
=
boost
::
get
<
double
>
(
rYGate
.
getParameter
(
0
));
auto
mat11
=
std
::
cos
(
angle
/
2.0
);
auto
mat22
=
mat11
;
auto
mat12
=
-
1.0
*
std
::
sin
(
angle
/
2.0
);
auto
mat21
=
-
1.0
*
mat12
;
ComplexTensor
ry
(
2
,
2
),
I
(
2
,
2
);
I
.
setValues
(
{
{
1
,
0
},
{
0
,
1
}});
ry
.
setValues
(
{
{
mat11
,
mat12
},
{
mat21
,
mat22
}});
auto
actingQubits
=
rYGate
.
bits
();
ProductList
productList
;
for
(
int
j
=
0
;
j
<
qubits
->
size
();
j
++
)
{
productList
.
push_back
(
I
);
}
// If this is a one qubit gate, just replace
// the currect I in the list with the gate
productList
.
at
(
actingQubits
[
0
])
=
ry
;
// Create a total unitary for this layer of the circuit
ComplexTensor
localU
=
productList
.
at
(
0
);
for
(
int
j
=
1
;
j
<
productList
.
size
();
j
++
)
{
localU
=
localU
.
kronProd
(
productList
.
at
(
j
));
}
qubits
->
applyUnitary
(
localU
);
};
auto
rz
=
[
&
]
(
Rz
&
rZGate
)
{
const
std
::
complex
<
double
>
i
(
0
,
1
);
double
angle
=
boost
::
get
<
double
>
(
rZGate
.
getParameter
(
0
));
auto
matElement
=
std
::
exp
(
i
*
angle
);
auto
matElement11
=
std
::
exp
(
-
1.0
*
i
*
angle
);
auto
matElement12
=
std
::
exp
(
i
*
angle
);
ComplexTensor
rz
(
2
,
2
),
I
(
2
,
2
);
I
.
setValues
(
{
{
1
,
0
},
{
0
,
1
}});
rz
.
setValues
(
{
{
1
,
0
},
{
0
,
matElement
}});
rz
.
setValues
(
{
{
matElement11
,
0.0
},
{
0.0
,
matElement12
}});
auto
actingQubits
=
rZGate
.
bits
();
ProductList
productList
;
for
(
int
j
=
0
;
j
<
qubits
->
size
();
j
++
)
{
...
...
@@ -244,10 +326,33 @@ void SimpleAccelerator::execute(std::shared_ptr<AcceleratorBuffer> buffer,
qubits
->
applyUnitary
(
localU
);
};
// auto cphase = [&] (Rz& rZGate) {
// const std::complex<double> i(0, 1);
// double angle = boost::get<double>(rZGate.getParameter(0));
// auto matElement = std::exp(i * angle);
// ComplexTensor rz(2,2), I(2,2);
// I.setValues( { {1, 0}, {0, 1}});
// rz.setValues( { {1, 0}, {0, matElement}});
// auto actingQubits = rZGate.bits();
// ProductList productList;
// for (int j = 0; j < qubits->size(); j++) {
// productList.push_back(I);
// }
// // If this is a one qubit gate, just replace
// // the currect I in the list with the gate
// productList.at(actingQubits[0]) = rz;
// // Create a total unitary for this layer of the circuit
// ComplexTensor localU = productList.at(0);
// for (int j = 1; j < productList.size(); j++) {
// localU = localU.kronProd(productList.at(j));
// }
// qubits->applyUnitary(localU);
// };
// Create a Visitor that will execute our lambdas when
// we encounter one
auto
visitor
=
std
::
make_shared
<
FunctionalGateInstructionVisitor
>
(
hadamard
,
cnot
,
x
,
measure
,
z
,
cond
,
rz
);
cnot
,
x
,
y
,
z
,
rx
,
ry
,
rz
,
measure
,
cond
);
XACCInfo
(
"Execution Simple Accelerator Simulation."
);
...
...
quantum/gate/ir/instructions/Rx.cpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
"Rx.hpp"
namespace
xacc
{
namespace
quantum
{
Rx
::
Rx
(
int
qbit
,
double
theta
)
:
GateInstruction
(
"Rx"
,
std
::
vector
<
int
>
{
qbit
},
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
theta
)
})
{
}
Rx
::
Rx
(
std
::
vector
<
int
>
qbits
)
:
GateInstruction
(
"Rx"
,
qbits
,
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
0.0
)
})
{
}
RegisterGateInstruction
<
Rx
>
RXTEMP
(
"Rx"
);
}
}
quantum/gate/ir/instructions/Rx.hpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
*
**********************************************************************************/
#ifndef QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RX_HPP_
#define QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RX_HPP_
#include
"GateInstruction.hpp"
namespace
xacc
{
namespace
quantum
{
class
Rx
:
public
virtual
GateInstruction
{
public:
Rx
(
std
::
vector
<
int
>
qbits
);
Rx
(
int
qbit
,
double
theta
);
DEFINE_VISITABLE
()
};
}
}
#endif
quantum/gate/ir/instructions/Ry.cpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
"Ry.hpp"
namespace
xacc
{
namespace
quantum
{
Ry
::
Ry
(
int
qbit
,
double
theta
)
:
GateInstruction
(
"Ry"
,
std
::
vector
<
int
>
{
qbit
},
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
theta
)
})
{
}
Ry
::
Ry
(
std
::
vector
<
int
>
qbits
)
:
GateInstruction
(
"Ry"
,
qbits
,
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
0.0
)
})
{
}
RegisterGateInstruction
<
Ry
>
RYTEMP
(
"Ry"
);
}
}
quantum/gate/ir/instructions/Ry.hpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
*
**********************************************************************************/
#ifndef QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RY_HPP_
#define QUANTUM_GATE_GATEQIR_INSTRUCTIONS_RY_HPP_
#include
"GateInstruction.hpp"
namespace
xacc
{
namespace
quantum
{
class
Ry
:
public
virtual
GateInstruction
{
public:
Ry
(
std
::
vector
<
int
>
qbits
);
Ry
(
int
qbit
,
double
theta
);
DEFINE_VISITABLE
()
};
}
}
#endif
quantum/gate/ir/instructions/Y.cpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
"Y.hpp"
namespace
xacc
{
namespace
quantum
{
Y
::
Y
(
std
::
vector
<
int
>
qbit
)
:
GateInstruction
(
"Y"
,
qbit
)
{
}
Y
::
Y
(
int
qbit
)
:
Y
(
std
::
vector
<
int
>
{
qbit
})
{
}
RegisterGateInstruction
<
Y
>
YTEMP
(
"Y"
);
}
}
quantum/gate/ir/instructions/Y.hpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2017, 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
*
**********************************************************************************/
#ifndef QUANTUM_GATE_IR_Y_HPP_
#define QUANTUM_GATE_IR_Y_HPP_
#include
"GateInstruction.hpp"
namespace
xacc
{
namespace
quantum
{
/**
*
*/
class
Y
:
public
virtual
GateInstruction
{
public:
Y
(
std
::
vector
<
int
>
qbit
);
Y
(
int
qbit
);
DEFINE_VISITABLE
()
};
}
}
#endif
quantum/gate/ir/tests/RxTester.cpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* 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
*
**********************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE RxTester
#include
<boost/test/included/unit_test.hpp>
#include
"Rx.hpp"
using
namespace
xacc
::
quantum
;
BOOST_AUTO_TEST_CASE
(
checkCreation
)
{
Rx
rx
(
0
,
3.14
);
BOOST_VERIFY
(
boost
::
get
<
double
>
(
rx
.
getParameter
(
0
))
==
3.14
);
BOOST_VERIFY
(
rx
.
toString
(
"qreg"
)
==
"Rx(3.14) qreg0"
);
BOOST_VERIFY
(
rx
.
bits
().
size
()
==
1
);
BOOST_VERIFY
(
rx
.
bits
()[
0
]
==
0
);
BOOST_VERIFY
(
rx
.
getName
()
==
"Rx"
);
Rx
rx2
(
44
,
1.71234
);
BOOST_VERIFY
(
boost
::
get
<
double
>
(
rx2
.
getParameter
(
0
))
==
1.71234
);
BOOST_VERIFY
(
rx2
.
toString
(
"qreg"
)
==
"Rx(1.71234) qreg44"
);
BOOST_VERIFY
(
rx2
.
bits
().
size
()
==
1
);
BOOST_VERIFY
(
rx2
.
bits
()[
0
]
==
44
);
BOOST_VERIFY
(
rx2
.
getName
()
==
"Rx"
);
}
BOOST_AUTO_TEST_CASE
(
checkAutoRegistration
)
{
xacc
::
InstructionParameter
p
=
3.1415
;
auto
rx
=
GateInstructionRegistry
::
instance
()
->
create
(
"Rx"
,
std
::
vector
<
int
>
{
0
});
rx
->
setParameter
(
0
,
p
);
BOOST_VERIFY
(
rx
->
getName
()
==
"Rx"
);
BOOST_VERIFY
(
boost
::
get
<
double
>
(
rx
->
getParameter
(
0
))
==
3.1415
);
}
quantum/gate/ir/tests/RyTester.cpp
0 → 100644
View file @
da9dad1e
/***********************************************************************************
* Copyright (c) 2016, UT-Battelle
* All rights reserved.