Skip to content

Latest commit

 

History

History
190 lines (111 loc) · 12.7 KB

HISTORY.md

File metadata and controls

190 lines (111 loc) · 12.7 KB

0.15.7

set with a with_mutation index optic now mutates an Array or its view in place when the value already has its element type, as for a vector stored into a Vector{Any}; BangBang copied it before.

0.15.6

Reuse gradient output buffers in the DifferentiationInterface extension via value_and_gradient!, including gradient calls on Hessian preparations. Returned gradients alias cache storage, consistent with the existing !! contract.

Widened the OrderedCollections compat bound to 1.8.1, 2 (#192). OrderedCollections 2.0 is a breaking release, but AbstractPPL only constructs OrderedDicts, so none of its removals or behaviour changes apply.

prepare takes scratch::Tuple, storage that a scalar-valued problem with order=1 writes values computed from x into and reads back. Mooncake (both modes) and Enzyme through DifferentiationInterface support it, and ForwardDiff and every other DifferentiationInterface backend reject it. Every slot the problem writes must be written on every call before it is read, and the storage must reach the problem only through scratch, with no aliasing across entries. The DifferentiationInterface compat bound is now 0.6.47, 0.7.

0.15.5

Widened the Mooncake compat bound to 0.5.27, 0.6 (#180). Mooncake 0.6 is a breaking release (forward-mode redesign), but the reverse-mode rule API and the prepared-cache API AbstractPPLMooncakeExt uses (prepare_gradient_cache, prepare_derivative_cache, prepare_hessian_cache, value_and_gradient!!, value_gradient_and_hessian!!, AutoMooncake, AutoMooncakeForward) are unchanged, so the extension works as-is.

0.15.4

value_and_gradient!!, value_and_jacobian!!, and value_gradient_and_hessian!! now accept a context= keyword that overrides, for a single call, the context frozen at prepare — without re-preparing (#167). The default (context=nothing) leaves the hot path unchanged; a Tuple override must match the frozen context's element types and shapes — a type mismatch (or a non-Tuple override) throws an ArgumentError — and reuses the type-keyed cache. Backends that bake context into their prepared state throw an ArgumentError for a non-empty-input override (re-prepare instead): compiled-tape ReverseDiff (AutoReverseDiff(; compile=true)) on all three entry points, and Mooncake's Hessian; Mooncake Jacobian preps are context-free by construction, so only an empty override validates there. Empty input runs no derivative machinery, so no backend rejects an override there (it is still validated).

Fixed a Mooncake reverse-mode correctness bug (Mooncake issue #1238): when a problem function closed over differentiable data (e.g. a model capturing observed data reached through an in-place solve), a reused prepared cache accumulated that captured data's cotangent and returned an incorrect gradient after the first evaluation. The Mooncake extension now closes the function and its context into a NoTangent target, so the captured data carries no cotangent and reuse is correct.

0.15.3

Added the of type system: a self-contained, declarative way to specify the shape, element type, and support of model variables. Construct specifications with the exported of function or the exported @of macro:

using AbstractPPL
s = of(Real, 0, 1)                       # a real in [0, 1]
RegressionParams = @of(
    y = of(Array, Float64, 100), beta = of(Array, Float64, 3), sigma = of(Real, 0, nothing),
)

of-types support rand/zero (drawing or zeroing a value of the declared shape) and size/length (querying the declared shape), and can be flattened to / unflattened from a flat numeric vector. rand accepts an optional AbstractRNG for reproducible draws. flatten returns a vector whose element type is the promotion of the declared leaf types, and unflatten is automatic-differentiation transparent (float leaves take promote_type(declared, eltype(flat)), so ForwardDiff.Dual numbers flow through); both are type-stable. These are narrow methods dispatched on AbstractPPL-owned OfType subtypes. The supporting types (OfType and its subtypes) and the inspection/flatten/unflatten helpers are marked public for downstream use without being exported.

0.15.2

Added AbstractPPLForwardDiffExt, a direct ForwardDiff path for AutoForwardDiff (gradient, Jacobian, Hessian, context, chunk size, custom tag).

0.15.1

Added Hessian support to the AD interface. Pass order=2 to prepare(adtype, problem, x) to build a Hessian-capable evaluator. The new value_gradient_and_hessian!!(prepared, x) then returns (value, gradient, hessian) in a single call. Both the DifferentiationInterface and Mooncake extensions implement this.

order=2 accepts the same context::Tuple and check_dims options as order=1. NamedTuple inputs are not supported with order=2.

The AbstractPPLTestExt conformance harness now provides a :hessian group covering value, gradient and Hessian round-trips, along with an order-mismatch edge case.

0.15.0

Added a new evaluator-preparation interface for AD backends. prepare binds a callable to a sample input, either a vector or a NamedTuple, and returns a Prepared wrapper. value_and_gradient!! and value_and_jacobian!! then compute value-and-derivative pairs from that wrapper. The !! suffix means the returned derivative may alias backend cache storage, so copy it if you need to keep it across calls.

using ADTypes, Mooncake  # or DifferentiationInterface + ForwardDiff
using AbstractPPL: prepare, value_and_gradient!!
prepared = prepare(AutoMooncake(), x -> -0.5 * sum(abs2, x), zeros(3))
val, grad = value_and_gradient!!(prepared, [1.0, 2.0, 3.0])
# val == -7.0; grad == [-1.0, -2.0, -3.0]

Added two AD-backend extensions:

  • AbstractPPLDifferentiationInterfaceExt, supporting DifferentiationInterface backends.
  • AbstractPPLMooncakeExt, supporting AutoMooncake and AutoMooncakeForward.

The new evaluator path supports scalar gradients, vector-output Jacobians, NamedTuple inputs, reusable AD caches, input-shape checks, and constant context arguments via context::Tuple.

AbstractPPLTestExt now provides a small AD conformance harness through generate_testcases and run_testcases, with reserved groups :vector, :namedtuple, :edge, and :cache_reuse.

See docs/src/evaluators.md for the full interface, the check_dims and context::Tuple options, the NamedTuple input path, and extension-author guidance.

0.14.2

Fix string serialisation of VarNames such that the order of keyword arguments is preserved (this was previously guaranteed, but JSON.jl v1.5.0 introduced a change that caused the keyword arguments to always be sorted.)

Minor performance optimisation for AbstractPPL.append_optic.

0.14.1

Export the concretize_top_level function, which concretizes only the indices contained in an AbstractPPL.Index, and does not recurse into child optics.

0.14.0

This release overhauls the VarName type. Much of the external API for traversing and manipulating VarNames (once they have been constructed) has been preserved, but if you use the VarName type directly, there are significant changes.

Internal representation

The optic field of VarName now uses our hand-rolled optic types, which are subtypes of AbstractPPL.AbstractOptic. Previously these were optics from Accessors.jl.

This change was made for two reasons: firstly, it is easier to provide custom behaviour for VarNames as we avoid running into possible type piracy issues, and secondly, the linked-list data structure used in AbstractOptic is easier to work with than Accessors.jl, which used Base.ComposedFunction to represent optic compositions and required a lot of care to avoid a litany of issues with associativity and identity optics (see e.g. JuliaLang/julia#54877).

To construct an optic, the easiest way is to use the @opticof macro, which superficially behaves similarly to Accessors.@optic (for example, you can write @opticof _[1].y.z), but also supports automatic concretization by passing a second parameter (just like @varname).

Concretization

VarNames using 'dynamic' indices, i.e., begin and end, are now instantiated in a 'dynamic' form, meaning that these indices are unresolved. These indices need to be resolved, or concretized, against the actual container. For example, @varname(x[end]) is dynamic, but when concretized against x = randn(3), this becomes @varname(x[3]). This can be done using concretize(varname, x).

The idea of concretization is not new to AbstractPPL. However, there are some differences:

  • Colons are no longer concretized: they always remain as Colons, even after calling concretize.
  • Previously, AbstractPPL would refuse to allow you to construct unconcretized versions of begin and end. This is no longer the case; you can now create such VarNames in their unconcretized forms. This is useful, for example, when indexing into a chain that contains x as a variable-length vector. This change allows you to write chain[@varname(x[end])] without having AbstractPPL throw an error.

Keyword arguments to getindex

VarNames can now be constructed with keyword arguments in Index optics, for example @varname(x[i=1]). This is specifically implemented to support DimensionalData.jl's DimArrays.

Other interface functions

The vsym function (and @vsym) has been removed; you should use getsym(vn) instead.

The Base.get and Accessors.set methods for VarNames have been removed (these were responsible for method ambiguities). Instead of using these methods you can first convert the VarName to an optic using varname_to_optic(vn), and then use the getter and setter methods on the optics.

VarNames cannot be composed with optics now (compose the optics yourself).

The inspace function has been removed. It used to be relevant for Turing's old Gibbs sampler; but now it no longer serves any use.

ConcretizedSlice has been removed (since colons are no longer concretized).

The subsumption interface has been pared down to just a single function, subsumes. All other functions, such as subsumedby, uncomparable, and the Unicode operators, have been removed.

Serialization still works exactly as before. However, you will see differences in the serialization output compared to previous versions, due to the changes in the internal structure.

0.13.6

Fix a missing qualifier in AbstractPPLDistributionsExt.

0.13.5

Implemented a generic varname_leaves and varname_and_value_leaves for other unsupported types.

0.13.4

Added missing methods for subsumes(::IndexLens, ::PropertyLens) and vice versa.

0.13.3

Bumped compatibility for JSON.jl to include v1.

0.13.2

Implemented varname_leaves for LinearAlgebra.Cholesky.

0.13.1

Moved the functions varname_leaves and varname_and_value_leaves to AbstractPPL. They are now part of the public API of AbstractPPL.

0.13.0

Minimum compatibility has been bumped to Julia 1.10.

Added the new functions hasvalue(container::T, ::VarName[, ::Distribution]) and getvalue(container::T, ::VarName[, ::Distribution]), where T is either NamedTuple or AbstractDict{<:VarName}.

These functions check whether a given VarName has a value in the given NamedTuple or AbstractDict, and return the value if it exists.

The optional Distribution argument allows one to reconstruct a full value from its component indices. For example, if container has x[1] and x[2], then hasvalue(container, @varname(x), dist) will return true if size(dist) == (2,) (for example, MvNormal(zeros(2), I)). In this case plain hasvalue(container, @varname(x)) would return false, since we can not know whether the vector-valued variable x has all of its elements specified in container (there might be an x[3] missing).

These functions (without the Distribution argument) were previously in DynamicPPL.jl (albeit unexported).

0.12.0

VarName constructors

Removed the constructors VarName(vn, optic) (this wasn't deprecated, but was dangerous as it would silently discard the existing optic in vn), and VarName(vn, ::Tuple) (which was deprecated).

Usage of VarName(vn, optic) can be directly replaced with VarName{getsym(vn)}(optic).

Optic normalisation

In the inner constructor of a VarName, its optic is now normalised to ensure that the associativity of ComposedFunction is always the same, and that compositions with identity are removed. This helps to prevent subtle bugs where VarNames with semantically equal optics are not considered equal.

0.11.0

Added the prefix(vn::VarName, vn_prefix::VarName) and unprefix(vn::VarName, vn_prefix::VarName) functions.