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

Speed-up SparsePauliOp.simplify #7122

Merged
merged 10 commits into from Oct 19, 2021
Merged

Speed-up SparsePauliOp.simplify #7122

merged 10 commits into from Oct 19, 2021

Conversation

t-imamichi
Copy link
Member

@t-imamichi t-imamichi commented Oct 12, 2021

Summary

SparsePauliOp.simplify is very slow if there are so many Pauli strings. I optimized some numpy codes.

Details and comments

micro benchmark

import random
from timeit import timeit

from qiskit.quantum_info import SparsePauliOp

k = 10
n = 10_000

random.seed(123)
op = SparsePauliOp.from_list([(''.join(random.choices('IXYZ', k=k)), 1) for _ in range(n)])
print(f'{timeit(lambda: op.simplify(), number=10)} sec')

main (06795bf)

2.9950154619999996 sec

this PR v1 (418c55b6)

0.2740141010000001 sec

this PR v2 (8492a26e)

0.162777092 sec

this PR v3 (aa134b0)

0.07564510999999996 sec

this PR v4 (f09d662) thanks to @jakelishman

0.04969994 sec

@t-imamichi t-imamichi requested review from chriseclectic and a team as code owners October 12, 2021 11:53
@t-imamichi
Copy link
Member Author

@ikkoham Could you review this PR?

@mtreinish mtreinish added performance mod: quantum info Related to the Quantum Info module (States & Operators) labels Oct 12, 2021
@ikkoham
Copy link
Contributor

ikkoham commented Oct 12, 2021

Thank you @t-imamichi . The first part is the performance regression I introduced in #6826.
I think this PR should be merged before the next version is released.

LGTM.

@t-imamichi
Copy link
Member Author

t-imamichi commented Oct 12, 2021

I notice that I can further speed-up this code. Let me check.
I applied a further optimization by packing bool vectors of paulis.x and paulis.z into np.int8 vectors.

@t-imamichi t-imamichi force-pushed the spo_simplify2 branch 2 times, most recently from aa134b0 to 3b2fbc4 Compare October 13, 2021 12:16
Copy link
Member

@jakelishman jakelishman 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, and a great speed up! I learned about np.packbits too, which I'd not come across before.

@jakelishman jakelishman added automerge Changelog: None Do not include in changelog labels Oct 18, 2021
@mergify mergify bot merged commit c432df2 into Qiskit:main Oct 19, 2021
@t-imamichi t-imamichi deleted the spo_simplify2 branch October 19, 2021 03:11
@kdk kdk added this to the 0.19 milestone Nov 15, 2021
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 mod: quantum info Related to the Quantum Info module (States & Operators) performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants