Skip to content

Remove sympy as a hard dependency #14396

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
merged 7 commits into from
Jun 2, 2025

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented May 17, 2025

Summary

With the move to symbolic expression class added in #13278 the
dependency on sympy is no longer as core to the Qiskit package as it was
in the past. The only pieces that are still reliant on it are QPY
deserialization of payloads older than QPY v13 and some small
visualization utilities where sympy is used to generate the output.
Since this functionality is not core to the library and only used in
some less common use cases we no longer need to install sympy for every
installation of Qiskit. In preparation for this Qiskit 2.0 laid the
groundwork by marking all uses of sympy in Qiskit as being fallible if
sympy was not installed and documented that sympy is not guaranteed to
be installed with Qiskit anymore.

This commit implements this change and moves sympy to be an optional
dependency only used by some small components.

Details and comments

This is based on #14389 and #14391 and will need to be rebased after those PRs merge, Until that is done you can view the contents of just this PR with the head commit: c72288c Now that both dependencies have merged this has been rebased.

@mtreinish mtreinish added this to the 2.1.0 milestone May 17, 2025
@mtreinish mtreinish requested a review from a team as a code owner May 17, 2025 10:13
@mtreinish mtreinish added the Changelog: API Change Include in the "Changed" section of the changelog label May 17, 2025
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @mtreinish
  • @nkanazawa1989

@mtreinish mtreinish added the on hold Can not fix yet label May 17, 2025
@mtreinish
Copy link
Member Author

Oh looks like a few tests are missing skip decorators so the tests without optionals installed are failing.

@coveralls
Copy link

coveralls commented May 17, 2025

Pull Request Test Coverage Report for Build 15395252099

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

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • 33 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 87.813%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 9 91.48%
crates/qasm2/src/parse.rs 24 95.76%
Totals Coverage Status
Change from base Build 15393181973: -0.03%
Covered Lines: 80423
Relevant Lines: 91584

💛 - Coveralls

@mtreinish mtreinish force-pushed the remove-sympy-for-good-mostly branch from c72288c to 1544896 Compare May 21, 2025 21:28
@mtreinish mtreinish requested a review from nonhermitian as a code owner May 21, 2025 21:28
With the move to symbolic expression class added in Qiskit#13278 the
dependency on sympy is no longer as core to the Qiskit package as it was
in the past. The only pieces that are still reliant on it are QPY
deserialization of payloads older than QPY v13 and some small
visualization utilities where sympy is used to generate the output.
Since this functionality is not core to the library and only used in
some less common use cases we no longer need to install sympy for every
installation of Qiskit. In preparation for this Qiskit 2.0 laid the
groundwork by marking all uses of sympy in Qiskit as being fallible if
sympy was not installed and documented that sympy is not guaranteed to
be installed with Qiskit anymore.

This commit implements this change and moves sympy to be an optional
dependency only used by some small components.
@mtreinish mtreinish force-pushed the remove-sympy-for-good-mostly branch from 1544896 to fc437ea Compare May 22, 2025 12:41
@mtreinish mtreinish removed the on hold Can not fix yet label May 22, 2025
ElePT
ElePT previously approved these changes May 27, 2025
Copy link
Contributor

@ElePT ElePT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mtreinish mtreinish requested review from Cryoris and ElePT May 29, 2025 17:05
@mtreinish mtreinish requested a review from Cryoris June 2, 2025 14:42
Copy link
Contributor

@Cryoris Cryoris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional info -- let's see if anyone complains after the release, or if we correctly identified these bits as "not used so much" 😛

@Cryoris Cryoris added this pull request to the merge queue Jun 2, 2025
Merged via the queue into Qiskit:main with commit fe3e00e Jun 2, 2025
26 checks passed
@mtreinish mtreinish deleted the remove-sympy-for-good-mostly branch June 2, 2025 16:22
rahaman-quantum pushed a commit to rahaman-quantum/qiskit that referenced this pull request Jun 20, 2025
* Remove sympy as a hard dependency

With the move to symbolic expression class added in Qiskit#13278 the
dependency on sympy is no longer as core to the Qiskit package as it was
in the past. The only pieces that are still reliant on it are QPY
deserialization of payloads older than QPY v13 and some small
visualization utilities where sympy is used to generate the output.
Since this functionality is not core to the library and only used in
some less common use cases we no longer need to install sympy for every
installation of Qiskit. In preparation for this Qiskit 2.0 laid the
groundwork by marking all uses of sympy in Qiskit as being fallible if
sympy was not installed and documented that sympy is not guaranteed to
be installed with Qiskit anymore.

This commit implements this change and moves sympy to be an optional
dependency only used by some small components.

* Add sympy to backwards compat qpy jobs

* Update release notes

* Update releasenotes/notes/no-sympy-19687d5ca814042c.yaml

Co-authored-by: Julien Gacon <[email protected]>

---------

Co-authored-by: Julien Gacon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants