Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
fb8773a
Refuse a device sparse coupling with no conversion to CSR
claude Nov 30, 2026
7d9bde2
Link the published benchmark grid from the performance page
claude Nov 30, 2026
9ff53c8
Drop recorded times of test items that no longer exist
claude Nov 30, 2026
a800a76
Shorten the README motivation bullets to one sentence each
claude Nov 30, 2026
26d6b08
Test the CSC conversion only where JLArrays has it, and reword a READ…
claude Nov 30, 2026
88e3f22
Add the pure step and take its local derivative in the rule
claude Nov 30, 2026
9a3925d
Test the pure step and drop the tests of the rebuild fallback
claude Nov 30, 2026
c8eb19e
Document the pure step and the two ways a component takes the rule
claude Nov 30, 2026
18677ed
Keep the step pullbacks that pay and drop the rest
claude Nov 30, 2026
a489537
List the call-checked scenario among those that take plain AD
claude Nov 30, 2026
08af340
Write the 32-entry tuple regression's modifier as a pure step
claude Dec 1, 2026
47b1fd9
Fail a step that reads its parameters from the modifier, and reverse …
claude Dec 1, 2026
f7ddae6
Pass the static analysis of the pure step
claude Dec 1, 2026
6189dcd
Merge remote-tracking branch 'origin/main' into claude/amazing-shanno…
claude Dec 1, 2026
74bc387
Merge branch 'canonical-step-stage1' into claude/amazing-shannon-6nrow8
claude Dec 1, 2026
71c6202
Say why a recurrence does not take the rule, and port the device fixt…
claude Dec 1, 2026
28b8a37
Keep the coupled primal at speed and the dual pass inferred on Julia …
claude Dec 1, 2026
2f72bde
Drop unreachable dual-pass methods and test a group's starting state
claude Dec 1, 2026
ba05903
Merge branch 'canonical-step-stage1' into claude/amazing-shannon-6nrow8
claude Dec 1, 2026
2c8be20
Say where the forward-mode pass of a step gives NaN
claude Dec 1, 2026
0a9026f
Take record markers, a recurrence without a kernel and an unbounded s…
claude Dec 1, 2026
cd6f3f4
Port the tests and fixtures to record markers
claude Dec 1, 2026
7af7746
Document record markers, a recurrence without a kernel and an unbound…
claude Dec 1, 2026
e376ce6
Read the markers from types in the remaining tests
claude Dec 1, 2026
8f55983
Give Resume its maths and keep the record prose one sentence a line
claude Dec 1, 2026
1c30972
Hold the barrier test's constants as constants
claude Dec 1, 2026
fe86466
Drop the host-copy init pullback a pure step no longer takes
claude Dec 1, 2026
c779d35
Test that a step whose type refuses changed parameters passes its check
claude Dec 1, 2026
9b1acdd
Merge branch 'canonical-step-stage1' into claude/amazing-shannon-6nrow8
claude Dec 1, 2026
4d204b9
Merge branch 'typed-record' into claude/amazing-shannon-6nrow8
claude Dec 1, 2026
fd4c722
Say groups, not strata, in the README's opening bullets
claude Dec 1, 2026
1305f39
Drop the notes on tracked numbers and recorded tapes
claude Dec 1, 2026
21fb0bb
Split an overlong sentence on record markers
claude Dec 1, 2026
ffb3917
Carry a share's bound in its type
claude Dec 1, 2026
f9291ab
Add Reactant registry rows for the named-trace record scenario (#927)
seabbs-bot Dec 1, 2026
4d5b1f1
Check CR inside Wren models (#917)
seabbs-bot Dec 1, 2026
1f19e43
Dispatch a share flow on any Share
claude Dec 1, 2026
66aead3
Remove the news file: release notes live on the release
claude Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
- A call on device arrays (GPU arrays, such as `CuArray` or `JLArray`) whose kernel, coupling, modifier parameters, gain or add input, or resumed state holds a host array is now an `ArgumentError`.
Before, such a call ran its strata loops with the host arrays inside device kernels, which works on JLArrays but not on a GPU.
To migrate, move kernels and parameters to the device first, for example with `Adapt.adapt(CuArray, r)`, which moves every parameter of an operator `r`, or `Recurrence(cu(g))`.
- A device sparse coupling in a form its array package cannot convert to CSR, such as COO or BSR, is an `ArgumentError` when the `Recurrence` is built.
To migrate, convert the coupling to the device's CSR sparse matrix first.

- ForwardDiff is a weak dependency.
A gradient through the local derivative of a coupling, modifier, depletion form or `Transform` without its own `pullback!` or `derivative` needs `using ForwardDiff`, and without it throws an `ArgumentError` that says so ([adjoints and backends][adjoints]).
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@ Fast, [composable](https://composablerecurrences.epiaware.org/stable/explanation

## Why ComposableRecurrences?

- A recurrence computes each value from its own past values, such as infections from earlier infections.
A convolution weights the past values of another series, such as reported cases from earlier infections.
- Both are usually hand-written loops, rewritten for each model.
`Recurrence` and `Convolution` express them as two operators, for one series or for many strata, such as towns, run side by side.
- Mixing between strata, finite pools and caps are added by passing couplings and modifiers to an operator.
- Operators run on CPU threads and on [GPU arrays](https://composablerecurrences.epiaware.org/stable/explanation/adjoints-and-backends/#gpu-arrays) through KernelAbstractions.jl.
On Julia 1.12 and later, a forward run compiles into a [trimmed executable](https://composablerecurrences.epiaware.org/stable/developer/extending-performance/#trimming) with `juliac`.
- The aim is to be as fast as hand-written code with hand-written gradients.
Against a hand-written loop of each documented model, the package's Mooncake and Enzyme gradients are a median 4.1× and 2.4× faster than the same backend on the loop, comparing minimum times.
The forward run and ForwardDiff gradient run at a median 1.2× and 1.1× the loop's speed, and are slower on several models.
These figures are from revision 48f2396; see the [benchmarks](https://composablerecurrences.epiaware.org/stable/benchmarks/over-time/#benchmarks-hand-written) for each model and the slower cases.
- Epidemic models are built from recurrences, where each value depends on earlier values, and convolutions, where a delay spreads one series into another.
Comment thread
seabbs-bot marked this conversation as resolved.
Resolved
- These are usually hand-written loops, rewritten and re-debugged for each new model.
- Here they are building blocks that combine, so adding strata, mixing between them, a finite population or a time-varying delay does not mean starting again.
- The aim is the speed of hand-written code with hand-written gradients, without writing either.
- The same model code runs on CPU and GPU arrays, and under forward- and reverse-mode automatic differentiation.

## Getting started

Expand Down
8 changes: 0 additions & 8 deletions docs/docs_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,6 @@ const INDEX_REWRITES = Pair{String, String}[
"](@ref api-overview)",
"](https://composablerecurrences.epiaware.org/stable/explanation/adjoints-and-backends/)" =>
"](@ref adjoints-backends)",
# The performance summary's link, to the benchmarks page section.
"](https://composablerecurrences.epiaware.org/stable/benchmarks/over-time/#benchmarks-hand-written)" =>
"](@ref benchmarks-hand-written)",
# The GPU and trimming links, as in-site references.
"](https://composablerecurrences.epiaware.org/stable/explanation/adjoints-and-backends/#gpu-arrays)" =>
"](@ref gpu-arrays)",
"](https://composablerecurrences.epiaware.org/stable/developer/extending-performance/#trimming)" =>
"](@ref trimming)",
# The extensions overview, as an in-site reference.
"](https://composablerecurrences.epiaware.org/stable/getting-started/#extensions-overview)" =>
"](@ref extensions-overview)",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/extensions/gpuarrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Put every array the call reads on the device, e.g. with `Adapt.adapt(CuArray, r)
Convert floats with [`convert_floats(Float32, r)`](@ref ComposableRecurrences.convert_floats) to run in `Float32`.
A sparse coupling must be a device sparse matrix, best in CSR form, one stratum's row per kernel index.
A CSC or other device sparse coupling is converted to CSR when the recurrence is built, through the array package's own conversion.
A form the package cannot convert is kept as given and runs through the package's own sparse products.
A form the array package cannot convert is an `ArgumentError` that names its type.
Adapting a built recurrence moves its coupling by the array package's own rules, without this conversion, so a host sparse coupling may arrive as CSC or dense.
To take the CSR kernel, build the recurrence with its coupling already on the device.
A device CSR coupling takes the package's rule, as a dense one does; another device sparse form takes plain AD.
A device CSR coupling takes the package's rule, as a dense one does; a coupling that adapting leaves in another sparse form takes plain AD.
JLArrays stands in for a GPU here; CUDA, AMDGPU and Metal arrays work the same way.

```jldoctest gpu
Expand Down
1 change: 1 addition & 0 deletions docs/src/performance/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ performance_summary("transform") # hide

The tables read `benchmark/results/docs.csv`, so the docs build times nothing.
Each example is a case in `test/ADFixtures/src/matrix_cases.jl`, timed at the docs tier, and `task -t benchmark/Taskfile.yml matrix-docs` regenerates the file.
The [full benchmark grid](https://github.com/EpiAware/ComposableRecurrences.jl/tree/benchmarks/full) is timed weekly on `main` and published with its commit and date.
11 changes: 9 additions & 2 deletions ext/ComposableRecurrencesGPUArraysExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,18 @@ end
# A device CSR coupling gives each stratum its own row, so the rows run as
# one loop with no shared writes. Another device sparse form is converted
# to CSR when the recurrence is built, through the array package's own
# conversion.
# conversion, and a form with no such conversion is refused.
CR._stored_coupling(C::AbstractGPUSparseMatrixCSR) = C
function CR._stored_coupling(C::AbstractGPUSparseMatrix)
T = typeof(C)
return hasmethod(csr_type, Tuple{Type{T}}) ? csr_type(T)(C) : C
hasmethod(csr_type, Tuple{Type{T}}) || throw(
ArgumentError(
"a device sparse coupling of type $(nameof(T)) has no " *
"conversion to CSR form; convert it to the device's CSR " *
"sparse matrix before building the recurrence"
)
)
return csr_type(T)(C)
end
function CR.forward!(
C::AbstractGPUSparseMatrixCSR, ::Pressure, q::AnyGPUArray, p, t
Expand Down
5 changes: 0 additions & 5 deletions test/item_times.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
0.6 Adjoint: the local step without `ForwardDiff` says to load it
0.2 Adjoint: the local step's dual numbers compare by value
2.1 Adjoint: the plain-AD note logs at construction only
1.8 Adjoint: the read and array steps' helpers, called directly
17.8 Adjoint: threaded reverse pass with outputs read and routes
0.6 Adjoint: time-varying dense coupling pullback with every mirror
0.3 Adjoint: user operators declare their adjoint
Expand Down Expand Up @@ -214,7 +213,6 @@
1.2 Device: arrays on a device select it
1.0 Discrete delays: a step sums whole lags
1.3 Discrete delays: gradients reach the parameters on a step
36.7 Docstring examples run
0.0 EXECUTOR: serial by default, set per block
9.4 Eltypes: Float32 in, Float32 out
15.7 Eltypes: ForwardDiff gradients through every slot
Expand Down Expand Up @@ -345,7 +343,6 @@
2.2 Show: each summary is inferred as a String
2.1 Show: one-line summaries
0.9 Standards: README and page prose
0.6 Standards: README code is from the getting started page
0.5 Standards: README example prints nothing on the home page
1.1 Standards: docstring examples
0.8 Standards: docstring maths
Expand All @@ -371,7 +368,6 @@
15.6 Trace: a trace written in each step under other executors
2.2 Trace: a trace written in each step with a short or long history
2.7 Trace: each flow's amount against a naive loop
139.2 Trace: gradients through a trace and the default trace of user modifiers, the rule against ForwardDiff
22.2 Trace: gradients through the pressure, the rule against ForwardDiff
0.9 Trace: state with a trace written in each step
7.6 Trace: the default is the state after the step
Expand All @@ -391,7 +387,6 @@
2.0 Transform: ForwardDiff through a recurrence
2.2 Transform: a map carrying parameters is differentiated whole
8.2 Transform: a map of each value against a naive loop
0.7 Transform: a supplied derivative replaces the local one
0.2 Transform: argument validation
0.2 Transform: local derivative helpers called directly
3.9 Transform: per-stratum parameters
Expand Down
12 changes: 3 additions & 9 deletions test/unit/device_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1311,18 +1311,18 @@ end

@testitem "JLArrays: a device sparse coupling runs as CSR, and a CSC one is converted where it can be" setup = [DeviceRules] begin
using SparseArrays: SparseArrays, sparse
using GPUArrays: AbstractGPUSparseMatrixCOO, csr_type
using GPUArrays: csr_type
S = 4
C = sparse([0.0 0.1 0.0 0.2; 0.3 0.0 0.0 0.0; 0.0 0.2 0.0 0.1; 0.1 0.0 0.4 0.0])
x, h = inputs(S), fill(1.0, S, L)
y0 = Recurrence(pmf; coupling = C)(x; history = h)
for (name, Cd) in (
"CSR" => JLSparseMatrixCSR(C), "CSC" => JLSparseMatrixCSC(C),
)
# Older JLArrays give a CSC matrix no `csr_type`, so it is kept.
# Older JLArrays give a CSC matrix no `csr_type`, so it is refused.
Comment thread
seabbs-bot marked this conversation as resolved.
Resolved
if !(Cd isa JLSparseMatrixCSR) &&
!hasmethod(csr_type, Tuple{Type{typeof(Cd)}})
@test Recurrence(JLArray(pmf); coupling = Cd).coupling === Cd
@test_throws ArgumentError Recurrence(JLArray(pmf); coupling = Cd)
continue
end
r = Recurrence(JLArray(pmf); coupling = Cd)
Expand All @@ -1332,12 +1332,6 @@ end
@test y1 isa JLArray
@test Array(y1) ≈ y0
end
# A device sparse form with no conversion to CSR is kept as given.
# JLArrays has no such form, so a stub with no `csr_type` stands in.
struct NoCSRStub <: AbstractGPUSparseMatrixCOO{Float64, Int} end
Base.size(::NoCSRStub) = (S, S)
stub = NoCSRStub()
@test Recurrence(JLArray(pmf); coupling = stub).coupling === stub
end

@testitem "JLArrays: the rule passes of a CSR coupling match the CPU" setup = [DeviceRules] begin
Expand Down
21 changes: 21 additions & 0 deletions test/unit/gpu_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,27 @@ end
@test_throws "is a host array" r(x; history = h)
end

@testitem "JLArrays: a device sparse coupling with no conversion to CSR is an error" begin
using ComposableRecurrences, JLArrays
using GPUArrays: AbstractGPUSparseMatrixBSR, AbstractGPUSparseMatrixCOO
# JLArrays has only CSC and CSR device sparse matrices, so stubs with no
# `csr_type` stand in for the COO and BSR forms of a GPU array package.
struct StubSparseCOO <: AbstractGPUSparseMatrixCOO{Float64, Int} end
struct StubSparseBSR <: AbstractGPUSparseMatrixBSR{Float64, Int} end
Base.size(::Union{StubSparseCOO, StubSparseBSR}) = (2, 2)
g = JLArray([0.5, 0.5])
for C in (StubSparseCOO(), StubSparseBSR())
err = try
Recurrence(g; coupling = C)
catch e
e
end
@test err isa ArgumentError
@test occursin(string(nameof(typeof(C))), err.msg)
@test occursin("CSR", err.msg)
end
end

@testitem "JLArrays: coefficients from change points refuse a device" begin
using ComposableRecurrences, JLArrays, Adapt
using ComposableRecurrences: Transform, Primary
Expand Down
Loading