diff --git a/docs/src/index.md b/docs/src/index.md index c47b4a7..2655c51 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -54,6 +54,7 @@ AutoZygote AutoEnzyme AutoChainRules AutoDiffractor +AutoPiste ``` ### Forward, reverse, or sparse mode diff --git a/src/ADTypes.jl b/src/ADTypes.jl index 6e09893..4b6b1a1 100644 --- a/src/ADTypes.jl +++ b/src/ADTypes.jl @@ -48,6 +48,7 @@ export AutoChainRules, AutoModelingToolkit, AutoMooncake, AutoMooncakeForward, + AutoPiste, AutoPolyesterForwardDiff, AutoReverseDiff, AutoSymbolics, diff --git a/src/dense.jl b/src/dense.jl index e5e5697..1f5b0b0 100644 --- a/src/dense.jl +++ b/src/dense.jl @@ -384,6 +384,43 @@ function Base.show(io::IO, backend::AutoMooncakeForward) return print(io, ")") end +""" + AutoPiste{M,chunksize} + +Struct used to select the [Piste.jl](https://github.com/EvoArt/Piste.jl) backend for automatic differentiation. + +Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl). + +# Constructors + + AutoPiste(; mode=ForwardMode(), chunksize=nothing) + +# Type parameters + + - `chunksize`: the number of partials carried per forward pass (forward mode only), either `nothing` or an `Int`. + Pass an explicit value when compiling with `juliac --trim`, so that the width is known statically. + +# Fields + + - `mode::M`: either [`ForwardMode()`](@ref ForwardMode) (dual numbers) or [`ReverseMode()`](@ref ReverseMode) (a tape). +""" +struct AutoPiste{M <: Union{ForwardMode, ReverseMode}, chunksize} <: AbstractADType + mode::M +end + +function AutoPiste(; mode::M = ForwardMode(), chunksize = nothing) where {M} + return AutoPiste{M, _unwrap_val(chunksize)}(mode) +end + +mode(backend::AutoPiste) = backend.mode + +function Base.show(io::IO, backend::AutoPiste{M, chunksize}) where {M, chunksize} + print(io, AutoPiste, "(") + print(io, "mode=", repr(backend.mode; context = io)) + chunksize !== nothing && print(io, ", chunksize=", repr(chunksize; context = io)) + return print(io, ")") +end + """ AutoPolyesterForwardDiff{chunksize,T} diff --git a/src/symbols.jl b/src/symbols.jl index afa5a22..137bbc1 100644 --- a/src/symbols.jl +++ b/src/symbols.jl @@ -24,7 +24,7 @@ Auto(package::Symbol, args...; kws...) = Auto(Val(package), args...; kws...) for backend in ( :ChainRules, :Diffractor, :Enzyme, :Reactant, :FastDifferentiation, - :FiniteDiff, :FiniteDifferences, :ForwardDiff, :GTPSA, :HyperHessians, :Mooncake, + :FiniteDiff, :FiniteDifferences, :ForwardDiff, :GTPSA, :HyperHessians, :Mooncake, :Piste, :PolyesterForwardDiff, :ReverseDiff, :Symbolics, :Tapir, :TaylorDiff, :Tracker, :Zygote, ) @eval Auto(::Val{$(QuoteNode(backend))}, args...; kws...) = $(Symbol(:Auto, backend))( diff --git a/test/dense.jl b/test/dense.jl index aa27f8d..6dd9258 100644 --- a/test/dense.jl +++ b/test/dense.jl @@ -203,6 +203,26 @@ end @test ad.config === nothing end +@testset "AutoPiste" begin + ad = AutoPiste() + @test ad isa AbstractADType + @test ad isa AutoPiste{ForwardMode, nothing} + @test mode(ad) isa ForwardMode + + ad = AutoPiste(; chunksize = 4) + @test ad isa AutoPiste{ForwardMode, 4} + @test mode(ad) isa ForwardMode + + ad = AutoPiste(; chunksize = Val(4)) + @test ad isa AutoPiste{ForwardMode, 4} + + ad = AutoPiste(; mode = ReverseMode()) + @test ad isa AutoPiste{ReverseMode, nothing} + @test mode(ad) isa ReverseMode + + @test_throws TypeError AutoPiste(; mode = SymbolicMode()) +end + @testset "AutoPolyesterForwardDiff" begin ad = AutoPolyesterForwardDiff() @test ad isa AbstractADType diff --git a/test/misc.jl b/test/misc.jl index b160589..9057bb6 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -48,6 +48,9 @@ for backend in [ ADTypes.AutoMooncake(; config = :config), ADTypes.AutoMooncakeForward(), ADTypes.AutoMooncakeForward(; config = :config), + ADTypes.AutoPiste(), + ADTypes.AutoPiste(; mode = ADTypes.ReverseMode()), + ADTypes.AutoPiste(; chunksize = 4), ADTypes.AutoPolyesterForwardDiff(), ADTypes.AutoPolyesterForwardDiff(chunksize = 3, tag = :tag), ADTypes.AutoReverseDiff(), diff --git a/test/symbols.jl b/test/symbols.jl index 5d121f0..d00a9e7 100644 --- a/test/symbols.jl +++ b/test/symbols.jl @@ -10,6 +10,7 @@ using Test @test ADTypes.Auto(:ForwardDiff) isa AutoForwardDiff @test ADTypes.Auto(:HyperHessians) isa AutoHyperHessians @test ADTypes.Auto(:Mooncake) isa AutoMooncake +@test ADTypes.Auto(:Piste) isa AutoPiste @test ADTypes.Auto(:PolyesterForwardDiff) isa AutoPolyesterForwardDiff @test ADTypes.Auto(:ReverseDiff) isa AutoReverseDiff @test ADTypes.Auto(:Reactant) isa AutoReactant