Repository navigation
Pure step, record markers and the first part of the redesign - #907
Conversation
A device sparse coupling whose array package gives it no conversion to CSR (COO or BSR) was stored as given and ran through generic sparse products. Building a Recurrence with one is now an ArgumentError that names the type and says to convert to CSR. CSC is still converted through the array package's own csr_type. Part of #834. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Part of #281. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
The bullets no longer name the API, tooling or benchmark figures, which the performance page holds. The home-page link rewrites for the links they carried are removed with them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
…ME bullet The refusal of a form with no CSR conversion is tested with stubs in gpu_arrays.jl, so the conversion item no longer repeats the condition. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Try this Pull Request!Option 1: Julia Package ManagerOpen Julia and type: import Pkg
Pkg.activate(temp=true)
Pkg.add(url="https://github.com/EpiAware/ComposableRecurrences.jl", rev="claude/amazing-shannon-6nrow8")
using ComposableRecurrencesOption 2: Local CheckoutIf you have the repo locally: git checkout claude/amazing-shannon-6nrow8
julia --project=. -e "using Pkg; Pkg.instantiate()" |
Benchmark comparison vs baseMinimum time per call. Buckets are PR time as a % of base, so lower is faster (🟢 faster, ⚪ within 5%, 🔴 slower). Counts of benchmarks per bucket:
Evaluation — 17 benchmarks (by time change)
AD gradients — 42 benchmarks (by time change)
|
|
📖 Documentation preview is ready! View the docs for this PR at: https://EpiAware.github.io/ComposableRecurrences.jl/previews/PR907/ This preview will be updated automatically when you push new commits. |
A modifier that acts on each stratum or group is written as step(m, θ, v, s), with init(m, θ, history) and an optional step_pullback. θ holds the modifier's fields, each parameter read at the stratum and time, so the rule differentiates the step with one forward-mode pass over (v, s, θ) and never rebuilds the type. Transform and the depletion forms Hazard, Floor and Truncate are pure steps. A coupling or modifier written with forward! takes the rule with a pullback! or islinear, and plain AD otherwise. ForwardDiff is a dependency: the dual-number code moves from its extension into src, and the struct-rebuild fallback, the rebuilds field and the widths of _fit go. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Adds test/unit/pure_step.jl: a pure step against a hand loop, its rule against ForwardDiff for each parameter form, group steps, ties, single precision, a depletion form, the step check of PieceInterface and JLArrays with scalar indexing off. Test modifiers without a pullback! become pure steps, and the items that pinned the fallback's internals go. The AD fixtures write their pointwise modifiers as pure steps where the package has them. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
The first example of Writing new types is a struct with init and step, its optional step_pullback, and a group step. Adjoints and backends replaces the fallback table with the two-row rule and describes the local derivative. The benchmark modifier is a pure step, and benchmark/step_pullback_ab.jl times a rule with step pullbacks hidden. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Timed against the local derivative on Mooncake and Enzyme reverse, in alternating fresh processes, the step pullbacks of Floor and of Transform's +, * and clamp show no gain, so they go. Truncate's is 1.17 to 1.22 times faster and stays. Hazard's shows no gain in time but stays for the empty pool, where a dual pass multiplies the zero pool by the infinite slope of its power. Also fixes what the full suite and the quality checks found: test and fixture modifiers that relied on the rebuild fallback become pure steps, the AD registry lists the scenarios that take plain AD by design, and the dual-number helpers pass Aqua and ExplicitImports. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Its coupling has no pullback!, so its call takes plain AD on both reverse backends. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
The modifier holding a tuple of 35 or 40 active scalars takes the rule again, with its local derivative in two passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
…init on a device The step check of PieceInterface changes the modifier's own float parameters while holding θ and asks for the same result, so a step that reads a field instead of θ fails rather than giving a zero gradient. A pure step's init reverses per stratum or group as its step does, in order on the host and as a kernel on device arrays, so a pure step with an init and array parameters takes the rule on a device. The docs navigation file is the kit's again, and the forms page says how to write a form whose power of the pool is zero at an empty pool. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
A stateless step is chosen by dispatch, so the analysis does not narrow the modifier to the built-in stateless types, and init has a method for a type no modifier has, so its method table is not empty. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
|
Scope change: this branch now also carries stage 1 of the piece-interface redesign, stacked on the small fixes above and on current It was pushed here so the work is not lost with the build container; it is not yet fully verified and should not be merged as it stands. What stage 1 adds:
Verified so far: the non-AD suite and quality checks before the rebase onto Generated by Claude Code |
…ures The rule called directly on a recurrence with a part that has no pullback throws an ArgumentError naming the part, where it failed with a MethodError inside a step. The device rule fixtures without a pullback are pure steps. The chunked dual pass and the init pass take their running cotangents through helpers, so no closure captures a reassigned variable. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
|
CI on 74bc387, for the record:
Generated by Claude Code |
…1.11 The matrix coupling's first column now assigns and the rest accumulate. With ForwardDiff loaded when the package precompiles, the zeroing pass compiled to a library memset call, which costs more than the loop at a few strata (5 to 15% of a coupled run). The dual pass hands its tag to the closures as a static parameter: a closure that captures a type as a value does not infer it on Julia 1.11. The A/B script also times ForwardDiff gradients and the primal. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
A step's output and its cotangent are numbers and tuples, never a NamedTuple, and a step always has a float input, so those methods of the dual pass are removed, with the mirror reader's method for a missing scalar mirror. New tests: a blockwise pure step whose state is read, so its `init` is differentiated in the parameters and the histories; a constant history; an `Init` set by `forward!` with no `pullback!`; a local derivative nested in another comparing by value; a constant map. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
|
Generated by Claude Code |
|
The benchmark comparison on 21fb0bb reports every evaluation case 1.2× to 2× slower. Three alternating rounds of the suite's Evaluation group,
In the CI table the control with no package code ( Not covered by this run: the AD gradient groups at this head. Generated by Claude Code |
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Claude-Session: https://claude.ai/code/session_01WwC7ixPP4D3aW3SnheFhKB Co-authored-by: Claude <noreply@anthropic.com>
* Add Wren models that use CR, with hand-loop references Three Wren models (renewal with delay, stratified renewal with mixing and depletion, time-varying delay) each written with CR and with hand loops, plus scripts for gradient checks, Reactant checks and timings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyRmhVe6dsWT5gvbPS * Add Wren check results, reproducers and README Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyRmhVe6dsWT5gvbPS * Format compile_check.jl helper for Runic Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyRmhVe6dsWT5gvbPS * Make Wren checks fail loudly, bound compat, regenerate all results check_primal.jl and ad_check.jl now exit with an error on a mismatch, a large gradient error or a CR rule that does not run. run_all.sh now produces every log in results/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iyRmhVe6dsWT5gvbPS --------- Co-authored-by: Claude <noreply@anthropic.com>
Downstream check: BVDOutbreakSize
|
| Run | Pass | Fail | Error | Broken |
|---|---|---|---|---|
ad_only on this branch |
4260 | 2 | 0 | 0 |
fast on this branch |
60683 | 0 | 0 | 0 |
the two failing ad_only items, original pin |
3553 | 2 | 0 | 0 |
Both failures are in test/test_mooncake_rules.jl and both also fail on the original pin, so neither comes from this branch.
- "every rule passes Mooncake's test_rule", testset
accumulate_occupancy: confirmed clamp: fails the same way on both versions, with identical numbers. - "each rule beats the rules-off derivation", testset
discretise_censored: generation interval: a wall-clock assertionratio <= 0.8on a 20 μs call.
The ratio was 1.006 on this branch and 0.861 on the original pin.
No call on this branch logged "plain AD of the whole operator".
Not run: the full suite, the :slow fits and the :quality items.
The later commits on this branch (typed record markers, Share{B}) were not part of this check.
Generated by Claude Code
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
What changes
The first part of the redesign tracked in #921.
step(m, θ, v, s) -> (v′, s′), with an optionalinit(m, θ, history)and an optionalstep_pullback.θholds the modifier's fields, read at the stratum and time of the step.The local derivative comes from one dual-number pass over
(v, s, θ), so a modifier needs no hand-written rule.ForwardDiff becomes a dependency and its extension is removed.
recordtakesPressure(),Trace()andResume(), and the call returnsywith a field for each, in the orderstate,pressure,trace.Recurrence(; coupling, modifiers)is a recurrence with a unit kernel.Share(; bounded = false)takes a share with no upper bound.benchmark/wren/.NEWS.mdis removed; release notes live on the release.Tested
Locally, on the commit before the record markers were merged:
main);main: at parity (median ratio 1.00).On later commits:
main: median ratio 0.99, range 0.88 to 1.07;Not yet confirmed
Share{B}is the candidate fix; no CI run has completed on it.ad / ReverseDiff (compiled)fails as onmain(ReverseDiff compiled tape gives wrong values for the transpose of normalised table increments #913); the fix is in Settle the open issues: a compiled-tape fix and the outcome of each issue #925.Follow-up work is in the PRs listed on #921.
https://claude.ai/code/session_01WwC7iwncmH7NPsrzAxQM9s
Generated by Claude Code