Skip to content

change use of measurements to records in tomography #7421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cirq-core/cirq/experiments/qubit_characterizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,16 +529,16 @@ def single_qubit_state_tomography(
"""
circuit_z = circuit + circuits.Circuit(ops.measure(qubit, key='z'))
Copy link
Contributor

@maffoo maffoo Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think it would be good to check here whether the key 'z' is being used in the given circuit, and if so pick a unique key. One thing that could still fail is if the key is already used in the circuit to measure two or more qubits (e.g. cirq.measure(q0, q1, key='z')) then adding another instance here with a single qubit will cause errors when running the circuit.

results = sampler.run(circuit_z, repetitions=repetitions)
rho_11 = np.mean(results.measurements['z'])
rho_11 = np.mean(results.records['z'][:, -1])
rho_00 = 1.0 - rho_11

circuit_x = circuits.Circuit(circuit, ops.X(qubit) ** 0.5, ops.measure(qubit, key='z'))
results = sampler.run(circuit_x, repetitions=repetitions)
rho_01_im = np.mean(results.measurements['z']) - 0.5
rho_01_im = np.mean(results.records['z'][:, -1]) - 0.5

circuit_y = circuits.Circuit(circuit, ops.Y(qubit) ** -0.5, ops.measure(qubit, key='z'))
results = sampler.run(circuit_y, repetitions=repetitions)
rho_01_re = 0.5 - np.mean(results.measurements['z'])
rho_01_re = 0.5 - np.mean(results.records['z'][:, -1])

rho_01 = rho_01_re + 1j * rho_01_im
rho_10 = np.conj(rho_01)
Expand Down