Measurement¶
Overview¶
Measurement records qubit values into classical bits so you can retrieve results after execution.
This page describes how to add measurement operations to a circuit and how to read shot results and aggregated counts from the job result.
For the end-to-end flow (provider → backend → circuit → run), see Circuits.
For execution options such as shots, see Run Settings.
Add measurement to a circuit¶
Measure a single qubit¶
Use qc.measure(qubit, classical_bit) to project a qubit into a classical bit.
from QuantumRingsLib import QuantumCircuit
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.measure(0, 0)
Measure all qubits¶
Use qc.measure_all() to add in-place measurement to all qubits.
Projections are made to the corresponding classical bits. Classical bits are added
if required.
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
Measure active qubits¶
Use qc.measure_active() to add in-place measurement to all non-idle qubits.
Projections are made to the corresponding classical bits. Classical bits are added
if required.
Run and read results¶
After calling backend.run(...), use job.result() to retrieve a Result object.
Two common ways to read measurement output are:
result.get_memory()— returns measurement data for all shots as a list of strings.result.get_counts()— returns a dictionary of outcomes, where the value is the percentage of occurrence for each measurement result.
from QuantumRingsLib import QuantumCircuit, QuantumRingsProvider
provider = QuantumRingsProvider()
backend = provider.get_backend("scarlet_quantum_rings")
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
job = backend.run(qc, shots=100)
result = job.result()
memory = result.get_memory()
counts = result.get_counts()
print(memory[:10])
print(counts)
See also¶
Return to Quantum Rings SDK Documentation.