Conversation
Add MemoCanon.fsx to Scripts/ — extends Memo.fsx with a canonical
variable-name mapping layer so equations with identical *shape* but
different variable labels share a single cache entry.
Changes:
- New script: src/Informedica.GenSOLVER.Lib/Scripts/MemoCanon.fsx
• CanonKey module: sorts variable names, maps each to xi symbol,
replaces names in Equation.toString before caching
• Solver.solveAllMemoCanon: per-call Dictionary keyed on canonical
repr instead of exact variable-name repr
• Demo: shows two structurally identical equations (different labels)
yield the same canonical key, different exact keys
• Cross-patient batch test: canonical cache achieves higher hit rate
than exact cache when the same dosing formula is solved for many
patients with per-patient variable prefixes
• Correctness check: canonical results match baseline for dosing and
value-set scenarios
• Performance benchmarks: dosing (10 patients) + value-set (20 vals)
Next steps (per solver-memoization.md):
□ Full result remapping: on Changed hits, remap canonical names back
to caller names instead of re-solving
□ Session-level persistent cache with LRU eviction
□ Integrate into Solver.fs solveE
□ Property-based tests for name-independent cache-key correctness
Related: docs/code-reviews/solver-memoization.md, Roadmap W2
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
halcwb
approved these changes
Mar 17, 2026
Contributor
Greptile SummaryThis PR adds
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Equation.solve called] --> B{Cache lookup}
B -- Exact key hit --> C[Return cached result]
B -- Miss --> D[Canonicalise variable names\nsort alphabetically → x0, x1, x2…]
D --> E{Canonical cache lookup}
E -- Hit --> F[Remap canonical result\nback to original names]
F --> G[Return result + store under exact key]
E -- Miss --> H[Run Equation.solve]
H --> I[Store under canonical key\n+ exact key]
I --> J[Return result]
Last reviewed commit: 850b1e7 |
This was referenced Mar 18, 2026
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 PR was created by Repo Assist, an automated AI assistant.
Summary
This PR adds
MemoCanon.fsxtosrc/Informedica.GenSOLVER.Lib/Scripts/, extending the solver memoization work from Memo.fsx (merged in PR #169) with canonical variable-name mapping.Motivation
Memo.fsxcachesEquation.solveresults using the exactEquation.toStringrepresentation as the key. This means two structurally identical equations (same operator, same arity, same value constraints) with different variable labels produce different cache keys and miss each other's entries.Canonical-key memoization fixes this: before caching, variable names are sorted alphabetically and replaced with positional symbols (
x0,x1,x2, …). The canonical key therefore identifies the equation's shape + value snapshot independently of its label, allowing more cache sharing.Changes
src/Informedica.GenSOLVER.Lib/Scripts/MemoCanon.fsxCanonKeymodule: sorts variable names, maps each toxi, applies longest-name-first string replacement to avoid partial-match issuesSolver.solveAllMemoCanon: per-callDictionarykeyed on canonical representationresult = factorA * factorBandoutput = inputX * inputYwith the same value sets produce the same canonical key but different exact keysRelationship to solver-memoization.md roadmap
The
docs/code-reviews/solver-memoization.mdchecklist item:is addressed by this prototype. The remaining checklist items (full result remapping on Changed hits, session-level LRU cache, integration into
Solver.fs, property-based tests) are noted in the script's Summary section as next steps.Test Status