The aim of this notebook is to analyze in more detail the output of the submission of a job.
We will be focussing on the following simple circuit:
from qat.lang.AQASM import Program, H, CNOT, Y
prog = Program()
reg = prog.qalloc(2) # quantum register
creg = prog.calloc(3) # classical register
prog.apply(H, reg[0])
prog.apply(CNOT, reg)
prog.measure(reg[1], creg[1])
prog.cc_apply(creg[1], Y, reg[0])
prog.measure(reg[0], creg[0])
prog.logic(creg[2], ~ creg[1])
prog.reset(reg[1])
circ = prog.to_circ()
Let us examine the evolution of the quantum state step-by-step:
In summary, we expect two possible intermediate measurement results:
We can now check that this is indeed what happens when executing this circuit on the QLM:
from qat.qpus import PyLinalg
qpu = PyLinalg()
# we execute the circuit 3 times
for _ in range(3):
res = qpu.submit(circ.to_job(nbshots=1, aggregate_data=False))
print("====================")
print(" ---- 3 intermediate measurements (including reset)---------------")
#print(res)
for meas_res in res.raw_data[0].intermediate_measurements:
print(" measure = %s (position = %s)"%(meas_res.cbits, meas_res.gate_pos))
print(" ---- final state of the quantum and classical register ------")
print(" quantum register = %s (bit order q0 q1)"% res.raw_data[0].state)
We can see that res.raw_data
is a list containing a objects (of the type Sample
) containing several pieces of information:
its field intermediate_measurements
contains a list of measurement results (type MeasurementResult
), which in particular contain the value of the measured bit(s) (field cbits
) and the index of the measurement/reset gate in the circuit (field gate_pos
)
its field state
contains the final quantum state after a measurement, in the computational basis, of all the qubits at the end of the circuit (one can also decide to measure only a subset of qubits at the end of the circuit, by specifying the parameter qubits
in the call to to_job
)