Skip to content
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

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

Merged
merged 6 commits into from
Mar 17, 2025

Conversation

Cryoris
Copy link
Contributor

@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
Collaborator

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

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

@coveralls
Copy link

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
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 😉)

StandardGate::Z,
StandardGate::T,
StandardGate::S,
StandardGate::Tdg,
Copy link
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
Contributor 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 🙂

Copy link
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
20 checks passed
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants