Document persistent designs and factor encoding - #336
Open
leostimpfle wants to merge 1 commit into
Open
Conversation
This was
linked to
issues
Aug 27, 2026
leostimpfle
force-pushed
the
design/persistent-design-changelog
branch
from
August 29, 2026 08:22
4a75c19 to
0d23f96
Compare
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.
Hi @schroedk ! I'm on holiday this week so had too much time to create too many pull requests 🙂
This PR concludes the stack #326 to address #268 and #269. I'll try to outline the stack's structure with the hope that it will make it easier to follow what's going on. Although there are many PRs (15 including this one), each individual diff is small and the core changes are in four PRs with the remaining ones being mostly mechanical refactors (see below).
This PR stack introduces two core features
DesignAPI: PersistentDesign#269A core design decision is the separation of an immutable
Designand a solver-specificSolverState:within/crates/within-py/src/api.rs
Lines 325 to 328 in a5e9282
This separates a persistent
Design's ownership from aSolver's local state (e.g., weighting, slope whitening, ...). I have landed on this separation after encountering some ownership awkwardness in #320. Note that the current implementation does not ensure that aSolverStateis consistent with aDesign, so if we end up with this implementation, we may want to add additional guardrails (similar to #270).Illustration of new features
The changes allow us to do something like this:
Guide to PR stack
The core changes are in four PRs:
FactorLabelabstraction to make coefficient layouts and unidentified directions use caller-visible factor labels.Solverinto a design-specificSolverStateand an immutableDesign.Designin Python and allows multiple Python solvers to share it.u32labels into dense internal positions while preserving caller-label result lookup.The remaining PRs have a mostly supporting role to enable the four core changes above:
FactorEncodingabstraction used by caller-label translation.Designfrom a categories matrix.Solver::from_design, allowing multiple Rust solvers to borrow one persistent design.SolverStatepublic so the Python facade can own it alongside a persistentDesign.Designin the one-shotsolveandsolve_batchfunctions as well.Potential clean-ups (if we settle on the basic implementation in this stack)
Solverconstruction from a borrowed&'a Design<a'>without touching the existing owned construction to keep the diff small. We may want to remove the "owned" and only keep the "borrowed" construction.Designwith aSolverStateconstructed from a differentDesign. AlthoughSolverStateis public, it is not intended be part of the main user-facing API. It only needs to be public forwithin-py.