Skip to content

Commit

Permalink
Add safe mode (#55)
Browse files Browse the repository at this point in the history
* Add safe mode

* Add test to check that safe mode is on by default

* Bump minor version

* Update test/dense.jl

---------

Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com>
  • Loading branch information
willtebbutt and gdalle authored May 14, 2024
1 parent d749b5a commit 3d4e912
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
authors = [
"Vaibhav Dixit <vaibhavyashdixit@gmail.com>, Guillaume Dalle and contributors",
]
version = "1.1.0"
version = "1.2.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
8 changes: 7 additions & 1 deletion src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ mode(::AutoSymbolics) = SymbolicMode()
Struct used to select the [Tapir.jl](https://github.com/withbayes/Tapir.jl) backend for automatic differentiation.
Exported from [ADTypes.jl](https://github.com/SciML/ADTypes.jl).
# Keyword Arguments
- `safe_mode::Bool`: whether to run additional checks to catch errors early. On by default. Turn off to maximise performance if your code runs correctly.
"""
struct AutoTapir <: AbstractADType end
Base.@kwdef struct AutoTapir <: AbstractADType
safe_mode::Bool = true
end

mode(::AutoTapir) = ReverseMode()

Expand Down
4 changes: 4 additions & 0 deletions test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ end
@test ad isa AbstractADType
@test ad isa AutoTapir
@test mode(ad) isa ReverseMode
@test ad.safe_mode

ad = AutoTapir(; safe_mode=false)
@test !ad.safe_mode
end

@testset "AutoTracker" begin
Expand Down

3 comments on commit 3d4e912

@willtebbutt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdalle could we tag this?

@gdalle
Copy link
Collaborator

@gdalle gdalle commented on 3d4e912 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on it

@gdalle
Copy link
Collaborator

@gdalle gdalle commented on 3d4e912 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.