Commit 025f8e66 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

updating python api slightly



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 49bd9bdd
......@@ -274,7 +274,14 @@ PYBIND11_MODULE(_pyxacc, m) {
"Return a newly allocated register of all qubits on the Accelerator.")
.def("execute",
(void (xacc::Accelerator::*)(std::shared_ptr<AcceleratorBuffer>,
std::shared_ptr<Function>)) &
const std::shared_ptr<Function>)) &
xacc::Accelerator::execute,
"Execute the Function with the given AcceleratorBuffer.")
.def("execute",
(std::vector<std::shared_ptr<AcceleratorBuffer>>(
xacc::Accelerator::*)(
std::shared_ptr<AcceleratorBuffer>,
const std::vector<std::shared_ptr<Function>>)) &
xacc::Accelerator::execute,
"Execute the Function with the given AcceleratorBuffer.");
......@@ -293,6 +300,7 @@ PYBIND11_MODULE(_pyxacc, m) {
"Return the expectation value with respect to the Z operator.")
.def("resetBuffer", &xacc::AcceleratorBuffer::resetBuffer,
"Reset this buffer for use in another computation.")
.def("size", &xacc::AcceleratorBuffer::size, "")
.def("appendMeasurement",
(void (xacc::AcceleratorBuffer::*)(const std::string &)) &
xacc::AcceleratorBuffer::appendMeasurement,
......
......@@ -215,6 +215,30 @@ class qpu(object):
def __call__(self, f):
return WrappedF(f, *self.args, **self.kwargs)
def compute_p10(qubits, buffer, qpu):
functions = []
checkedBitStrings = [] # ['001','010','100'] for 3 bits
probs = []
zeros = '0'*buffer.size()
for i, q in enumerate(qubits):
measure = xacc.gate.create('Measure',[q],[i])
f = xacc.gate.createFunction('meas_'+str(q), [])
f.addInstruction(measure)
functions.append(f)
tmp = list(zeros)
tmp[buffer.size()-1-q] = '1'
checkedBitStrings.append(''.join(tmp))
# Execute
qubits = qpu.createBuffer('tmp',max(qubits)+1)
results = qpu.execute(qubits, functions)
# Populate with probability you saw a 1 but expected 0
for i, b in enumerate(results):
probs.append(b.computeMeasurementProbability(checkedBitStrings[i]))
return probs
def functionToLatex(function):
try:
......
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