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 NLocal & family #13310

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

Oxidize NLocal & family #13310

wants to merge 8 commits into from

Conversation

Cryoris
Copy link
Contributor

@Cryoris Cryoris commented Oct 11, 2024

Summary

Part of #13046: create the n_local function and port the internals to Rust. This will include other parts of the NLocal family, such as TwoLocal, EfficientSU2, RealAmplitudes etc. EvolvedOperatorAnsatz is potentially a bit more involved and might be done in a follow-up.

Details and comments

The new code is particularly fast when dealing with gates we already have in Rust and that don't need any special re-parameterization. In this case:

the new code is ~22x faster for 100 qubits, full entanglement and 10 reps
num qubits: 10, speedup: 9.075
main: 0.005 +- 0.004
this: 0.001 +- 0.000

num qubits: 50, speedup: 18.138
main: 0.063 +- 0.014
this: 0.003 +- 0.003

num qubits: 100, speedup: 22.011
main: 0.251 +- 0.034
this: 0.011 +- 0.007

num qubits: 200, speedup: 26.829
main: 0.957 +- 0.034
this: 0.036 +- 0.010

But if custom gates or special parameterizations are used (e.g. RXGate(x + 3 * y)) we need to go back to Python space to correctly handle the parameter logic. This slows down the code and in this case:

the new code is ~3.5x faster for 100 qubits, linear entanglement (full took too long) and 10 reps
num qubits: 10, speedup: 4.594
main: 0.027 +- 0.006
this: 0.006 +- 0.000

num qubits: 50, speedup: 3.947
main: 0.162 +- 0.006
this: 0.041 +- 0.011

num qubits: 100, speedup: 3.666
main: 0.366 +- 0.031
this: 0.100 +- 0.019

To do

  • Improve docstrings
  • Make the entanglement handling rust-side a bit better to understand instead of a 4-times nested vec
  • Use n_local in NLocal (i.e. fast path for Python code) This might not be possible since NLocal works with QuantumCircuits as blocks, but n_local needs gates. Functionally it'd be the same but the circuits are nested differently, which is not backward compatible. We could add a fast-path in case the inputs are not circuits but gates.
  • Add the family members, like efficient_su2 etc.

@Cryoris Cryoris added performance Rust This PR or issue is related to Rust code in the repository mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Oct 11, 2024
@coveralls
Copy link

coveralls commented Oct 11, 2024

Pull Request Test Coverage Report for Build 11385891601

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

  • 528 of 540 (97.78%) changed or added relevant lines in 14 files are covered.
  • 48 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.06%) to 88.713%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/circuit/library/n_local/excitation_preserving.py 15 16 93.75%
crates/accelerate/src/circuit_library/n_local/blocks.rs 92 95 96.84%
qiskit/circuit/library/n_local/n_local.py 87 95 91.58%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/two_qubit_decompose.rs 1 91.54%
qiskit/circuit/library/standard_gates/u.py 1 93.0%
qiskit/circuit/library/standard_gates/rz.py 2 95.83%
qiskit/synthesis/stabilizer/stabilizer_decompose.py 2 96.77%
qiskit/circuit/library/standard_gates/ry.py 2 95.95%
qiskit/circuit/library/standard_gates/u3.py 2 97.06%
qiskit/synthesis/unitary/qsd.py 2 97.56%
qiskit/circuit/library/standard_gates/rx.py 2 96.05%
qiskit/transpiler/passes/scheduling/base_scheduler.py 5 88.37%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 11372663133: 0.06%
Covered Lines: 73694
Relevant Lines: 83070

💛 - Coveralls

@mtreinish mtreinish added this to the 1.3.0 milestone Oct 15, 2024
@Cryoris Cryoris marked this pull request as ready for review October 17, 2024 13:33
@qiskit-bot
Copy link
Collaborator

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

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

@mtreinish mtreinish self-assigned this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library 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.

4 participants