Engine performance: SymPy finiteness bookkeeping, SymEngine at full size, simplification on large examples

Open
#348 7 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
performance

Research direction

Start with the benchmark set in benchmarks/ and the linked issues #264, #285, #330, and #331 for the original details. Profile each engine on polya_urn_coins, log_series_coins, digitRecognition, and nested_while.ppy to identify the reported bottlenecks. Done means each performance issue is fixed or explained, nested_while.ppy runs well below the CI limit without a higher timeout, and the benchmarks show the gains.

Written by the indexing model from the issue text.

Description

area: engines priority: medium topic: engine consistency

Collects the open performance problems of the engines (formerly #264, #285, #330, #331; their descriptions stay readable there). All exist on main. The benchmark set from #325 (benchmarks/, see #190) is the yardstick: every fix shows its effect there.

Items

  • SymPy recomputes finiteness (#331, #285): GeneratingFunction.__init__ recomputes _is_finite_function whenever a caller passes finite=False; SymPy is about 4x slower than GiNaC on polya_urn_coins and log_series_coins. The equivalence test nested_while.ppy on SymPy takes 67–100 s of its 120 s limit in the CI on Python 3.11 because of 98 finiteness checks (one cancel each). Likely one fix: derive the finiteness flag from the operation instead of re-checking every result.
  • SymEngine at full size (#330): polya_urn_coins with 8 outer / 30 inner iterations takes more than 120 s on SymEngine, 21 s on GiNaC; at 3/10 it is 1.3 s, so a further cause appears only at larger sizes. Not profiled.
  • SymPy with simplification on digitRecognition (#264): more than 13 min with simplification (the CLI default), 47 s without; 7840 observe statements and coefficients with thousands of digits. Probably simplification after every step; skip it where it cannot help (pure rationals).
  • SymPy _term_generator (from an independent code audit, verified on main): generating_function.py iterates a finite Poly by repeatedly subtracting the leading term (poly -= poly.EC() * poly.EM()), quadratic in the number of terms; a micro-benchmark showed 25x–250x for 26–401 terms when iterating reversed(poly.terms()) once and rebuilding the monomials from poly.gens. Keep the order of states; tests for univariate, multivariate, constant and zero polynomials. Quick fix.
  • SymEngine's SymPy fallbacks (same audit): the SymEngine engine falls back to SymPy in comparison, coefficient sums, iteration, expected values, substitution and unilateral approximation. Collect them in one place, document why each exists (missing functionality, exact semantics, convenience), and measure them on the benchmark set; replace one by native SymEngine only when the measurement shows a gain and exactness is kept.

Done when

Each item is profiled and fixed or explained, nested_while.ppy stays well below the CI limit without a raised timeout, and the benchmark set shows the gains.

Dominant language
Python
Stars
6
Forks
2
Avg merge
1h 52m
Merged PRs (30d)
187

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LKlinke/Prodigy

All issues in LKlinke/Prodigy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.