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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ADTypes"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
authors = ["Vaibhav Dixit <[email protected]>, Guillaume Dalle and contributors"]
version = "1.17.0"
version = "1.18.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
7 changes: 7 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ ADTypes.symmetric_coloring
ADTypes.NoColoringAlgorithm
```

## No automatic differentiation

```@docs
NoAutoDiff
NoAutoDiffSelectedError
```

## Modes

```@docs
Expand Down
4 changes: 3 additions & 1 deletion src/ADTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export AutoChainRules,
AutoTapir,
AutoTaylorDiff,
AutoTracker,
AutoZygote
AutoZygote,
NoAutoDiff,
NoAutoDiffSelectedError
@public AbstractMode
@public ForwardMode, ReverseMode, ForwardOrReverseMode, SymbolicMode
@public mode
Expand Down
32 changes: 32 additions & 0 deletions src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,35 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
struct AutoZygote <: AbstractADType end

mode(::AutoZygote) = ReverseMode()

"""
NoAutoDiff

Struct used to select no automatic differentiation.

Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).

# Constructors

NoAutoDiff()
"""
struct NoAutoDiff <: AbstractADType end

"""
NoAutoDiffSelectedError <: Exception

Signifies that code tried to use automatic differentiation, but [`NoAutoDiff`](@ref) was specified.

# Constructor

NoAutoDiffSelectedError(msg::String)
"""
struct NoAutoDiffSelectedError <: Exception
msg::String
end

NoAutoDiffSelectedError() = NoAutoDiffSelectedError("Automatic differentiation can not be used with NoAutoDiff()")

function mode(::NoAutoDiff)
throw(NoAutoDiffSelectedError())
end
3 changes: 3 additions & 0 deletions src/symbols.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
ADTypes.Auto(package::Symbol)
ADTypes.Auto(nothing)::NoAutoDiff

A shortcut that converts an AD package name into an instance of [`AbstractADType`](@ref), with all parameters set to their default values.

Expand Down Expand Up @@ -27,3 +28,5 @@ for backend in (:ChainRules, :Diffractor, :Enzyme, :FastDifferentiation,
@eval Auto(::Val{$(QuoteNode(backend))}, args...; kws...) = $(Symbol(:Auto, backend))(
args...; kws...)
end

Auto(::Nothing) = NoAutoDiff()
7 changes: 7 additions & 0 deletions test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,10 @@ end
@test ad isa AutoZygote
@test mode(ad) isa ReverseMode
end

@testset "NoAutoDiff" begin
ad = NoAutoDiff()
@test ad isa AbstractADType
@test ad isa NoAutoDiff
@test_throws NoAutoDiffSelectedError mode(ad)
end
1 change: 1 addition & 0 deletions test/symbols.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using Test
@test ADTypes.Auto(:Tapir) isa AutoTapir
@test ADTypes.Auto(:Tracker) isa AutoTracker
@test ADTypes.Auto(:Zygote) isa AutoZygote
@test ADTypes.Auto(nothing) isa NoAutoDiff

@test_throws MethodError ADTypes.Auto(:ThisPackageDoesNotExist)
@test_throws UndefKeywordError ADTypes.Auto(:ChainRules)
Expand Down
Loading