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
3283a560
Commit
3283a560
authored
Jun 28, 2017
by
Mccaskey, Alex
Browse files
Fixing bug in function evaluate variable params.
parent
f4038d43
Changes
6
Hide whitespace changes
Inline
Side-by-side
impls/rigetti/QuilVisitor.hpp
View file @
3283a560
...
...
@@ -126,20 +126,23 @@ public:
}
void
visit
(
Rx
&
rx
)
{
auto
angleStr
=
boost
::
lexical_cast
<
std
::
string
>
(
rx
.
getParameter
(
0
));
quilStr
+=
"RX("
+
std
::
to_string
(
boost
::
get
<
double
>
(
rx
.
getParameter
(
0
)))
+
angleStr
+
") "
+
std
::
to_string
(
rx
.
bits
()[
0
])
+
"
\n
"
;
}
void
visit
(
Ry
&
ry
)
{
auto
angleStr
=
boost
::
lexical_cast
<
std
::
string
>
(
ry
.
getParameter
(
0
));
quilStr
+=
"RY("
+
std
::
to_string
(
boost
::
get
<
double
>
(
ry
.
getParameter
(
0
)))
+
angleStr
+
") "
+
std
::
to_string
(
ry
.
bits
()[
0
])
+
"
\n
"
;
}
void
visit
(
Rz
&
rz
)
{
auto
angleStr
=
boost
::
lexical_cast
<
std
::
string
>
(
rz
.
getParameter
(
0
));
quilStr
+=
"RZ("
+
std
::
to_string
(
boost
::
get
<
double
>
(
rz
.
getParameter
(
0
)))
+
angleStr
+
") "
+
std
::
to_string
(
rz
.
bits
()[
0
])
+
"
\n
"
;
}
...
...
impls/rigetti/RigettiAccelerator.cpp
View file @
3283a560
...
...
@@ -36,6 +36,7 @@
#include
<codecvt>
#include
<memory>
#include
<boost/python.hpp>
#include
"GateQIR.hpp"
#define RAPIDJSON_HAS_STDSTRING 1
...
...
impls/rigetti/examples/h2qve_scaffold_rigetti.cpp
View file @
3283a560
...
...
@@ -49,12 +49,12 @@
// " creg[2] = MeasZ(qreg[2]);\n"
// "}\n");
const
std
::
string
src
(
"__qpu__ teleport (qbit qreg,
double
phi)
{
\
n
"
"
cbit
creg
[
3
];
\
n
"
const
std
::
string
src
(
"__qpu__ teleport (qbit qreg,
float
phi)
{
\
n
"
"
cbit
creg
[
2
];
\
n
"
"
H
(
qreg
[
0
]);
\
n
"
"
X
(
qreg
[
1
]);
\
n
"
"
CNOT
(
qreg
[
0
],
qreg
[
1
]);
\
n
"
"
//
Rz(qreg[1],phi);\n" // general rotation
"
CNOT
(
qreg
[
0
],
qreg
[
1
]);
\
n
"
"
Rz
(
qreg
[
1
],
phi
);
\
n
" // general rotation
"
creg
[
0
]
=
MeasZ
(
qreg
[
0
]);
\
n
"
"
creg
[
1
]
=
MeasZ
(
qreg
[
1
]);
\
n
"
"
}
\
n
");
...
...
@@ -78,7 +78,7 @@ int main (int argc, char** argv) {
// Request the quantum kernel representing
// the above source code
auto
teleport
=
program
.
getKernel
<
double
>
(
"teleport"
);
auto teleport = program.getKernel<
float
>("
teleport
");
float phi = 0.;
teleport(qubitReg, 0.);
...
...
impls/scaffold/ScaffoldASTConsumer.hpp
View file @
3283a560
...
...
@@ -263,7 +263,6 @@ public:
llvm
::
raw_string_ostream
lhss
(
lhsstr
);
lhs
->
printPretty
(
lhss
,
nullptr
,
policy
);
auto
lhsString
=
lhss
.
str
();
// std::cout << "HELLO BINOP LHS: " << lhsString << "\n";
boost
::
replace_all
(
lhsString
,
cbitVarName
,
""
);
boost
::
replace_all
(
lhsString
,
"["
,
""
);
...
...
@@ -281,14 +280,12 @@ public:
xacc
::
quantum
::
GateInstructionRegistry
::
instance
()
->
create
(
"Measure"
,
std
::
vector
<
int
>
{
std
::
stoi
(
rhsString
)
});
// , std::stoi(lhsString));
xacc
::
InstructionParameter
classicalIdx
(
std
::
stoi
(
lhsString
));
inst
->
setParameter
(
0
,
classicalIdx
);
cbitRegToMeasuredQubit
.
insert
(
std
::
make_pair
(
lhss
.
str
(),
std
::
stoi
(
rhsString
)));
// std::cout << "ADDING A MEASUREMENT GATE " << lhss.str() << "\n";
function
->
addInstruction
(
inst
);
}
...
...
quantum/gate/ir/GateFunction.hpp
View file @
3283a560
...
...
@@ -179,7 +179,7 @@ public:
runtimeParameters
);
}
else
{
if
(
inst
->
isParameterized
())
{
if
(
inst
->
isParameterized
()
&&
inst
->
getName
()
!=
"Measure"
)
{
for
(
int
i
=
0
;
i
<
inst
->
nParameters
();
i
++
)
{
auto
param
=
inst
->
getParameter
(
i
);
...
...
@@ -192,7 +192,6 @@ public:
auto
it
=
std
::
find
(
parameters
.
begin
(),
parameters
.
end
(),
param
);
if
(
it
==
parameters
.
end
())
{
std
::
cout
<<
"COULD NOT FIND VARIABLE
\n
"
;
XACCError
(
"Variable "
+
variable
+
" not found in Function parameters."
);
}
else
{
auto
index
=
std
::
distance
(
parameters
.
begin
(),
...
...
xacc/accelerator/AcceleratorBuffer.hpp
View file @
3283a560
...
...
@@ -33,13 +33,16 @@
#include
<boost/dynamic_bitset.hpp>
#include
<string>
#include
<sstream>
#include
<iostream>
#include
"Utils.hpp"
namespace
xacc
{
// Our Accelerator Bits can be a 1, 0, or unknown
enum
class
AcceleratorBitState
{
ZERO
,
ONE
,
UNKNOWN
};
enum
class
AcceleratorBitState
{
ZERO
,
ONE
,
UNKNOWN
};
/**
* The AcceleratorBit wraps an AcceleratorBitSate
...
...
@@ -54,13 +57,17 @@ public:
/**
* The constructor, all bits are initialized to unknown state
*/
AcceleratorBit
()
:
state
(
AcceleratorBitState
::
UNKNOWN
){}
AcceleratorBit
()
:
state
(
AcceleratorBitState
::
UNKNOWN
)
{
}
/**
* Update the Bit state to a one or zero
*/
void
update
(
int
zeroOrOne
)
{
state
=
(
zeroOrOne
==
0
?
AcceleratorBitState
::
ZERO
:
AcceleratorBitState
::
ONE
);
state
=
(
zeroOrOne
==
0
?
AcceleratorBitState
::
ZERO
:
AcceleratorBitState
::
ONE
);
}
/**
...
...
@@ -110,43 +117,44 @@ public:
bits
[
idx
].
update
(
zeroOrOne
);
}
void
appendMeasurement
(
const
boost
::
dynamic_bitset
<>&
measurement
){
void
appendMeasurement
(
const
boost
::
dynamic_bitset
<>&
measurement
)
{
measurements
.
push_back
(
measurement
);
}
}
double
getAverage
()
const
{
double
getAverage
()
const
{
//std::assert(measurements.size()>0);
std
::
stringstream
ss
;
double
aver
=
0.
;
long
n_measurements
=
measurements
.
size
();
unsigned
long
tmp
;
bool
odd
;
for
(
unsigned
long
bucket
=
0
;
bucket
<
(
1UL
<<
measurements
[
0
].
size
());
++
bucket
){
for
(
unsigned
long
bucket
=
0
;
bucket
<
(
1UL
<<
measurements
[
0
].
size
());
++
bucket
)
{
long
count
=
0
;
// use bucket to "collect"(i.e. count)
for
(
const
auto
outcome
:
measurements
){
if
(
outcome
.
to_ulong
()
==
bucket
)
{
for
(
const
auto
outcome
:
measurements
)
{
if
(
outcome
.
to_ulong
()
==
bucket
)
{
count
++
;
}
}
double
p
=
double
(
count
)
/
n_measurements
;
ss
<<
"p= "
<<
p
<<
std
::
endl
;
double
p
=
double
(
count
)
/
n_measurements
;
ss
<<
"p= "
<<
p
<<
std
::
endl
;
tmp
=
bucket
;
odd
=
false
;
while
(
tmp
){
odd
=
!
odd
;
tmp
=
tmp
&
(
tmp
-
1
);
while
(
tmp
)
{
odd
=
!
odd
;
tmp
=
tmp
&
(
tmp
-
1
);
}
if
(
!
odd
){
if
(
!
odd
)
{
aver
+=
p
;
}
else
{
}
else
{
aver
-=
p
;
}
}
}
XACCInfo
(
ss
.
str
());
return
aver
;
}
}
AcceleratorBitState
getAcceleratorBitState
(
const
int
idx
)
{
return
bits
[
idx
].
getState
();
}
...
...
@@ -156,12 +164,13 @@ public:
virtual
void
print
(
std
::
ostream
&
stream
)
{
}
virtual
~
AcceleratorBuffer
()
{}
virtual
~
AcceleratorBuffer
()
{
}
protected:
std
::
vector
<
boost
::
dynamic_bitset
<>>
measurements
;
std
::
vector
<
boost
::
dynamic_bitset
<>>
measurements
;
std
::
string
bufferId
;
std
::
vector
<
AcceleratorBit
>
bits
;
...
...
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