Commit 10a4182
Part 1 of autograd backend: DifferentiationInterface extention (#158)
* Add DifferentiationInterface extension on top of evaluator interface
Layer the DifferentiationInterface AD extension onto the simplified evaluator
interface introduced on the `evaluators` branch. This is the catch-all path
for any `<:AbstractADType` backend without a native AbstractPPL extension.
- ext/AbstractPPLDifferentiationInterfaceExt.jl: DI-backed `prepare`,
`value_and_gradient!!`, and `value_and_jacobian!!` for vector-input
evaluators. The evaluator is passed as a `DI.Constant` so DynamicPPL-style
problem state stays constant across calls. Compiled `AutoReverseDiff{true}`
takes the one-argument tape path (the `DI.Constant` route would invalidate
the compiled tape across calls). Empty inputs short-circuit before
`DI.prepare_*` since many backends fail on length-zero arrays.
- Project.toml: DifferentiationInterface added as a weakdep with extension
trigger and compat bound.
- test/autograd_tests.jl: shared problem definitions and `run_autograd_tests`
entry point with separate gradient / jacobian / empty-input helpers.
- test/ext/differentiationinterface/: isolated test env using a local
`DummyADType <: AbstractADType` to exercise the catch-all dispatch without
pulling in a real AD package.
- .github/workflows/CI.yml: extend the ext matrix with
`ext/differentiationinterface` alongside the existing
`ext/logdensityproblems`.
- test/run_extras.jl: register the new label.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Inline AD output-shape assertions into the DI extension
The upstream `Simplify Evaluators module after review` commit dropped
`_assert_supported_output` / `_assert_jacobian_output` from
`Evaluators.jl`, expecting the AD-extension PRs that actually call them
to bring them back. Move both helpers into the DI extension, the sole
caller after rebase.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Fold AD output-shape checks into prepare's dispatch
Replace `_assert_supported_output` / `_assert_jacobian_output` with an
`if y isa Number / elseif y isa AbstractVector / else throw` cascade.
The jacobian assertion was unreachable after the scalar branch, and
the supported-output helper had a single call site; inlining the
remaining check as the `else` arm is clearer than two named helpers.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Move AD test cases into package test resources
Expose shared AD backend fixtures through TestResources so extension test environments can reuse the same cases without including files from test/.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Use ForwardDiff in DI extension tests
Exercise the DifferentiationInterface catch-all with a real backend instead of a stub so the extension test covers the integration path used by downstream AD packages.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* Address PR review: simplify AD prepare and move test fixtures to Test extension
Replace `prepare(adtype, problem, x)`'s two-step `prepare` + `VectorEvaluator`
wrap with a single delegated call to `AbstractPPL.prepare(problem, x; check_dims)`,
eliminating a latent double-wrap when `check_dims=false`.
Move `TestResources` (callable problems, test cases, runner) out of `src/` and
into a new `AbstractPPLTestExt` package extension, so `Test` is loaded only when
downstream code opts in. Split the unified `TestCase` into `ValueCase` /
`ErrorCase`, drop the unused `:namedtuple` fixtures, and store the error
operation as a callable instead of a `:call`/`:gradient` symbol.
Flatten the DI extension test file to two `run_testcases(Val(...); ...)` calls.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Fix empty-input gradient arity, advertise LDP capabilities for DI
- value_and_gradient!! / value_and_jacobian!! now check arity before the
length-zero short-circuit, so empty-input vector-valued / scalar-valued
functions surface the correct ArgumentError instead of silently returning
the wrong shape. Uses Val(0) as the cache sentinel for empty inputs.
- New AbstractPPLDifferentiationInterfaceLogDensityProblemsExt advertises
LogDensityOrder{1} for any DI-prepared evaluator, registering the method
in __init__ to side-step extension precompile-visibility constraints.
- Empty-input arity errors and the new capability advertisement are
exercised in the DI test environment, which now also loads LDP.
- Project.toml [compat] alphabetised.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Unify LDP capabilities: Prepared = order 1, bare evaluator = order 0
Drop the triple extension and have AbstractPPLLogDensityProblemsExt
advertise LogDensityOrder{1} for any Prepared{<:Any,<:VectorEvaluator}.
The contract is now uniform: anything from `prepare(adtype, …)` claims
gradient capability; a bare VectorEvaluator from `prepare(problem, x)`
stays at order 0. Backends that don't implement value_and_gradient!! or
that wrap a vector-output function surface a runtime error at call time
rather than via a capability downgrade.
Documents the rule in docs/src/evaluators.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* format
* Skip Aqua persistent_tasks on Julia 1.10; drop dead --project from extras
Aqua's persistent_tasks check spawns a wrapper subprocess that runs
Pkg.precompile() on a package depending on AbstractPPL. On Julia 1.10
this hits "Declaring __precompile__(false) is not allowed in files
that are being precompiled" inside the wrapper's extension precompile
path. The dedicated Ext CI jobs load and exercise every extension on
min Julia and pass, so this is a Julia 1.10 / Aqua interaction, not a
defect in our extensions. Re-enable when min is bumped past 1.10.
The CI extras step also had a redundant --project=. that was overridden
by run_extras.jl's own Pkg.activate; drop it.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Polish evaluator API: public stubs, docstrings, AD-missing hints
- Mark generate_testcases / run_testcases as public (1.11+) so downstream
AD-backend packages can reuse the conformance suite without reaching
into private API.
- Note in the Prepared docstring that the two-arg constructor is for
backends that allocate fresh storage per call.
- Expand the _ad_output_arity error message to call out matrix/tuple
outputs explicitly and recommend flattening.
- Add a MethodError hint on value_and_gradient!! / value_and_jacobian!!
that fires when no AD backend extension is loaded — also surfaces
through LogDensityProblems.logdensity_and_gradient, which delegates
to value_and_gradient!!. Suppressed once any backend registers a
method, where the standard candidate list is more informative.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Update JULIA.md
* Address PR review: drop LDP ext, fix DI gradient/jacobian edges
- Drop AbstractPPLLogDensityProblemsExt and its test launcher; downstream
packages can define LDP methods on `Prepared` directly when needed.
- Add `_check_vector_length` to enforce dim mismatch on
`value_and_gradient!!`/`value_and_jacobian!!` before the `Val(0)`
short-circuit and DI call (matches `VectorEvaluator{true}` behaviour).
- Unify gradient/jacobian DI prep into `_prepare_di(prep, ...)`; the
`AutoReverseDiff{true}` carve-out now also fixes Jacobian tape recording.
- Tidy DI tests: remove LDP block, drop redundant constants and edge cases,
tighten gradient-of-vector-valued case to `ArgumentError`.
- Document prep-time `evaluator(x)` call and reserved `Val{:vector}` /
`Val{:edge}` testcase keys.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Reject integer inputs in DI value_and_{gradient,jacobian}!!
The bare `VectorEvaluator` rejected integer vectors with a clear
`ArgumentError`, but the DI derivative entry points went straight to
DI prep and surfaced an opaque `PreparationMismatchError`. Apply the
same compile-time `T <: Integer` check before dispatching to DI, and
add matching `:edge` testcases.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Add coverage upload to ext job, bump setup-julia and codecov-action versions
* Add regression test for AutoReverseDiff compiled tape no-context path
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Shravan Goswami <shravanngoswamii@gmail.com>1 parent 23fc8c5 commit 10a4182
15 files changed
Lines changed: 406 additions & 141 deletions
File tree
- .github/workflows
- ext
- src
- evaluators
- test
- ext
- differentiationinterface
- logdensityproblems
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
72 | | - | |
| 74 | + | |
73 | 75 | | |
74 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
34 | | - | |
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
31 | | - | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| 45 | + | |
43 | 46 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
This file was deleted.
0 commit comments