Measurement and Running the Simulator
Like Qiskit's shot-based AerSimulator, Cirq's .run() method executes a circuit with measurement many times and tallies the results, this is what a real device would give you, no direct access to amplitudes.
Running with repetitions
import cirq
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit([
cirq.H(q0),
cirq.CNOT(q0, q1),
cirq.measure(q0, q1, key='result'),
])
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1024)
counts = result.histogram(key='result')
print(counts) # Counter({0: ~512, 3: ~512})
repetitions=1024is Cirq's name for what Qiskit callsshots, run the whole circuit 1024 independent times.result.histogram(key='result')tallies outcomes for the measurement tagged'result', returned as aCounter. Notice the keys are integers, not bitstrings like Qiskit's'00'/'11', Cirq encodes a multi-qubit measurement as one combined integer (0=00,3=11for 2 qubits), where Qiskit keeps it as a string.
Converting to a bitstring, if you want one
for value, count in counts.items():
bitstring = format(value, '02b') # pad to 2 bits
print(bitstring, '->', count)
format(value, '02b') converts an integer to its binary string representation, padded to 2 digits, exactly the inverse of the int(bitstring, 2) conversion from the RNG lesson.
Statistical noise, same as any SDK
result_small = simulator.run(circuit, repetitions=10)
print(result_small.histogram(key='result')) # could easily be lopsided with so few repetitions
Exactly like Qiskit, fewer repetitions means a noisier estimate of the true 50/50 distribution, this isn't an SDK quirk, it's the statistics of sampling any random process a small number of times.
NOTE
counts only ever contains 0 (00) and 3 (11), the same entanglement result from the previous lesson's exact Statevector-equivalent probabilities, now observed empirically through repeated measurement.