Commit c6d64045 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

expose getNativeCode to python



Signed-off-by: Nguyen, Thien Minh's avatarThien Nguyen <nguyentm@ornl.gov>
parent 7b7222a2
import xacc
xacc.qasm('''
.compiler xasm
.circuit iterative_qpe
.qbit q
H(q[0]);
X(q[1]);
// Prepare the state:
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
H(q[0]);
// Measure and reset
Measure(q[0], c[0]);
Reset(q[0]);
H(q[0]);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
// Conditional rotation
if(c[0]) {
Rz(q[0], -pi/2);
}
H(q[0]);
Measure(q[0], c[1]);
Reset(q[0]);
H(q[0]);
CPhase(q[0], q[1], -5*pi/8);
CPhase(q[0], q[1], -5*pi/8);
if(c[0]) {
Rz(q[0], -pi/4);
}
if(c[1]) {
Rz(q[0], -pi/2);
}
H(q[0]);
Measure(q[0], c[2]);
Reset(q[0]);
H(q[0]);
CPhase(q[0], q[1], -5*pi/8);
if(c[0]) {
Rz(q[0], -pi/8);
}
if(c[1]) {
Rz(q[0], -pi/4);
}
if(c[2]) {
Rz(q[0], -pi/2);
}
H(q[0]);
Measure(q[0], c[3]);
''')
f = xacc.getCompiled('iterative_qpe')
qpu = xacc.getAccelerator('ibm:ibmq_manhattan')
print('HOWDY:\n', qpu.getNativeCode(f))
\ No newline at end of file
...@@ -112,6 +112,12 @@ void bind_accelerator(py::module &m) { ...@@ -112,6 +112,12 @@ void bind_accelerator(py::module &m) {
xacc::Accelerator::updateConfiguration, xacc::Accelerator::updateConfiguration,
"") "")
.def("getConnectivity", &xacc::Accelerator::getConnectivity, "") .def("getConnectivity", &xacc::Accelerator::getConnectivity, "")
.def(
"getNativeCode",
[](xacc::Accelerator &qpu, std::shared_ptr<CompositeInstruction> f) {
return qpu.getNativeCode(f);
},
"")
.def("configurationKeys", &xacc::Accelerator::configurationKeys, "") .def("configurationKeys", &xacc::Accelerator::configurationKeys, "")
.def("contributeInstructions", &xacc::Accelerator::contributeInstructions, .def("contributeInstructions", &xacc::Accelerator::contributeInstructions,
""); "");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment