Open p51lee opened 5 months ago
Thank you for the bug report. From the Cirq sync: to help make a decision regarding whether a fix or an exception is more appropriate, @p51lee do you have concrete use cases in mind where two qubit registers with the same name and different lengths are measured with the same key?
In either case, we should also consider adding documentation about the expected behavior where appropriate.
Thank you for following up. The issue occurs even when using qubits with different names:
qubits_1 = [cirq.NamedQubit("p")]
qubits_2 = [cirq.NamedQubit("q"), cirq.NamedQubit("r")]
circuit = cirq.Circuit(
cirq.measure(qubits_1, key='c'),
cirq.measure(qubits_2, key='c'),
)
print(circuit.to_qasm())
For a use case, I considered circuits with classically conditioned gates. However, since Cirq doesn’t support conditional QASM output, an exception for measurements with different sizes but the same key seems appropriate. This would prevent confusion and incorrect QASM translations.
Description of the issue
When a
Circuit
contains multiple measurements under the same key but with varying sizes, theto_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
Result:
Cirq version 1.3.0