Skip to content

Incorrect Classical Register Size in to_qasm with Inhomogeneous Measurements #6508

Closed
@p51lee

Description

@p51lee

Description of the issue

When a Circuit contains multiple measurements under the same key but with varying sizes, the to_qasm method improperly assigns the classical register size, resulting in a smaller than required register.
A potential solution includes �fixing this behavior directly or, throwing an exception for circuits with measurements of differing sizes being translated to OpenQASM, to prevent incorrect translations.

How to reproduce the issue

import cirq

qubits = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
    cirq.measure(qubits[0], key='c'),
    cirq.measure(qubits, key='c'),
)
# No issue
# circuit = cirq.Circuit(
#    cirq.measure(qubits, key='c'),
#    cirq.measure(qubits[0], key='c'),
# )

print(circuit.to_qasm())

Result:

// Generated from Cirq v1.3.0

OPENQASM 2.0;
include "qelib1.inc";


// Qubits: [q(0), q(1)]
qreg q[2];
creg m_c[1];  // Incorrectly suggests a single-bit register, expected size is 2


measure q[0] -> m_c[0];

// Gate: cirq.MeasurementGate(2, cirq.MeasurementKey(name='c'), ())
measure q[0] -> m_c[0];
measure q[1] -> m_c[1]; 

Cirq version
1.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/interoparea/qasmkind/bug-reportSomething doesn't seem to work.triage/acceptedA consensus emerged that this bug report, feature request, or other action should be worked ontriage/needs-more-evidence[Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions