Skip to content

Add TranspileLayout to the C API #14780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Jul 22, 2025

Summary

This commit adds the TranspileLayout struct added in #14778 to the C
API. It is a straightforward addition to the API as the interface is
fairly simple. Given a pointer to a TranspileLayout the methods return
the arrays for the various views of the layout or the number of qubits
for the input and output circuits.

One small change was made to the PhysicalQubit and VirtualQubit type
definitions to use #[repr(transparent)] which in practice shouldn't
change anything, but it makes it explicit that these can be used
interchangeably with a u32. This simplifies how we can return arrays of
either type to C because it is safe to cast them as pointers to u32s.

Note that nothing in the C API is capable of generating a transpile
layout currently. The intent is for it to be part of the full
transpile() function return (see #14778). In the meantime this is
tested solely through rust tests and there aren't any tests written
in C yet. A potential follow up commit can be made to update the
standalone vf2 layout pass function to use a transpile layout inside
it's result type which would be more ergonomic than it's current
layout object in the result. But to keep this PR targeted this doesn't
update that interface and only exposes the struct to the C API.

Details and comments

This is based on #14778 and this PR will need to be rebased after #14778 merges. In the meantime you can view the content of this PR with the HEAD commit: 8efe505

This commit adds a Rust TranspileLayout object which is analgous to the
Python space object. It is a self contained struct that is only for
Rust and will be used by the C API for the C transpiler so that users
will be able to reason about the permutations caused by the transpiler.
This will also be used by Qiskit#14106 to apply a transpilation layout to the
SparseObservable in C. This commit only adds the rust struct and it's
associated tests, a subsequent PR will add the C API on top. This won't
be used until we have a full path transpiler in C though (see Qiskit#14760).
@mtreinish mtreinish added this to the 2.2.0 milestone Jul 22, 2025
@mtreinish mtreinish requested a review from a team as a code owner July 22, 2025 14:13
@mtreinish mtreinish added on hold Can not fix yet Changelog: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler C API Related to the C API labels Jul 22, 2025
@qiskit-bot
Copy link
Collaborator

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

@coveralls
Copy link

coveralls commented Jul 22, 2025

Pull Request Test Coverage Report for Build 16447886981

Details

  • 491 of 491 (100.0%) changed or added relevant lines in 2 files are covered.
  • 20 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.05%) to 87.83%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/parse.rs 6 97.56%
crates/circuit/src/symbol_expr.rs 7 73.69%
crates/qasm2/src/lex.rs 7 91.49%
Totals Coverage Status
Change from base Build 16420779601: 0.05%
Covered Lines: 81966
Relevant Lines: 93323

💛 - Coveralls

@mtreinish mtreinish force-pushed the add-c-api-transpile-layout branch 2 times, most recently from 8efe505 to 2d9a893 Compare July 22, 2025 14:53
This commit adds the TranspileLayout struct added in Qiskit#14778 to the C
API. It is a straightforward addition to the API as the interface is
fairly simple. Given a pointer to a TranspileLayout the methods return
the arrays for the various views of the layout or the number of qubits
for the input and output circuits.

One small change was made to the PhysicalQubit and VirtualQubit type
definitions to use #[repr(transparent)] which in practice shouldn't
change anything, but it makes it explicit that these can be used
interchangeably with a u32. This simplifies how we can return arrays of
either type to C because it is safe to cast them as pointers to u32s.

Note that nothing in the C API is capable of generating a transpile
layout currently. The intent is for it to be part of the full
transpile() function return (see Qiskit#14778). In the meantime this is
tested solely through rust tests and there aren't any tests written
in C yet. A potential follow up commit can be made to update the
standalone vf2 layout pass function to use a transpile layout inside
it's result type which would be more ergonomic than it's current
layout object in the result. But to keep this PR targeted this doesn't
update that interface and only exposes the struct to the C API.
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: New Feature Include in the "Added" section of the changelog mod: transpiler Issues and PRs related to Transpiler on hold Can not fix yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants