Skip to content

Support roundtrip conversion of register-wise classical conditional qasm #7624

@p51lee

Description

@p51lee

Describe the issue

OpenQASM supports register-wise classical conditionals (if (creg == <int>) op;) where the integer is interpreted in binary across creg.
Cirq can import such programs but Circuit.to_qasm() cannot export them back. Maybe Cirq's conditionals are too general to do so; still, it would be great if the QASM subset is recognized and emitted.

Explain how to reproduce the bug or problem

from cirq.contrib.qasm_import import circuit_from_qasm

qasm = """
OPENQASM 2.0;
include "qelib1.inc";

qreg q[1];
creg c[2];

if(c==0) h q[0];
measure q[0] -> c[1];
"""

circuit = circuit_from_qasm(qasm)
circuit.to_qasm()
ValueError: QASM does not support multiple conditions.

Tell us the version of Cirq where this happens

Cirq version: 1.6.1

Metadata

Metadata

Assignees

Labels

area/qasmkind/feature-requestDescribes new functionalitytriage/discussNeeds decision / discussion, bring these up during Cirq Cynque

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions