fix(CachedDag): cache the inputs a call was given - #83
Merged
Merged
Conversation
- Persist explicitly given var-node inputs in CachedDag.cache after a successful computation. - Re-passing an input with its cached value is allowed; a different value raises ValueError. - Cached values take precedence over the dag's defaults. - A user-supplied Mapping cache is now actually used (was left unset). - Fix the always-true assertion in cached_dag_test; add meshed/tests/test_cached_dag.py. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Address review of #83: recurse through _compute (not __call__) so the cache check and input caching run once per call; compare values without raising (identity first, then guarded ==); reject inputs that contradict cached downstream outputs; more tests (multi-level, array-like, nan, arg order, intermediate inputs). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Second review round of #83: a failed call left its intermediate outputs in the cache while (deliberately) not caching its inputs, so the retry was rejected by the downstream-contradiction check. Now the keys a failed call added are removed, and retries are tested. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ollback Third review round of #83: an intermediate var node given as an input was never checked against cached values it would be derived from, which silently poisoned the cache. It is now rejected. The rollback of a failed call no longer masks the original exception if the cache doesn't support deletion. Documented that inputs of a single call are not validated against each other. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…termines Fourth review round of #83: the upstream check fired whenever any ancestor was cached; now it only fires when every source of the node is settled by the cache or the dag's defaults, so giving an intermediate whose other inputs are unknown still works. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Closes #34
CachedDag.__call__used root inputs only transiently, soc('g', a=1)followed byc('f')failed with a missinga.Changes (all in
meshed/scrap/cached_dag.py):cacheafter a successful computation. Non-var-node kwargs are not cached.ChainMap(cache, defaults)), so a cachedy=5is not shadowed by the defaulty=2. Before this PR the cache only held non-root outputs, which have no defaults, so this doesn't change previous behaviour._computenow recurses into itself instead of re-entering__call__). An input is rejected if it is cached with a different value, if cached outputs downstream of it were computed without it, or if it is a non-root node the cache + defaults already determine. Inputs of a single call are not validated against each other (documented).nanand numpy-like inputs work (for those, only the same object counts as the same value).Mappingpassed ascache=is now actually used (previouslyself.cachewas never set in that branch ->AttributeError).cached_dag_testhad an always-trueassert c("f" == 2); fixed toc("f") == 2.meshed/tests/test_cached_dag.py(21 tests; CI's pytest ignoresscrap/, so the fix would otherwise be untested).Docstring examples still marked
+SKIPstay skipped: they fail for a separate reason (the dag built bycode_to_dagno longer carries defaults), not related to input caching.Review: four rounds by an independent refute-review agent; each round's findings (recursion re-running the checks, nan/array-like crashes, inputs pinned by failed calls, poisoned cache via intermediate inputs, rollback masking exceptions, over-broad rejection) were fixed and covered by tests.
Dependents: no module in the fleet imports
meshed.scrap.cached_dag(grep over all local repos + GitHub code search over thorwhalen/i2mint/otosense/inoocq). Test suites of the 10 local dependents present on this box (allude, dagapp, dotsci, extrude, front, guided, lookbook, theremin, titbit, uf) give byte-identical results with this branch and with master. meshed's own suite (excluding scrap/examples): 192 passed, 1 pre-existing failure (test_hybrid_dagneeds the optionalhttp2py).🤖 Generated with Claude Code