Skip to content

Add DAG-based variant of BasisTranslator transpiler pass and opaque EquivalenceLibrary type in C Api#16446

Open
bruno-ah-um wants to merge 3 commits into
Qiskit:mainfrom
bruno-ah-um:basis-equivalence
Open

Add DAG-based variant of BasisTranslator transpiler pass and opaque EquivalenceLibrary type in C Api#16446
bruno-ah-um wants to merge 3 commits into
Qiskit:mainfrom
bruno-ah-um:basis-equivalence

Conversation

@bruno-ah-um

Copy link
Copy Markdown
Contributor

Continuation of #15783 and #16261

@eliarbel: please review

Summary

Adds qk_transpiler_pass_basis_translator(), the DAG-based variant of the BasisTranslator standalone transpiler pass in the C API. This function operates directly on a QkDag instead of a QkCircuit, avoiding circuit↔DAG round-trip conversions when chaining multiple passes together.

Introduces QkEquivalenceLibrary, a new opaque C type that wraps Qiskit's standard gate equivalence library. qk_transpiler_pass_basis_translator() accepts the equivalence library as an explicit input parameter. This PR implements only qk_equivalence_library_new_standard() and qk_equivalence_library_free().

The key improvement over the standalone variant (qk_transpiler_pass_standalone_basis_translator) is that callers can construct the equivalence library once and reuse it across repeated pass invocations, avoiding the cost of regenerating it on every call.

Tests

4 new C tests in test/c/test_basis_translator.c:

  • test_dag_in_basis: DAG already in the target basis is left unchanged
  • test_basic_dag_basis_translator: H gate translated to U gate basis
  • test_toffoli_dag_basis_translator: CCX decomposed into {H, T, Tdg, CX} (15 gates total)
  • test_dag_basis_translator_reused_library: Run the pass twice on different DAGs sharing the same equivalence library

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: Claude Sonnet 4.6
  • I used the following tool to generate or modify code: Review code, improve it Sonnet 4.6

@bruno-ah-um bruno-ah-um requested a review from a team as a code owner June 17, 2026 21:53
@bruno-ah-um bruno-ah-um requested a review from ShellyGarion June 17, 2026 21:53
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 17, 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

@garrison garrison added the C API Related to the C API label Jun 17, 2026
@ShellyGarion ShellyGarion added the Changelog: Added Add an "Added" entry in the GitHub Release changelog. label Jun 18, 2026
@eliarbel eliarbel self-assigned this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C API Related to the C API Changelog: Added Add an "Added" entry in the GitHub Release changelog. 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.

5 participants