Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate "safe_mode" in favour of "debug_mode" for Tapir.jl #75

Closed
wants to merge 6 commits into from
Closed
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
Expand Up @@ -3,7 +3,7 @@ uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
authors = [
"Vaibhav Dixit <vaibhavyashdixit@gmail.com>, Guillaume Dalle and contributors",
]
version = "1.6.1"
version = "1.6.2"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
40 changes: 35 additions & 5 deletions src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,27 +331,57 @@ Defined by [ADTypes.jl](https://github.com/SciML/ADTypes.jl).

# Constructors

AutoTapir(; safe_mode=true)
AutoTapir(; debug_mode::Bool)

# Fields

- `safe_mode::Bool`: whether to run additional checks to catch errors early. While this is
- `safe_mode::Bool`: (to be renamed to `debug_mode` in the next breaking release)
whether to run additional checks to catch errors early. While this is
on by default to ensure that users are aware of this option, you should generally turn
it off for actual use, as it has substantial performance implications.
If you encounter a problem with using Tapir (it fails to differentiate a function, or
something truly nasty like a segfault occurs), then you should try switching `safe_mode`
on and look at what happens. Often errors are caught earlier and the error messages are
more useful.
"""
Base.@kwdef struct AutoTapir <: AbstractADType
safe_mode::Bool = true
struct AutoTapir <: AbstractADType
safe_mode::Bool
end

# This is a really awkward function to deprecate, because Julia does not dispatch on kwargs.
function AutoTapir(;
debug_mode::Union{Bool, Nothing}=nothing, safe_mode::Union{Bool, Nothing}=nothing
)
if debug_mode !== nothing && safe_mode !== nothing
throw(ArgumentError(
"Both `debug_mode` and `safe_mode` have been set. Please only set `debug_mode`."
))
end

if safe_mode !== nothing
Base.depwarn(
"AutoTapir(; safe_mode) is deprecated, use AutoTapir(; debug_mode) instead.",
((Base.Core).Typeof(AutoTapir)).name.mt.name,
)
return AutoTapir(safe_mode)
end

if debug_mode === nothing
Base.depwarn(
"AutoTapir() is deprecated, use AutoTapir(; debug_mode=true) instead.",
((Base.Core).Typeof(AutoTapir)).name.mt.name,
)
return AutoTapir(true)
else
return AutoTapir(debug_mode)
end
end

mode(::AutoTapir) = ReverseMode()

function Base.show(io::IO, backend::AutoTapir)
print(io, AutoTapir, "(")
!(backend.safe_mode) && print(io, "safe_mode=false")
!(backend.safe_mode) && print(io, "debug_mode=false")
print(io, ")")
end

Expand Down
5 changes: 5 additions & 0 deletions test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ end

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

# Check that new interface works as intended.
@test_throws ArgumentError AutoTapir(; debug_mode=false, safe_mode=true)
@test !AutoTapir(; debug_mode=false).safe_mode
@test AutoTapir(; debug_mode=true).safe_mode
end

@testset "AutoTracker" begin
Expand Down
Loading