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
2a7f735e
Commit
2a7f735e
authored
Jun 03, 2020
by
Mccaskey, Alex
Browse files
adding u1 rotation gate, defaults to rz in AllGateVisitor
Signed-off-by:
Alex McCaskey
<
mccaskeyaj@ornl.gov
>
parent
14d5bd87
Pipeline
#105218
passed with stage
in 9 minutes and 54 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
quantum/gate/GateQuantumActivator.cpp
View file @
2a7f735e
...
...
@@ -52,6 +52,8 @@ public:
auto
isw
=
std
::
make_shared
<
xacc
::
quantum
::
iSwap
>
();
auto
fsim
=
std
::
make_shared
<
xacc
::
quantum
::
fSim
>
();
auto
u
=
std
::
make_shared
<
xacc
::
quantum
::
U
>
();
auto
u1
=
std
::
make_shared
<
xacc
::
quantum
::
U1
>
();
auto
anneal
=
std
::
make_shared
<
xacc
::
quantum
::
AnnealingInstruction
>
();
auto
s
=
std
::
make_shared
<
xacc
::
quantum
::
S
>
();
...
...
@@ -84,6 +86,8 @@ public:
context
.
RegisterService
<
xacc
::
Instruction
>
(
isw
);
context
.
RegisterService
<
xacc
::
Instruction
>
(
fsim
);
context
.
RegisterService
<
xacc
::
Instruction
>
(
u
);
context
.
RegisterService
<
xacc
::
Instruction
>
(
u1
);
context
.
RegisterService
<
xacc
::
Instruction
>
(
ifstmt
);
context
.
RegisterService
<
xacc
::
Instruction
>
(
anneal
);
...
...
quantum/gate/ir/CommonGates.hpp
View file @
2a7f735e
...
...
@@ -193,6 +193,23 @@ public:
DEFINE_VISITABLE
()
};
class
U1
:
public
Gate
{
public:
U1
()
:
Gate
(
"U1"
,
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
0.0
)})
{}
U1
(
std
::
size_t
qbit
,
InstructionParameter
&&
theta
)
:
Gate
(
"U1"
,
std
::
vector
<
std
::
size_t
>
{
qbit
},
std
::
vector
<
InstructionParameter
>
{
theta
})
{}
U1
(
std
::
vector
<
std
::
size_t
>
qbits
)
:
Gate
(
"U1"
,
qbits
,
std
::
vector
<
InstructionParameter
>
{
InstructionParameter
(
0.0
)})
{}
const
int
nRequiredBits
()
const
override
{
return
1
;
}
DEFINE_CLONE
(
U1
)
DEFINE_VISITABLE
()
};
class
Rx
:
public
Gate
{
public:
Rx
()
...
...
quantum/gate/utils/AllGateVisitor.hpp
View file @
2a7f735e
...
...
@@ -16,6 +16,7 @@
#include
"InstructionIterator.hpp"
#include
"CommonGates.hpp"
#include
<Instruction.hpp>
namespace
xacc
{
namespace
quantum
{
...
...
@@ -44,6 +45,7 @@ class AllGateVisitor : public BaseInstructionVisitor,
public
InstructionVisitor
<
T
>
,
public
InstructionVisitor
<
Tdg
>
,
public
InstructionVisitor
<
U
>
,
public
InstructionVisitor
<
U1
>
,
public
InstructionVisitor
<
IfStmt
>
{
public:
void
visit
(
Hadamard
&
h
)
override
{}
...
...
@@ -51,6 +53,12 @@ public:
void
visit
(
Rz
&
h
)
override
{}
void
visit
(
Ry
&
h
)
override
{}
void
visit
(
Rx
&
h
)
override
{}
void
visit
(
U1
&
u1
)
override
{
InstructionParameter
p
=
u1
.
getParameter
(
0
);
Rz
rz
(
u1
.
bits
());
rz
.
setParameter
(
0
,
p
);
visit
(
rz
);
}
void
visit
(
X
&
h
)
override
{}
void
visit
(
Y
&
h
)
override
{}
void
visit
(
Z
&
h
)
override
{}
...
...
@@ -80,8 +88,8 @@ public:
visit
(
c3
);
}
void
visit
(
fSim
&
fsim
)
override
{}
void
visit
(
iSwap
&
isw
)
override
{}
void
visit
(
fSim
&
fsim
)
override
{}
void
visit
(
iSwap
&
isw
)
override
{}
void
visit
(
CRZ
&
crz
)
override
{}
void
visit
(
CH
&
ch
)
override
{}
void
visit
(
S
&
s
)
override
{}
...
...
quantum/plugins/xasm/tests/XASMCompilerTester.cpp
View file @
2a7f735e
...
...
@@ -22,24 +22,36 @@
#include
"Circuit.hpp"
TEST
(
XASMCompilerTester
,
checkU1
)
{
auto
compiler
=
xacc
::
getCompiler
(
"xasm"
);
auto
IR
=
compiler
->
compile
(
R"(__qpu__ void u1_test(qbit q, double x) {
U1(q[0], x);
})"
);
auto
kernel
=
IR
->
getComposites
()[
0
];
std
::
cout
<<
"HELLO: "
<<
kernel
->
toString
()
<<
"
\n
"
;
std
::
cout
<<
kernel
->
operator
()({
2.2
})
->
toString
()
<<
"
\n
"
;
}
TEST
(
XASMCompilerTester
,
checkISwapAndFSim
)
{
auto
compiler
=
xacc
::
getCompiler
(
"xasm"
);
auto
IR
=
compiler
->
compile
(
R"(__qpu__ void iswap_test(qbit q, double x, double y) {
auto
IR
=
compiler
->
compile
(
R"(__qpu__ void iswap_test(qbit q, double x, double y) {
H(q[0]);
iSwap(q[0], q[1]);
fSim(q[0], q[1], x, y);
CX(q[0], q[1]);
})"
);
auto
kernel
=
IR
->
getComposites
()[
0
];
auto
kernel
=
IR
->
getComposites
()[
0
];
std
::
cout
<<
"HELLO: "
<<
kernel
->
toString
()
<<
"
\n
"
;
std
::
cout
<<
kernel
->
operator
()({
2.2
,
3.3
})
->
toString
()
<<
"
\n
"
;
std
::
cout
<<
kernel
->
operator
()({
2.2
,
3.3
})
->
toString
()
<<
"
\n
"
;
}
TEST
(
XASMCompilerTester
,
checkTranslate
)
{
...
...
xacc/compiler/qalloc.cpp
View file @
2a7f735e
...
...
@@ -10,7 +10,7 @@ template <typename T> struct empty_delete {
qreg
::
qreg
(
const
int
n
)
{
buffer
=
xacc
::
qalloc
(
n
).
get
();
}
qreg
::
qreg
(
const
qreg
&
other
)
:
buffer
(
other
.
buffer
)
{}
qubit
qreg
::
operator
[](
const
std
::
size_t
&
i
)
{
qubit
qreg
::
operator
[](
const
std
::
size_t
i
)
{
return
std
::
make_pair
(
buffer
->
name
(),
i
);
}
AcceleratorBuffer
*
qreg
::
results
()
{
return
buffer
;
}
...
...
xacc/compiler/qalloc.hpp
View file @
2a7f735e
...
...
@@ -29,7 +29,7 @@ public:
qreg
()
=
default
;
qreg
(
const
int
n
);
qreg
(
const
qreg
&
other
);
qubit
operator
[](
const
std
::
size_t
&
i
);
qubit
operator
[](
const
std
::
size_t
i
);
AcceleratorBuffer
*
results
();
std
::
map
<
std
::
string
,
int
>
counts
();
double
exp_val_z
();
...
...
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