-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Remove sympy usage in polynomial_pauli_rotations #4385
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
Merged
mergify
merged 2 commits into
Qiskit:master
from
mtreinish:no-sympy-polynomial-rotations
May 6, 2020
Merged
Remove sympy usage in polynomial_pauli_rotations #4385
mergify
merged 2 commits into
Qiskit:master
from
mtreinish:no-sympy-polynomial-rotations
May 6, 2020
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit replaces the use of sympy's multinomial coefficient function with an inlined version. Sympy is a very large package and very slow to import (which is why the only other usage is imported at run time instead of at the module level). In this specific case requiring the entirety of sympy for simple functions to generate sequences of coefficients is a bit of overkill this commit adds equivalent private functions to the polynomial_pauli_rotations module for generating the coefficients. For performance in general we should only rely on sympy if we need it for symbolical math and then only if there isn't any other option. These functions are based heavily on the equivalents in sympy [1], however they're updated to remove the assumption that non-ints are passed in, and adjusted for terra's needs and style conventions. [1] https://github.com/sympy/sympy/blob/sympy-1.5.1/sympy/ntheory/multinomial.py
Cryoris
approved these changes
May 4, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the improvement! I wasn't aware that the sympy import is that heavy. 🙂
kdk
approved these changes
May 6, 2020
faisaldebouni
pushed a commit
to faisaldebouni/qiskit-terra
that referenced
this pull request
Aug 5, 2020
This commit replaces the use of sympy's multinomial coefficient function with an inlined version. Sympy is a very large package and very slow to import (which is why the only other usage is imported at run time instead of at the module level). In this specific case requiring the entirety of sympy for simple functions to generate sequences of coefficients is a bit of overkill this commit adds equivalent private functions to the polynomial_pauli_rotations module for generating the coefficients. For performance in general we should only rely on sympy if we need it for symbolical math and then only if there isn't any other option. These functions are based heavily on the equivalents in sympy [1], however they're updated to remove the assumption that non-ints are passed in, and adjusted for terra's needs and style conventions. [1] https://github.com/sympy/sympy/blob/sympy-1.5.1/sympy/ntheory/multinomial.py Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Sep 29, 2020
Just as in Qiskit#4385 and Qiskit#3156 we should not be importing sympy at the module level. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes imports significantly slower. This commit reverts the top level import of sympy, which was only added for type hints, to fix the import performance regression.
1ucian0
pushed a commit
that referenced
this pull request
Sep 30, 2020
Just as in #4385 and #3156 we should not be importing sympy at the module level. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes imports significantly slower. This commit reverts the top level import of sympy, which was only added for type hints, to fix the import performance regression.
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Nov 19, 2020
Just as has been demonstrated many times in the past we should not be importing sympy at the module level. In Qiskit#5259 another import was added and was immediately flagged as an import speed regression [1]. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes and is honestly a dependency we should be reluctant to add anywhere because it becomes the primary bottleneck whenever it is used. This commit removes the top level sympy import and moves to be a runtime import in the single method that uses sympy. Just as it was done in Qiskit#5149, Qiskit#4385, and Qiskit#3156 before. [1] https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?commits=b5d5a3bb
mergify bot
pushed a commit
that referenced
this pull request
Nov 20, 2020
Just as has been demonstrated many times in the past we should not be importing sympy at the module level. In #5259 another import was added and was immediately flagged as an import speed regression [1]. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes and is honestly a dependency we should be reluctant to add anywhere because it becomes the primary bottleneck whenever it is used. This commit removes the top level sympy import and moves to be a runtime import in the single method that uses sympy. Just as it was done in #5149, #4385, and #3156 before. [1] https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?commits=b5d5a3bb Co-authored-by: Julien Gacon <gaconju@gmail.com>
mtreinish
added a commit
to mtreinish/qiskit-core
that referenced
this pull request
Jan 4, 2021
Just as has been demonstrated many times in the past we should not be importing sympy at the module level. In Qiskit#5358 another import was added and was immediately flagged as an import speed regression [1]. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes and is honestly a dependency we should be reluctant to add anywhere because it becomes the primary bottleneck whenever it is used. This commit removes the top level sympy import and moves to be a runtime import in the single method that uses sympy. Just as it was done in Qiskit#5416, Qiskit#5149, Qiskit#4385, and Qiskit#3156 before. Fixes Qiskit#5575 [1] https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?commits=300e9507
kdk
pushed a commit
that referenced
this pull request
Jan 4, 2021
Just as has been demonstrated many times in the past we should not be importing sympy at the module level. In #5358 another import was added and was immediately flagged as an import speed regression [1]. Sympy is a very heavy dependency and is slow to import (and slow to run too). Adding a sympy import to the module level makes and is honestly a dependency we should be reluctant to add anywhere because it becomes the primary bottleneck whenever it is used. This commit removes the top level sympy import and moves to be a runtime import in the single method that uses sympy. Just as it was done in #5416, #5149, #4385, and #3156 before. Fixes #5575 [1] https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?commits=300e9507
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This commit replaces the use of sympy's multinomial coefficient function
with an inlined version. Sympy is a very large package and very slow to
import (which is why the only other usage is imported at run time instead
of at the module level). In this specific case requiring the entirety of
sympy for simple functions to generate sequences of coefficients is a
bit of overkill this commit adds equivalent private functions to the
polynomial_pauli_rotations module for generating the coefficients. For
performance in general we should only rely on sympy if we need it for
symbolical math and then only if there isn't any other option.
These functions are based heavily on the equivalents in sympy [1],
however they're updated to remove the assumption that non-ints are passed
in, and adjusted for terra's needs and style conventions.
Details and comments
This will address the import time performance regression:
https://qiskit.github.io/qiskit/#import.QiskitImport.time_qiskit_import?machine=qiskit-benchmarking&os=Ubuntu%2018.04&ram=16%20GB&commits=4bd91fef
which was introduced when moving the standard gates to the circuit library, which caused the library classes to imported from the base qiskit namespace.
[1] https://github.com/sympy/sympy/blob/sympy-1.5.1/sympy/ntheory/multinomial.py