1
$\begingroup$

In Qiskit, is there a way to get the individual results from each shot on the IBM quantum device (instead of simply the summary statistics)? The result JSON file provides the count of all the 1024 shots.

$\endgroup$
2
$\begingroup$

You can set memory=True in assemble() or execute(). Then use result.get_memory() to get the per-shot measurement.

For example:

job = execute(circs, memory=True, shots=4)
result = job.result()
print(result.get_counts(0))  # prints {'00': 3, '11': 1}
print(result.get_memory(0))  # prints ['00', '00', '11', '00']  
| improve this answer | |
$\endgroup$
2
$\begingroup$

It seems like this documentation will help you: https://qiskit.org/documentation/stubs/qiskit.result.Result.html#qiskit.result.Result.get_memory

from qiskit import QuantumCircuit, Aer, execute
provider = IBMQ.load_account()

circuit = QuantumCircuit(3)

circuit.h(0)
circuit.h(1)
circuit.cx(0, 1)
circuit.cx(0, 2)
circuit.barrier(range(3))
circuit.h(0)
circuit.h(1)
circuit.barrier(range(3))
circuit.measure_all()
print(circuit)

job = execute(circuit, Aer.get_backend('qasm_simulator'), shots=10, memory=True)

print('result for each shot:', job.result().get_memory() )
     ┌───┐           ░ ┌───┐ ░ ┌─┐      
q_0: ┤ H ├──■────■───░─┤ H ├─░─┤M├──────
     ├───┤┌─┴─┐  │   ░ ├───┤ ░ └╥┘┌─┐   
q_1: ┤ H ├┤ X ├──┼───░─┤ H ├─░──╫─┤M├───
     └───┘└───┘┌─┴─┐ ░ └───┘ ░  ║ └╥┘┌─┐
q_2: ──────────┤ X ├─░───────░──╫──╫─┤M├
               └───┘ ░       ░  ║  ║ └╥┘
c: 3/═══════════════════════════╩══╩══╩═
                                0  1  2 
result for each shot: ['101', '001', '100', '100', '101', '101', '001', '100', '101', '100']
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.