Quantum Computing Asked on April 21, 2021
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.
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']
Correct answer by jyu00 on April 21, 2021
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']
Answered by KAJ226 on April 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP