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

Oxidize TwoQubitDecomposeUpToDiagonal #12563

Merged
merged 9 commits into from
Jul 24, 2024

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Jun 13, 2024

Summary

This commit ports the TwoQubitDecomposeUpToDiagonal class from Python to rust. This internal private class is used internally by the quantum shannon decomposition code, and while not performance critical was simple to port. One difference is while the original Python implementation was a class, it acted more like a function in practice. So the new rust version is exposed as a function.

Details and comments

TODO:

This commit ports the TwoQubitDecomposeUpToDiagonal class from Python to
rust. This internal private class is used internally by the quantum
shannon decomposition code, and while not performance critical was
simple to port. One difference is while the original Python
implementation was a class, it acted more like a function in practice.
So the new rust version is exposed as a function.

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Sebastian Brandhofer <148463728+sbrandhsn@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Eli Arbel <46826214+eliarbel@users.noreply.github.com>
Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
Co-authored-by: Henry Zou <87874865+henryzou50@users.noreply.github.com>
Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
@mtreinish mtreinish added Changelog: None Do not include in changelog synthesis Rust This PR or issue is related to Rust code in the repository labels Jun 13, 2024
@coveralls
Copy link

coveralls commented Jun 13, 2024

Pull Request Test Coverage Report for Build 9496622203

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

  • 213 of 224 (95.09%) changed or added relevant lines in 2 files are covered.
  • 18 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 89.593%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 207 218 94.95%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 92.62%
crates/qasm2/src/parse.rs 12 97.15%
Totals Coverage Status
Change from base Build 9483656494: -0.01%
Covered Lines: 62661
Relevant Lines: 69940

💛 - Coveralls

Since Qiskit#12459 recently merged we now have a mechanism to build a circuit
from rust. This commit updates the synthesis function to build the
circuit directly in rust instead of returning a circuit sequence and
building the circuit from Python. This should speed up the construction
substantially.
@mtreinish mtreinish marked this pull request as ready for review June 14, 2024 05:36
@qiskit-bot
Copy link
Collaborator

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

  • @Eric-Arellano
  • @Qiskit/terra-core
  • @kevinhartman
  • @levbishop
  • @mtreinish

This commit removes the Python implementation of the function. This is
now unused in Qiskit and was never a public class so nothing external
should be depending on it. Since it's not used we should just remove it.
@coveralls
Copy link

coveralls commented Jun 14, 2024

Pull Request Test Coverage Report for Build 9512074968

Details

  • 228 of 239 (95.4%) changed or added relevant lines in 2 files are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.04%) to 89.749%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 224 235 95.32%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/qasm2/src/lex.rs 2 92.88%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9503795487: 0.04%
Covered Lines: 63527
Relevant Lines: 70783

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 26, 2024

Pull Request Test Coverage Report for Build 9679860893

Details

  • 228 of 239 (95.4%) changed or added relevant lines in 2 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 89.782%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 224 235 95.32%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 93.13%
Totals Coverage Status
Change from base Build 9676629284: 0.02%
Covered Lines: 63914
Relevant Lines: 71188

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 26, 2024

Pull Request Test Coverage Report for Build 9681374865

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

  • 228 of 239 (95.4%) changed or added relevant lines in 2 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.004%) to 89.764%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 224 235 95.32%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 92.62%
Totals Coverage Status
Change from base Build 9676629284: 0.004%
Covered Lines: 63901
Relevant Lines: 71188

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jul 24, 2024

Pull Request Test Coverage Report for Build 10080593333

Details

  • 226 of 237 (95.36%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 89.922%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/accelerate/src/two_qubit_decompose.rs 222 233 95.28%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 3 92.62%
Totals Coverage Status
Change from base Build 10075234532: 0.03%
Covered Lines: 65974
Relevant Lines: 73368

💛 - 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.

Looks good, just a few super minor comments.


#[new]
#[pyo3(signature=(unitary_matrix, fidelity=DEFAULT_FIDELITY, _specialization=None))]
fn new(
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 value in following the pattern of naming this py_new and naming the Rust-side constructor new?

Copy link
Member Author

Choose a reason for hiding this comment

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

The pattern that's used everywhere in accelerate for this was rust is foo_inner and python is foo. I think we should normalize on a single pattern across all the crates, but maybe do that in a separate standalone PR?

crates/accelerate/src/two_qubit_decompose.rs Outdated Show resolved Hide resolved
@mtreinish mtreinish added this to the 1.2.0 milestone Jul 24, 2024
@kevinhartman kevinhartman added this pull request to the merge queue Jul 24, 2024
Merged via the queue into Qiskit:main with commit 6a78c63 Jul 24, 2024
15 checks passed
@mtreinish mtreinish deleted the oxidize-up-to-diagonal branch July 24, 2024 21:21
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
* Oxidize TwoQubitDecomposeUpToDiagonal

This commit ports the TwoQubitDecomposeUpToDiagonal class from Python to
rust. This internal private class is used internally by the quantum
shannon decomposition code, and while not performance critical was
simple to port. One difference is while the original Python
implementation was a class, it acted more like a function in practice.
So the new rust version is exposed as a function.

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Sebastian Brandhofer <148463728+sbrandhsn@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Eli Arbel <46826214+eliarbel@users.noreply.github.com>
Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
Co-authored-by: Henry Zou <87874865+henryzou50@users.noreply.github.com>
Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>

* Build circuit from rust

Since Qiskit#12459 recently merged we now have a mechanism to build a circuit
from rust. This commit updates the synthesis function to build the
circuit directly in rust instead of returning a circuit sequence and
building the circuit from Python. This should speed up the construction
substantially.

* Remove unused private Python class

This commit removes the Python implementation of the function. This is
now unused in Qiskit and was never a public class so nothing external
should be depending on it. Since it's not used we should just remove it.

* Remove unused import

* Calculate best_nbasis in unwrap_or_else()

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Co-authored-by: Sebastian Brandhofer <148463728+sbrandhsn@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: Julien Gacon <gaconju@gmail.com>
Co-authored-by: Eli Arbel <46826214+eliarbel@users.noreply.github.com>
Co-authored-by: Raynel Sanchez <87539502+raynelfss@users.noreply.github.com>
Co-authored-by: Henry Zou <87874865+henryzou50@users.noreply.github.com>
Co-authored-by: Shelly Garion <46566946+ShellyGarion@users.noreply.github.com>
Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
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 Rust This PR or issue is related to Rust code in the repository synthesis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants