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

Add Rust representation for XXMinusYYGate and XXPlusYYGate #12606

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

ElePT
Copy link
Contributor

@ElePT ElePT commented Jun 19, 2024

Summary

This PR adds some of the remaining gates from #12566 XXPlusYY and XXMinusYY. It also adds a multiply_param function that makes the parameter multiplication step a bit more ergonomic (it matches the parameter type and deals with the different logic depending on whether it's a float or a parameter expression). The RZGate definition has been updated to use this function too.

This PR also fixes an oversight in the import path of TGate and TdgGate, which we should add a unit test for.

Details and comments

I don't love having to pass the py token around, so I am open to suggestions to improve the implementation.

…n function (naive approach).

Co-authored by: Julien Gacon [email protected]
Comment on lines -127 to +129
["qiskit.circuit.library.standard_gates.s", "TGate"],
["qiskit.circuit.library.standard_gates.t", "TGate"],
// TdgGate = 21
["qiskit.circuit.library.standard_gates.s", "TdgGate"],
["qiskit.circuit.library.standard_gates.t", "TdgGate"],
Copy link
Member

Choose a reason for hiding this comment

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

I'm slightly concerned that this didn't cause us test failures when the first PR merged; we're presumably missing coverage, because that import would have failed.

(Also, there's really no need for us to be importing all these from the specific modules; we could just import them from qiskit.circuit.library or at most qiskit.circuit.library.standard_gates.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how we could test these. From Rust space, as we'd need the Python GIL, and from Python space, we always have a Python object to refer to, right?

What I guess we could do is expose get_std_gate_class to Python and test it there, but it doesn't sound like the greatest idea.

Copy link
Member

Choose a reason for hiding this comment

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

The easiest test we should write for this is to call the QuantumCircuit gate method for each gate which will only create a rust representation then just do QuantumCircuit.data[0].operation and compare it against the expected one. That should give us full path coverage of this conversion.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, looking through the code this never gets used because we're always adding a tgate by class to a circuit before needing to instantiate a python object from rust so we have the mapping already. I expect via the equivalence library on import. This is only used if we're in a call path where we end up with a StandardGate::TGate created in rust before it's ever added to a circuit via the python object to add a fallback import path. I wrote up the test case as I suggested above locally and it passes without this change.

Copy link
Member

Choose a reason for hiding this comment

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

I pushed up a test for this here: #12623

* Use multiply_param in RZGate

* Fix signs and indices
@ElePT ElePT added Rust This PR or issue is related to Rust code in the repository performance Changelog: None Do not include in changelog labels Jun 19, 2024
@ElePT ElePT added this to the 1.2.0 milestone Jun 19, 2024
@coveralls
Copy link

coveralls commented Jun 19, 2024

Pull Request Test Coverage Report for Build 9585037750

Details

  • 151 of 160 (94.38%) changed or added relevant lines in 4 files are covered.
  • 15 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 89.785%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/circuit/src/operations.rs 107 116 92.24%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 92.37%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 9578841868: 0.02%
Covered Lines: 63705
Relevant Lines: 70953

💛 - Coveralls

@ElePT ElePT marked this pull request as ready for review June 20, 2024 07:24
@ElePT ElePT requested a review from a team as a code owner June 20, 2024 07:24
@qiskit-bot
Copy link
Collaborator

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

  • @Cryoris
  • @Qiskit/terra-core
  • @ajavadia
  • @kevinhartman
  • @mtreinish

Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

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

LGTM! The only question I have is whether changing the previous theta.clone_ref(py) to now theta.clone() has a performance difference. But we can still update this later if it is, and merge this to unblock other PRs that use parameters in gates 🙂

@Cryoris Cryoris added this pull request to the merge queue Jun 21, 2024
Merged via the queue into Qiskit:main with commit 87aa89c Jun 21, 2024
15 checks passed
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
…t#12606)

* Add XXMinusYYGate and XXPlusYYGate, implement parameter multiplication function (naive approach).

Co-authored by: Julien Gacon [email protected]

* * Format code

* Use multiply_param in RZGate

* Fix signs and indices
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 changelog performance Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants