Skip to content

Simulator returns incorrect empty measurement record shapes when repetitions=0 #8317

Description

@Prahalad-ship-it

Describe the issue

When running a quantum circuit using Simulator().run() with repetitions=0, Cirq's sampling fallback path in SimulatesSamples.run_sweep_iter returns a hardcoded empty measurement array shape of (0, 1, 1).

This layout ignores the structural context of the circuit entirely. If a circuit contains multi-qubit measurement operations or repeated instances of the same measurement key, the returned placeholder dimension fails to match the actual layout criteria (repetitions, measurement_instances, measured_qubits), leading to incorrect downstream shape dimensions.

Explain how to reproduce the bug or problem

Execute the following minimal sample script:

import cirq

q0, q1 = cirq.LineQubit.range(2)

circuit = cirq.Circuit(
    cirq.measure(q0, q1, key="m"),
    cirq.measure(q0, q1, key="m"),
)

result = cirq.Simulator().run(circuit, repetitions=0)
print("Returned shape:", result.records["m"].shape)
# Expected: (0, 2, 2)
# Actual: (0, 1, 1)
Click to view failing assertion example log
AssertionError: Pattern dimension mismatch. 
Expected shape layout: (0, 2, 2)
Received placeholder array layout: (0, 1, 1)

Tell us the version of Cirq where this happens

# Paste the output of your version command here (e.g., 1.4.0.dev or similar)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bug-reportSomething doesn't seem to work.triage/discussNeeds decision / discussion, bring these up during Cirq Cynque

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions