Repository navigation
Improve the performance of scalar models by detecting them - #32
Draft
Transurgeon wants to merge 16 commits into
Draft
Transurgeon wants to merge 16 commits into
Transurgeon wants to merge 16 commits into
Conversation
Transurgeon
force-pushed
the
scalar-perf
branch
from
November 8, 2026 22:20
d297008 to
2686ab6
Compare
Transurgeon
marked this pull request as ready for review
November 8, 2026 23:42
Transurgeon
marked this pull request as draft
November 8, 2026 23:56
Transurgeon
commented
Nov 8, 2026
Transurgeon
commented
Nov 8, 2026
sp.compact(terms) is a drop-in for sp.vstack(terms). Terms with the same template (same operations, differing only in variable entries and scalar constants) are rebuilt once as a vector expression; other terms are kept. It returns (expr, perm), where row j of expr is terms[perm[j]], or perm is None when the order is unchanged. Nodes now carry an op name, and index/power carry the attrs the template reads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Modules: _atoms -> atoms, _expression -> expression, _compile -> problem (compile.py would clash with sp.compile), _compact -> vectorize. compact now lowers each term to (opcode, *operands) instructions whose operands are value numbers, plus per-term args for each load/const. Node.op is renamed Node.opcode. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tes, errors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…P RK4) Each problem is written vectorized and as a scalar loop; the loop form is checked through vstack and compact against the vectorized reference (f, grad, g, J, Lagrangian Hessian), with group counts pinned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replaces _n_groups (which read the vstack structure of compact's result) with count_nodes in conftest: compacting a loop at n and 2n must give the same number of nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_lower recurses, so a single very deep term (e.g. a 3000-term sum chain) raised RecursionError; it now falls back to being kept unmerged. The Brusselator forcing test duplicated what test_compact_matches_vectorized already checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename insts -> instructions and lanes -> rows, and document compact and its helpers with Parameters/Returns sections, following CVXPY. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
compact stacks scalar expressions into rows; it does not sum them, so "term" was misleading. Rename UnsupportedTermError to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like an LLVM pass pipeline, Problem now runs compact on each run of consecutive scalar constraints. Merged rows are gathered back into the given order with one index node, so constraint values, Jacobian rows and Lagrange multipliers keep their order. test_vectorize_problems now builds the scalar problems directly with Problem. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Transurgeon
force-pushed
the
scalar-perf
branch
from
November 9, 2026 01:03
3aa02ff to
b49ba05
Compare
This branch has not been deployed
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
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.
This is a simple PR which is able to automatically detect and convert scalar models to an equivalent vectorized one.
Most of the changes are just for adding an opcode to the operators (sort of like an attribute which holds the name of the operator).
The bulk of the changes are in
vectorize.py, and are run throughcompact.py.