Skip to content

perf(engine): a constraint that sums a variable present at every coordinate builds faster - #2334

Open
FBumann wants to merge 2 commits into
mainfrom
claude/busy-fermi-0xqmah-whole-variable
Open

FBumann wants to merge 2 commits into
mainfrom
claude/busy-fermi-0xqmah-whole-variable

Conversation

@FBumann

@FBumann FBumann commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Prompt: "Then do the second one also stacked"

Note

The following content was generated by AI.

A constraint without a condition whose one linear term is a variable that holds every coordinate, summed or not, is built by arithmetic in its own row order: no join places the term, no sort transposes it. dispatch · l: whole build 0.75 s → 0.63 s.

constraints:
  power_balance:
    dims: [snapshot]
    expression: sum(p, over=generator) == load   # p: [snapshot, generator], every p_max > 0
Measurements, mutation table, gates

Whole build, median of 5 warm builds, 3 alternating rounds, base main 721cdd6 vs head, same 4-core VM, idle:

model base head
case-dispatch-l (generator naming) 0.762 / 0.756 / 0.748 0.647 / 0.630 / 0.622
case-dispatch-l-unit (unit naming) 0.720 / 0.668 / 0.728 0.657 / 0.619 / 0.622
dispatch, every 10th p_max zero (falls back) 0.691 / 0.699 / 0.719 0.686 / 0.676 / 0.701
case-nodal-l 0.370 / 0.317 / 0.353 0.353 / 0.327 / 0.349
case-transport-l 1.201 / 1.024 / 1.079 1.104 / 1.055 / 1.058
case-storage-l 1.086 / 0.952 / 1.078 1.101 / 1.011 / 0.973
pypsa-carbon_management 3.994 / 3.942 / 3.904 4.269 / 4.078 / 3.793

The last four are within the VM's ±10% between rounds.

Constraint step (model.timings()), median of 5, 2 rounds, dispatch at 10M entries:

naming base head
generator (sorts before snapshot) 0.376 / 0.406 0.273 / 0.275
unit (sorts after) 0.291 / 0.271 0.280 / 0.245

The constraint no longer depends on which name sorts first.

Mutation table: each guard removed by hand, __pycache__ dropped both sides, restored through git checkout --, full suite (pytest -n auto); tree clean after.

guard result
one linear term only caught (test_archive, …)
the constraint holds every row (dense) caught (…laid_out_in_row_order…[a-condition-on-the-rows-…])
the term is a known variable caught (TestRowOrderCarriesNoMeaning)
the term spans the constraint's dimensions caught (…[a-term-over-fewer-dimensions-…])
the variable holds every coordinate caught (test_update, …[…-a-condition-that-removes-some])
_variable_term registers its table caught (…summed_on_every_row_is_neither_joined_nor_sorted)
_sum_term registers its table caught (same)

Tests: test_a_whole_variable_laid_out_in_row_order_is_the_matrix_the_joins_place builds 12 constraint layouts × 3 variable conditions with and without the placement and compares the matrices; test_a_whole_variable_summed_on_every_row_is_neither_joined_nor_sorted holds that the stack is skipped.

  • gate: pixi run check (7037 passed, 995 skipped, 4 xfailed); test-bench not run (no bench/ change)
  • not done: two or more terms on one row still join and sort (the stack would still need its sort); a variable with gaps still joins

https://claude.ai/code/session_018B3nA3AgfyCmR33mR1u9op


Generated by Claude Code

…dinate builds faster

A lone term that is a variable holding every coordinate, summed over the
dimensions a constraint without a condition lacks, is counted out in the
constraint's row order: its rows and columns are arithmetic, so no join
places it and no sort turns the variable's order into the constraint's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA3AgfyCmR33mR1u9op
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA3AgfyCmR33mR1u9op
@coderabbitai

coderabbitai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 8 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ac33eb98-4cdd-4571-a8b6-7d6332864c07
Commits

Reviewing files that changed from the base of the PR and between 721cdd6 and e2bbde8.

Files selected for processing: 4

  • CHANGELOG.md
  • src/specsolve/_engine/assembly.py
  • src/specsolve/_engine/queries.py
  • tests/internals/engine/test_relational.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@read-the-docs-community

read-the-docs-community Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

📖 2 files modified


Preview · build overview · specsolve · built Dec. 6, 2026, 1:02 p.m. UTC

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants