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

[WIP] Move utility functions _inverse_pattern and _get_ordered_swap to Rust #12327

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jpacold
Copy link

@jpacold jpacold commented May 2, 2024

Summary

This PR starts addressing #12225. I moved the implementations of two functions from qiskit/synthesis/permutation/permutation_utils.py to Rust.

Details and comments

  • Created permutation.rs

    • I added some checks to ensure that inputs are actually permutations. Otherwise, _get_ordered_swap uses the same logic as it did in Python.
    • Performance is better than Python, but sensitive to input type (more notes below)
  • Added a module qiskit._accelerate.permutation and a submodule qiskit._accelerate.permutation.permutation_utils (following the structure of the existing Python modules). The wrapped functions are in the permutation_utils submodule.

  • Replaced the function bodies in permutation_utils.py with calls to the Rust functions.

  • Added tests.

Performance

As expected, this implementation of _get_ordered_swap is faster than the Python version. However, the input type is expected to be an array of int64 and there is a performance cost for converting from any other type. On my machine:

Input type Speedup over Python
Numpy array (int64) ~15x
Numpy array (int32, uint32, or uint64) ~4x
Python list ~7x

For now, I don't think this matters much, because the bottleneck in synth_permutation_basic is constructing the circuit, but it is something that might need to be optimized later on.

@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label May 2, 2024
@CLAassistant
Copy link

CLAassistant commented May 2, 2024

CLA assistant check
All committers have signed the CLA.

@mtreinish mtreinish added performance synthesis Rust This PR or issue is related to Rust code in the repository labels May 2, 2024
@mtreinish mtreinish added this to the 1.2.0 milestone May 2, 2024
@coveralls
Copy link

coveralls commented May 2, 2024

Pull Request Test Coverage Report for Build 9109062685

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

  • 84 of 84 (100.0%) changed or added relevant lines in 4 files are covered.
  • 7 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.03%) to 89.629%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 7 92.62%
Totals Coverage Status
Change from base Build 9100255975: 0.03%
Covered Lines: 62371
Relevant Lines: 69588

💛 - Coveralls

@jpacold jpacold marked this pull request as ready for review May 7, 2024 04:00
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the the following people are requested to review this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community PR PRs from contributors that are not 'members' of the Qiskit repo performance Rust This PR or issue is related to Rust code in the repository synthesis
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

5 participants