Skip to content

Commit

Permalink
Check if config is nothing before accessing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
penelopeysm committed Oct 3, 2024
1 parent 942eead commit 5107c11
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Mooncake"
uuid = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.4.5"
version = "0.4.6"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
6 changes: 5 additions & 1 deletion ext/MooncakeLogDensityProblemsADExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ function logdensity_and_gradient(∇l::MooncakeGradientLogDensity, x::Vector{Flo
end

# Interop with ADTypes.
function getconfig(x::ADTypes.AutoMooncake)
c = x.config
isnothing(c) ? Mooncake.DEFAULT_CONFIG : c
end
function ADgradient(x::ADTypes.AutoMooncake, ℓ)
debug_mode = x.config.debug_mode
debug_mode = getconfig(x).debug_mode
if debug_mode
msg = "Running Mooncake in debug mode. This mode is computationally expensive, " *
"should only be used when debugging a problem with AD, and turned off in " *
Expand Down
2 changes: 2 additions & 0 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Configuration struct for use with ADTypes.AutoMooncake.
debug_mode::Bool=false
silence_debug_messages::Bool=false
end

const DEFAULT_CONFIG = Config()
4 changes: 2 additions & 2 deletions test/config.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@testset "config" begin
@test !Mooncake.Config().debug_mode
@test !Mooncake.Config().silence_debug_messages
@test !Mooncake.DEFAULT_CONFIG.debug_mode
@test !Mooncake.DEFAULT_CONFIG.silence_debug_messages
end

0 comments on commit 5107c11

Please sign in to comment.