Skip to content

Add fixed size 2q matrix methods to operations and PackedInstruction#15858

Merged
alexanderivrii merged 1 commit intoQiskit:mainfrom
mtreinish:fixed-size-2q-matrices
Mar 25, 2026
Merged

Add fixed size 2q matrix methods to operations and PackedInstruction#15858
alexanderivrii merged 1 commit intoQiskit:mainfrom
mtreinish:fixed-size-2q-matrices

Conversation

@mtreinish
Copy link
Copy Markdown
Member

Summary

This commit adds new methods to the circuit operation types and the PackedInstruction type to support getting fixed size 2q matrices. 2q matrices are only 16 complex numbers and are commonly used in the transpiler as part of peephole optimization and other optimizations. Using a fixed size array for these will avoid needing heap allocation and also let the compiler potentially do more compile time optimization because the compiler knows exactly how many values are being used for operations. We already exposed these methods for 1q gates for the same reason, this just expands it to 2q gates. We probably won't go beyond this for 3q gates however, because they're 8x8 so too large and also are not as commonly used as 2q gates and matrices.

Details and comments

This commit adds new methods to the circuit operation types and the
PackedInstruction type to support getting fixed size 2q matrices. 2q
matrices are only 16 complex numbers and are commonly used in the
transpiler as part of peephole optimization and other optimizations.
Using a fixed size array for these will avoid needing heap allocation
and also let the compiler potentially do more compile time optimization
because the compiler knows exactly how many values are being used for
operations. We already exposed these methods for 1q gates for the same
reason, this just expands it to 2q gates. We probably won't go beyond
this for 3q gates however, because they're 8x8 so too large and also
are not as commonly used as 2q gates and matrices.
@mtreinish mtreinish added this to the 2.5.0 milestone Mar 23, 2026
@mtreinish mtreinish requested a review from a team as a code owner March 23, 2026 21:58
@mtreinish mtreinish added Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository labels Mar 23, 2026
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Qiskit/terra-core

Copy link
Copy Markdown
Member

@alexanderivrii alexanderivrii left a comment

Choose a reason for hiding this comment

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

LGTM!

@alexanderivrii alexanderivrii added this pull request to the merge queue Mar 25, 2026
Merged via the queue into Qiskit:main with commit 6fafd8e Mar 25, 2026
26 checks passed
@mtreinish mtreinish deleted the fixed-size-2q-matrices branch March 28, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: None Do not include in the GitHub Release changelog. Rust This PR or issue is related to Rust code in the repository

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants