`circuit_from_qasm` imports `rc3x` as a 4-qubit `MatrixGate` that `cirq.qasm()` cannot export
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
Research direction
Run the reproducer against cirq.contrib.qasm_import.circuit_from_qasm and inspect how qelib1.inc gates are mapped there, especially the existing handling of multi-qubit gates such as rccx and cswap. Compare that mapping with what cirq.qasm() can export, then decide whether rc3x should be decomposed on import using its qelib1.inc body (h, t, tdg, cx) or handled in the exporter. Done means the OpenQASM 2.0 round trip succeeds without a MatrixGate export error and import/export tests cover rc3x.
Written by the indexing model from the issue text.
Description
Describe the issue
circuit_from_qasm imports rc3x (from Qiskit's qelib1.inc) as a single 4-qubit cirq.MatrixGate. cirq.qasm() cannot write that gate, so an OpenQASM 2.0 round trip of a valid circuit fails. The matrix itself is correct (equal to the rc3x definition in Qiskit's qelib1.inc up to global phase), and the qelib1.inc body of rc3x (h, t, tdg, cx), parsed by Cirq, exports. Of the other multi-qubit qelib1.inc gates, rccx (imported as a 3-qubit MatrixGate), c3x, c3sqrtx, c4x and cswap all export.
Explain how to reproduce the bug or problem
import cirq
from cirq.contrib.qasm_import import circuit_from_qasm
c = circuit_from_qasm('OPENQASM 2.0;\ninclude "qelib1.inc";\nqreg q[4];\nrc3x q[0],q[1],q[2],q[3];\n')
print([type(op.gate).__name__ for op in c.all_operations()])
print(cirq.qasm(c))
['MatrixGate']
Traceback (most recent call last):
...
ValueError: Cannot output operation as QASM: cirq.MatrixGate(np.array([[(1+0j), 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j, 0j], ...
Expected: the importer decomposes rc3x using its definition in Qiskit's qelib1.inc (h, t, tdg, cx), or the exporter decomposes the matrix, so cirq.qasm() succeeds.
Tell us the version of Cirq where this happens
cirq-core 1.7.0 and 1.8.0.dev20261121043546 (ply 3.11, numpy 2.5.5, Python 3.12.15, Linux x86_64).
Found while cross-checking simulators with Quantum Rosetta (https://github.com/SeQuSoS-Project/QRosetta), which runs one OpenQASM 2.0 circuit through several SDKs and compares their results.
I prepared this report with help from an AI assistant and checked the reproducer and results myself.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 1.3k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 48
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from quantumlib/Cirq
-
Potential missed optimization: `drop_diagonal_before_measurement` leaves an identity `PhasedXZGate` that blocks further removalPossibly taken @jangyoujin0917 claimed this 22 days ago. Openarea/gates area/optimization kind/feature-request triage/accepted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
quantumlib/Cirq#8523 · 1 comment ·
Maintainers usually reply within 1 day
-
`defer_measurements` ignores `BitMaskKeyCondition.index` and changes circuit behaviorMay be free again @Tejendra-06 claimed this 54 days ago, and no pull request is open. Opengood for learning help wanted kind/bug-report skill/experienced triage/accepted triage/wont-fix
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
quantumlib/Cirq#8361 · 8 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
kind/feature-request triage/discuss
quantumlib/Cirq#8598 ·
Maintainers usually reply within 1 day
-
area/docstrings area/google kind/bug-report triage/discuss
Difficulty 1/5 1-3 hours Newbie friendliness 91/100
quantumlib/Cirq#8587 ·
Maintainers usually reply within 1 day
-
kind/bug-report triage/discuss
Difficulty 2/5 1-3 hours Newbie friendliness 57/100
quantumlib/Cirq#8580 ·
Maintainers usually reply within 1 day
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day