qiskit
qiskit copied to clipboard
Oxidize `NLocal` & family
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
- [x] Improve docstrings
- [x] Make the
entanglementhandling rust-side a bit better to understand instead of a 4-times nested vec - [ ] ~~Use
n_localinNLocal(i.e. fast path for Python code)~~ This might not be possible sinceNLocalworks withQuantumCircuits as blocks, butn_localneeds 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. - [x] Add the family members, like
efficient_su2etc.
Pull Request Test Coverage Report for Build 11723083102
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.
- For more information on this, see Tracking coverage changes with pull request builds.
- To avoid this issue with future PRs, see these Recommended CI Configurations.
- For a quick fix, rebase this PR at GitHub. Your next report should be accurate.
Details
- 530 of 530 (100.0%) changed or added relevant lines in 14 files are covered.
- 843 unchanged lines in 32 files lost coverage.
- Overall coverage increased (+0.1%) to 88.87%
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| qiskit/transpiler/target.py | 1 | 96.13% |
| qiskit/circuit/parameter.py | 1 | 98.36% |
| qiskit/synthesis/unitary/qsd.py | 1 | 97.58% |
| qiskit/compiler/transpiler.py | 1 | 93.14% |
| qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py | 1 | 96.97% |
| qiskit/circuit/library/generalized_gates/gms.py | 2 | 94.44% |
| qiskit/circuit/library/generalized_gates/rv.py | 2 | 84.62% |
| qiskit/transpiler/passes/optimization/consolidate_blocks.py | 2 | 96.15% |
| crates/qasm2/src/lex.rs | 3 | 92.48% |
| qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py | 3 | 97.83% |
| <!-- | Total: | 843 |
| Totals | |
|---|---|
| Change from base Build 11683622570: | 0.1% |
| Covered Lines: | 78307 |
| Relevant Lines: | 88114 |
💛 - Coveralls
One or more of the following people are relevant to this code:
@Cryoris@Qiskit/terra-core@ajavadia
069f45c added tests for the flagged lines in Coveralls (for the new functions, not for the existing classes), so I think we should have the 100% on that 🙂