Skip to content

MAINT: Remove the sympy dependency - #947

Merged
mmcky merged 5 commits into
mainfrom
primes
Sep 9, 2026
Merged

mmcky merged 5 commits into
mainfrom
primes

Conversation

@oyamad

@oyamad oyamad commented Sep 4, 2026

Copy link
Copy Markdown
Member

Resolve the sympy half of #880:

  • Replace sympy.primerange(0, 7920) in qnwequi with a custom implementation _primes_upto (Claude Code Fable 5 recommended the most primitive algorithm).
  • This allows us to remove the sympy dependency.

oyamad and others added 2 commits August 19, 2026 17:39
Replace sympy.primerange with a custom prime sieve
Pin the invariants of the first 1000 primes (count, spot values, sum)
that qnwequi's Weyl and Haber sequences depend on, and the exclusive
upper bound matching sympy.primerange(0, n).

Co-Authored-By: Claude Fable 5 <[email protected]>
@oyamad oyamad added refactor dependencies Pull requests that update a dependency file labels Sep 4, 2026
@oyamad
oyamad requested a balanced review from Copilot September 4, 2026 07:07
@coveralls

coveralls commented Sep 4, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 90.789% (+0.009%) from 90.78% — primes into main

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The required changelog or release-note entry is missing, and the helper documentation misstates its exclusive upper bound.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Removes SymPy as a runtime dependency by replacing its prime generator with a NumPy sieve.

Changes:

  • Adds _primes_upto and uses it in qnwequi.
  • Adds prime-sequence regression tests.
  • Removes SymPy from package, test, and documentation environments.
File summaries
File Description
quantecon/quad.py Implements and uses the prime sieve.
quantecon/tests/test_quad.py Tests prime values and boundaries.
pyproject.toml Removes SymPy dependencies.
environment.yml Removes SymPy from development dependencies.
environment_np2.yml Removes SymPy from NumPy 2 environment.
docs/rtd-requirements.txt Removes SymPy from documentation dependencies.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread quantecon/quad.py Outdated
if equidist_pp is None:
import sympy as sym
equidist_pp = np.sqrt(np.array(list(sym.primerange(0, 7920))))
equidist_pp = np.sqrt(_primes_upto(7920))
Comment thread quantecon/quad.py Outdated

def _primes_upto(n):
"""
Return all primes up to n, by the Sieve of Eratosthenes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point. Changed the function name and the docstring.

oyamad and others added 2 commits September 4, 2026 16:18
The upper bound is exclusive; name and docstring now say so
(addresses a Copilot review comment on #947).

Co-Authored-By: Claude Fable 5 <[email protected]>
@oyamad oyamad added the ready label Sep 4, 2026

@quantecon-services quantecon-services left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @oyamad, this is a really nice, tidy change and it looks good to merge from my side. 🎉 The ~45 MB of sympy + mpmath that every pip install quantecon used to pay for one function-local call is gone, and qnwequi behaves exactly as before.

I went a bit beyond the CI run and checked the new sieve against sympy directly:

  • Same primes. _primes_below(7920) returns exactly the same 1000 primes as sympy.primerange(0, 7920), and the two agree for every upper bound from 0 to 2999.
  • Same qnwequi output. The default equidist_pp array is bit-for-bit identical to the old one, so kind="W" and kind="H" results are unchanged. I compared 56 shape combinations, up to 1000 dimensions, all identical. Together with the existing MATLAB-reference tests for W and H (which already go through the default equidist_pp path) and the new invariants test, the "output unchanged" criterion in #880 is well covered.
  • Fresh venv is clean. A pip install of this branch into a fresh venv pulls in no sympy or mpmath; import quantecon works and test_quad.py passes with sympy absent. That ticks the "fresh venv" criterion in #880 too. As a bonus, the sieve runs in about 20 µs versus roughly 1 ms for primerange (after a 0.2 s import).
  • Merges cleanly onto current main.

On the open Copilot comment asking for a changelog entry: per AGENTS.md, release notes live on GitHub Releases and per-PR changelog entries are not added, so that thread can safely be ignored. The lighter footprint can be mentioned in the next release notes instead.

Two optional nits, neither blocking:

  • The qnwequi docstring still says equidist_pp : ... TODO: I don't know what this does. Since this PR pins down exactly what it is, a one-liner along the lines of "square roots of the first 1000 primes by default; only the first d entries are used by the Weyl and Haber sequences" would be a nice improvement, here or in a follow-up.
  • math.isqrt instead of int(n**0.5), see the inline suggestion.

A few housekeeping thoughts for after the merge:

  • Keep #880 open for the requests half (or split that into its own issue).
  • When the next release is cut, note the dropped dependency in the release notes, and remember to drop sympy from the conda-forge feedstock run requirements (and the emscripten-forge recipe, if it lists it), since this PR only updates the metadata in this repo.
  • Nice side benefit for the JupyterLite work in #933: one fewer heavy wheel to load in the browser.

Generated by Claude Code

Comment thread quantecon/quad.py Resolved
Co-authored-by: QuantEcon <[email protected]>
@mmcky

mmcky commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

thanks @oyamad. Merging.

@mmcky
mmcky merged commit 4f4a502 into main Sep 9, 2026
14 checks passed
@mmcky
mmcky deleted the primes branch September 9, 2026 00:29
mmcky added a commit that referenced this pull request Sep 9, 2026
Catches the @-operator migration up to main (#831, #937, #947, #949).
Conflict in quantecon/tests/test_matrix_eqn.py: #831 appended
test_solve_discrete_riccati_system_beta_ge_one_failure_message directly
after the assert this branch rewrote to the @ operator. Kept both sides.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@mmcky mmcky mentioned this pull request Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file ready refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants