Skip to content

Fix QASM3 exporter unitary gate naming#16062

Open
TSS99 wants to merge 1 commit intoQiskit:mainfrom
TSS99:codex/qasm3-avoid-unitary-name
Open

Fix QASM3 exporter unitary gate naming#16062
TSS99 wants to merge 1 commit intoQiskit:mainfrom
TSS99:codex/qasm3-avoid-unitary-name

Conversation

@TSS99
Copy link
Copy Markdown
Contributor

@TSS99 TSS99 commented Apr 18, 2026

Summary

Rename exported OpenQASM 3 gate definitions that would otherwise use the bare symbol unitary.

Fixes #14310.

Root cause

The OpenQASM 3 exporter preserved the UnitaryGate name when emitting a gate definition, so it produced output such as:

 gate unitary _gate_q_0 {
   ...
 }
 unitary q[0];

Downstream consumers such as Qiskit Aer treat unitary as a special instruction name rather than a user-defined gate symbol, so the exported program could be misclassified and fail when reloaded.

Fix

  • rename declared gate symbols derived from unitary to unitary_gate through the exporter symbol table
  • keep the change scoped to exported gate declarations and call sites only
  • add a regression test for nested synthesized unitary definitions
  • add a release note for the user-visible QASM output change

Tests

  • PYTHONPATH=$PWD python -m unittest -v test.python.qasm3.test_export
  • PYTHONPATH=$PWD python -m black --check qiskit/qasm3/exporter.py test/python/qasm3/test_export.py
  • PYTHONPATH=$PWD python -m ruff check qiskit/qasm3/exporter.py test/python/qasm3/test_export.py

Notes or limitations

  • reno lint could not be completed in this checkout because the local repository hits a Dulwich missing-object error while scanning note history (KeyError: b'09bcf1597b54b73fef724dc3f02a6fae8edbdf1f').

AI/LLM disclosure

  • I didn't use LLM tooling, or only used it privately.
  • I used the following tool to help write this PR description: OpenAI Codex (GPT-5)
  • I used the following tool to generate or modify code: OpenAI Codex (GPT-5)

@TSS99 TSS99 requested a review from a team as a code owner April 18, 2026 06:54
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Apr 18, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

Copy link
Copy Markdown
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a correct fix, because the root fault is not in the exporter but in the importer. The data model of Qiskit is not violated until an Instruction called unitary that is not a UnitaryGate is constructed, and Qiskit is not the only source of OpenQASM files, so the fix cannot be to write out an OpenQASM file differently.

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

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Qiskit QASM 3.0 dump function generates a gate named "unitary" causing runtime crash when reloading the code

3 participants