Skip to content

Concise StandardGate::<ID> enums in Rust space#14026

Merged
kevinhartman merged 6 commits into
Qiskit:mainfrom
Cryoris:shorts-ftw
Mar 17, 2025
Merged

Concise StandardGate::<ID> enums in Rust space#14026
kevinhartman merged 6 commits into
Qiskit:mainfrom
Cryoris:shorts-ftw

Conversation

@Cryoris
Copy link
Copy Markdown
Collaborator

@Cryoris Cryoris commented Mar 14, 2025

Summary

The Rust-side, internal StandardGate enum variants all repeat the fact that they are a gate. For example, the Hadamard is StandardGate::HGate instead of simply StandardGate::H. Being an enum variant, the fact that it is a gate is evident and always attached to the object. I suspect this is mainly a legacy naming from moving over from Python space (or maybe @mtreinish comes remembers 🙂)?

I'd suggest to shorten the enum variants to just the gate ID. This makes the code more concise and avoid redundant qualifiers. It also enables that gate enums in the C API, introduced in #14006, can be called QkGate_H instead of QkGate_HGate.

@Cryoris Cryoris requested a review from a team as a code owner March 14, 2025 16:32
@qiskit-bot
Copy link
Copy Markdown
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia
  • @levbishop

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 14, 2025

Pull Request Test Coverage Report for Build 13896854086

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 712 of 754 (94.43%) changed or added relevant lines in 52 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 88.102%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/synthesis/multi_controlled/mcmt.rs 1 2 50.0%
crates/accelerate/src/unitary_synthesis.rs 12 13 92.31%
crates/accelerate/src/two_qubit_decompose.rs 29 31 93.55%
crates/accelerate/src/synthesis/evolution/pauli_network.rs 7 10 70.0%
crates/accelerate/src/commutation_checker.rs 0 35 0.0%
Totals Coverage Status
Change from base Build 13853660516: -0.01%
Covered Lines: 72566
Relevant Lines: 82366

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

This seems like a nice improvement to me. Just a few minor comments.

(I didn't look too closely for typos--I assume you used an IDE to do symbolic renaming 😉)

Comment thread crates/accelerate/src/circuit_library/pauli_evolution.rs Outdated
Comment thread crates/accelerate/src/commutation_cancellation.rs Outdated
StandardGate::Z,
StandardGate::T,
StandardGate::S,
StandardGate::Tdg,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a good reason it's Tdg and not TDG, or is that just historical?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There's a good historical reason 😛 See #3695 and the associated issue, we decided the naming norm is: a single uppercase letter per gate type (e.g. T for T-gate, C for controlled, R for a rotation, S for square root...) and dg being just an inverse qualifier remains lowercase. Ofc there are exceptions, like SwapGate (no single letter gate type), or SGate (which I guess would technically be SZ as square root of Z) but that's minimal 🙂

Comment thread crates/accelerate/src/twirling.rs
Copy link
Copy Markdown
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

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

This looks good to me.

I think it's important for consistent naming in our C-API, and @mtreinish could have arbitrarily chosen to do this in the original standard gates PR, so I feel confident to merge this without more consensus. We can always change this again if anyone comes up with a good reason.

@kevinhartman kevinhartman added this pull request to the merge queue Mar 17, 2025
Merged via the queue into Qiskit:main with commit da47ded Mar 17, 2025
@Cryoris Cryoris deleted the shorts-ftw branch March 17, 2025 17:07
raynelfss pushed a commit to raynelfss/qiskit that referenced this pull request Mar 20, 2025
* Rename `StandardGate::([A-Z])*Gate --> StandardGate::$1`

* patch comments

* patch more comments

* `cargo fmt`

* fix rust class ref & full qualifiers in CommCancel
@eliarbel eliarbel added the Changelog: None Do not include in the GitHub Release changelog. label Jun 3, 2025
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants