Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion DifferentiationInterface/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.7.0]

### Changed

- Preparation is now strict by default ([#799])
- New Arxiv preprint for citation ([#795])

## [0.6.54] - 2025-05-11
Expand All @@ -24,10 +27,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Allocate Enzyme shadow memory during preparation ([#782])

[unreleased]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.54...main
[unreleased]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.7.0...main
[0.7.0]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.54...DifferentiationInterface-v0.7.0
[0.6.54]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.53...DifferentiationInterface-v0.6.54
[0.6.53]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterface-v0.6.52...DifferentiationInterface-v0.6.53

[#799]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/799
[#795]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/795
[#790]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/790
[#788]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/788
Expand Down
2 changes: 1 addition & 1 deletion DifferentiationInterface/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DifferentiationInterface"
uuid = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
authors = ["Guillaume Dalle", "Adrian Hill"]
version = "0.6.54"
version = "0.7.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
3 changes: 2 additions & 1 deletion DifferentiationInterface/src/docstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function docstring_prepare(operator; samepoint=false, inplace=false)
Otherwise, preparation becomes invalid and you need to run it again.
In some settings, invalid preparations may still give correct results (e.g. for backends that require no preparation), but this is not a semantic guarantee and should not be relied upon.

When `strict=Val(true)`, type checking is enforced between preparation and execution (but size checking is left to the user).
When `strict=Val(true)` (the default), type checking is enforced between preparation and execution (but size checking is left to the user).
While your code may work for different types by setting `strict=Val(false)`, this is not guaranteed by the API and can break without warning.
"""
end

Expand Down
16 changes: 5 additions & 11 deletions DifferentiationInterface/src/first_order/derivative.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
## Docstrings

"""
prepare_derivative(f, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_derivative(f!, y, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_derivative(f, backend, x, [contexts...]; strict=Val(true)) -> prep
prepare_derivative(f!, y, backend, x, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("derivative"; inplace=true))
"""
function prepare_derivative(
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(false)
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_derivative_nokwarg(strict, f, backend, x, contexts...)
end

function prepare_derivative(
f!::F,
y,
backend::AbstractADType,
x,
contexts::Vararg{Context,C};
strict::Val=Val(false),
f!::F, y, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_derivative_nokwarg(strict, f!, y, backend, x, contexts...)
end
Expand All @@ -42,8 +37,7 @@ function prepare!_derivative(
old_prep::DerivativePrep,
backend::AbstractADType,
x,
contexts::Vararg{Context,C};
strict::Val=Val(false),
contexts::Vararg{Context,C},
) where {F,C}
check_prep(f!, y, old_prep, backend, x, contexts...)
return prepare_derivative_nokwarg(is_strict(old_prep), f!, y, backend, x, contexts...)
Expand Down
4 changes: 2 additions & 2 deletions DifferentiationInterface/src/first_order/gradient.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Docstrings

"""
prepare_gradient(f, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_gradient(f, backend, x, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("gradient"))
"""
function prepare_gradient(
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(false)
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_gradient_nokwarg(strict, f, backend, x, contexts...)
end
Expand Down
14 changes: 4 additions & 10 deletions DifferentiationInterface/src/first_order/jacobian.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
## Docstrings

"""
prepare_jacobian(f, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_jacobian(f!, y, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_jacobian(f, backend, x, [contexts...]; strict=Val(true)) -> prep
prepare_jacobian(f!, y, backend, x, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("jacobian"; inplace=true))
"""
function prepare_jacobian(
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(false)
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_jacobian_nokwarg(strict, f, backend, x, contexts...)
end

function prepare_jacobian(
f!::F,
y,
backend::AbstractADType,
x,
contexts::Vararg{Context,C};
strict::Val=Val(false),
f!::F, y, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_jacobian_nokwarg(strict, f!, y, backend, x, contexts...)
end
Expand All @@ -43,7 +38,6 @@ function prepare!_jacobian(
backend::AbstractADType,
x,
contexts::Vararg{Context,C};
strict::Val=Val(false),
) where {F,C}
check_prep(f!, y, old_prep, backend, x, contexts...)
return prepare_jacobian_nokwarg(is_strict(old_prep), f!, y, backend, x, contexts...)
Expand Down
16 changes: 8 additions & 8 deletions DifferentiationInterface/src/first_order/pullback.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Docstrings

"""
prepare_pullback(f, backend, x, ty, [contexts...]; strict=Val(false)) -> prep
prepare_pullback(f!, y, backend, x, ty, [contexts...]; strict=Val(false)) -> prep
prepare_pullback(f, backend, x, ty, [contexts...]; strict=Val(true)) -> prep
prepare_pullback(f!, y, backend, x, ty, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("pullback"; inplace=true))
"""
Expand All @@ -12,7 +12,7 @@ function prepare_pullback(
x,
ty::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pullback_nokwarg(strict, f, backend, x, ty, contexts...)
end
Expand All @@ -24,7 +24,7 @@ function prepare_pullback(
x,
ty::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pullback_nokwarg(strict, f!, y, backend, x, ty, contexts...)
end
Expand Down Expand Up @@ -61,8 +61,8 @@ function prepare!_pullback(
end

"""
prepare_pullback_same_point(f, backend, x, ty, [contexts...]; strict=Val(false)) -> prep_same
prepare_pullback_same_point(f!, y, backend, x, ty, [contexts...]; strict=Val(false)) -> prep_same
prepare_pullback_same_point(f, backend, x, ty, [contexts...]; strict=Val(true)) -> prep_same
prepare_pullback_same_point(f!, y, backend, x, ty, [contexts...]; strict=Val(true)) -> prep_same

$(docstring_prepare("pullback"; samepoint=true, inplace=true))
"""
Expand All @@ -72,7 +72,7 @@ function prepare_pullback_same_point(
x,
ty::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pullback_same_point_nokwarg(strict, f, backend, x, ty, contexts...)
end
Expand All @@ -84,7 +84,7 @@ function prepare_pullback_same_point(
x,
ty::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pullback_same_point_nokwarg(strict, f!, y, backend, x, ty, contexts...)
end
Expand Down
16 changes: 8 additions & 8 deletions DifferentiationInterface/src/first_order/pushforward.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Docstrings

"""
prepare_pushforward(f, backend, x, tx, [contexts...]; strict=Val(false)) -> prep
prepare_pushforward(f!, y, backend, x, tx, [contexts...]; strict=Val(false)) -> prep
prepare_pushforward(f, backend, x, tx, [contexts...]; strict=Val(true)) -> prep
prepare_pushforward(f!, y, backend, x, tx, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("pushforward"; inplace=true))
"""
Expand All @@ -12,7 +12,7 @@ function prepare_pushforward(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pushforward_nokwarg(strict, f, backend, x, tx, contexts...)
end
Expand All @@ -24,7 +24,7 @@ function prepare_pushforward(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pushforward_nokwarg(strict, f!, y, backend, x, tx, contexts...)
end
Expand Down Expand Up @@ -63,8 +63,8 @@ function prepare!_pushforward(
end

"""
prepare_pushforward_same_point(f, backend, x, tx, [contexts...]; strict=Val(false)) -> prep_same
prepare_pushforward_same_point(f!, y, backend, x, tx, [contexts...]; strict=Val(false)) -> prep_same
prepare_pushforward_same_point(f, backend, x, tx, [contexts...]; strict=Val(true)) -> prep_same
prepare_pushforward_same_point(f!, y, backend, x, tx, [contexts...]; strict=Val(true)) -> prep_same

$(docstring_prepare("pushforward"; samepoint=true, inplace=true))
"""
Expand All @@ -74,7 +74,7 @@ function prepare_pushforward_same_point(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pushforward_same_point_nokwarg(strict, f, backend, x, tx, contexts...)
end
Expand All @@ -86,7 +86,7 @@ function prepare_pushforward_same_point(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_pushforward_same_point_nokwarg(
strict, f!, y, backend, x, tx, contexts...
Expand Down
4 changes: 2 additions & 2 deletions DifferentiationInterface/src/second_order/hessian.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Docstrings

"""
prepare_hessian(f, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_hessian(f, backend, x, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("hessian"))
"""
function prepare_hessian(
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(false)
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_hessian_nokwarg(strict, f, backend, x, contexts...)
end
Expand Down
8 changes: 4 additions & 4 deletions DifferentiationInterface/src/second_order/hvp.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Docstrings

"""
prepare_hvp(f, backend, x, tx, [contexts...]; strict=Val(false)) -> prep
prepare_hvp(f, backend, x, tx, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("hvp"))
"""
Expand All @@ -11,7 +11,7 @@ function prepare_hvp(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_hvp_nokwarg(strict, f, backend, x, tx, contexts...)
end
Expand All @@ -34,7 +34,7 @@ function prepare!_hvp(
end

"""
prepare_hvp_same_point(f, backend, x, tx, [contexts...]; strict=Val(false)) -> prep_same
prepare_hvp_same_point(f, backend, x, tx, [contexts...]; strict=Val(true)) -> prep_same

$(docstring_prepare("hvp"; samepoint=true))
"""
Expand All @@ -44,7 +44,7 @@ function prepare_hvp_same_point(
x,
tx::NTuple,
contexts::Vararg{Context,C};
strict::Val=Val(false),
strict::Val=Val(true),
) where {F,C}
return prepare_hvp_same_point_nokwarg(strict, f, backend, x, tx, contexts...)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
## Docstrings

"""
prepare_second_derivative(f, backend, x, [contexts...]; strict=Val(false)) -> prep
prepare_second_derivative(f, backend, x, [contexts...]; strict=Val(true)) -> prep

$(docstring_prepare("second_derivative"))
"""
function prepare_second_derivative(
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(false)
f::F, backend::AbstractADType, x, contexts::Vararg{Context,C}; strict::Val=Val(true)
) where {F,C}
return prepare_second_derivative_nokwarg(strict, f, backend, x, contexts...)
end
Expand Down
8 changes: 4 additions & 4 deletions DifferentiationInterface/test/Core/Internals/signature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ y = zeros(2)
c = 2.0

@testset "Out of place, no tangents" begin
prep = prepare_derivative(f, backend, x, Constant(c); strict=Val(true))
prep = prepare_derivative(f, backend, x, Constant(c))
prep_chill = prepare_derivative(f, backend, x, Constant(c); strict=Val(false))

@test_throws MethodError derivative(nothing, prep_chill, backend, x, Constant(c))
Expand Down Expand Up @@ -68,7 +68,7 @@ c = 2.0
end

@testset "In place, no tangents" begin
prep = prepare_derivative(f!, y, backend, x; strict=Val(true))
prep = prepare_derivative(f!, y, backend, x)
prep_chill = prepare_derivative(f!, y, backend, x; strict=Val(false))

@test_throws MethodError derivative(nothing, y, prep_chill, backend, x, Constant(c))
Expand All @@ -86,7 +86,7 @@ end
end

@testset "Out of place, with tangents" begin
prep = prepare_pushforward(f, backend, x, (x,), Constant(c); strict=Val(true))
prep = prepare_pushforward(f, backend, x, (x,), Constant(c))
prep_chill = prepare_pushforward(f, backend, x, (x,), Constant(c); strict=Val(false))

@test_throws MethodError pushforward(nothing, prep_chill, backend, x, (x,))
Expand All @@ -104,7 +104,7 @@ end
end

@testset "In place, with tangents" begin
prep = prepare_pushforward(f!, y, backend, x, (x,); strict=Val(true))
prep = prepare_pushforward(f!, y, backend, x, (x,))
prep_chill = prepare_pushforward(
f!, y, backend, x, (x,), Constant(c); strict=Val(false)
)
Expand Down
5 changes: 4 additions & 1 deletion DifferentiationInterfaceTest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.10.0]

### Changed

- Specify preparation arguments in DIT Scenario ([#786])
Expand All @@ -23,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support nested tuples of arrays as Caches ([#748])
- Test type consistency between preparation and execution ([#745])

[unreleased]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterfaceTest-v0.9.6...main
[unreleased]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterfaceTest-v0.10.0...main
[0.10.0]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterfaceTest-v0.9.6...DifferentiationInterfaceTest-v0.10.0
[0.9.6]: https://github.com/JuliaDiff/DifferentiationInterface.jl/compare/DifferentiationInterfaceTest-v0.9.5...DifferentiationInterfaceTest-v0.9.6

[#796]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/796
Expand Down
4 changes: 2 additions & 2 deletions DifferentiationInterfaceTest/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DifferentiationInterfaceTest"
uuid = "a82114a7-5aa3-49a8-9643-716bb13727a3"
authors = ["Guillaume Dalle", "Adrian Hill"]
version = "0.10.0"
version = "0.10.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -44,7 +44,7 @@ AllocCheck = "0.2"
Chairmarks = "1.2.1"
ComponentArrays = "0.15"
DataFrames = "1.6.1"
DifferentiationInterface = "0.6.53"
DifferentiationInterface = "0.7.0"
DocStringExtensions = "0.8,0.9"
ExplicitImports = "1.10.1"
FiniteDiff = "2.27.0"
Expand Down
Loading