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

[PoC] Reduce the number of reshapes to improve Statevector performance #14032

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

t-imamichi
Copy link
Member

@t-imamichi t-imamichi commented Mar 17, 2025

Summary

This PR is a PoC to study the performance issue to resolve #14028.
This is made for discussion.

  • Added flatten option to control the flatten operation in Statevector. _evolve_operator
    • Changed to apply flatten only at the beginning and the end of Statevector._evolve_instruction
  • Simplified the contraction with np.tensordot
    • It does not have any performance improvement though

Details and comments

import timeit

import numpy as np
from qiskit import __version__ as qiskit_vesrion
from qiskit.circuit.library import EfficientSU2
from qiskit.quantum_info import Statevector

print(f"{qiskit_vesrion=}")

n_qubits = 18

qiskit_circuit = EfficientSU2(n_qubits, entanglement="pairwise", reps=n_qubits)
qiskit_circuit.assign_parameters(np.ones(qiskit_circuit.num_parameters), inplace=True)

number = 1
execution_time = timeit.timeit(lambda: Statevector(qiskit_circuit), number=number)
print(f"Average execution time: {execution_time / number:.6f} seconds")

main branch a6d6584

qiskit_vesrion='2.1.0.dev0+a6d6584'
Average execution time: 1.764300 seconds

this PR

qiskit_vesrion='2.1.0.dev0+313d92d'
Average execution time: 1.373686 seconds

@t-imamichi t-imamichi added performance mod: quantum info Related to the Quantum Info module (States & Operators) labels Mar 17, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 13893388124

Details

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • 4 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.02%) to 88.14%

Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/unitary_synthesis.rs 1 94.69%
crates/qasm2/src/lex.rs 3 92.98%
Totals Coverage Status
Change from base Build 13864210106: 0.02%
Covered Lines: 72730
Relevant Lines: 82516

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mod: quantum info Related to the Quantum Info module (States & Operators) performance type: discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Statevector performance
2 participants