diff --git a/.buildkite/Manifest-v1.11.toml b/.buildkite/Manifest-v1.11.toml index 4b61a724a2..f045a203bf 100644 --- a/.buildkite/Manifest-v1.11.toml +++ b/.buildkite/Manifest-v1.11.toml @@ -1,8 +1,8 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.11.5" +julia_version = "1.11.3" manifest_format = "2.0" -project_hash = "04945e2a7116cfacb2d57340f477dbe23e208227" +project_hash = "a25db2ac38461b28c1b3a6176008dee03780354b" [[deps.ADTypes]] git-tree-sha1 = "be7ae030256b8ef14a441726c4c37766b90b93a3" @@ -1818,7 +1818,7 @@ version = "2.5.4+0" [[deps.OpenLibm_jll]] deps = ["Artifacts", "Libdl"] uuid = "05823500-19ac-5b8b-9628-191a04bc5112" -version = "0.8.5+0" +version = "0.8.1+2" [[deps.OpenMPI_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Hwloc_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "MPIPreferences", "TOML", "Zlib_jll"] @@ -2539,8 +2539,10 @@ uuid = "b718987f-49a8-5099-9789-dcd902bef87d" version = "1.0.2" [[deps.Thermodynamics]] -deps = ["DocStringExtensions", "KernelAbstractions", "Random", "RootSolvers"] -git-tree-sha1 = "bff801ad0a9bbb5c1bf38ffe89a83907a1b145cd" +deps = ["DocStringExtensions", "ForwardDiff", "KernelAbstractions", "Random", "RootSolvers"] +git-tree-sha1 = "1c6b10882d535f28b5c79be9d8d782a12f5592f9" +repo-rev = "zs/test_autodiff" +repo-url = "https://github.com/CliMA/Thermodynamics.jl.git" uuid = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c" version = "0.12.15" weakdeps = ["ClimaParams"] diff --git a/.buildkite/Project.toml b/.buildkite/Project.toml index 613c15fcb9..f6d0fca812 100644 --- a/.buildkite/Project.toml +++ b/.buildkite/Project.toml @@ -38,6 +38,7 @@ SnoopCompileCore = "e2b509da-e806-4183-be48-004708413034" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c" YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [compat] diff --git a/src/prognostic_equations/implicit/autodiff_utils.jl b/src/prognostic_equations/implicit/autodiff_utils.jl index 17300215ea..93bee59afc 100644 --- a/src/prognostic_equations/implicit/autodiff_utils.jl +++ b/src/prognostic_equations/implicit/autodiff_utils.jl @@ -143,6 +143,29 @@ end return ForwardDiff.dual_definition_retval(tag, val, deriv, partials) end +# Set the derivative of max(x, y) to handle cases where x == y. When x == y, +# the derivative is set to the derivative of x (the first argument) to ensure +# continuity and avoid numerical issues. This is a common approach in automatic +# differentiation for max functions. + +@inline function Base.max(d::ForwardDiff.Dual{Jacobian}, r::Integer) + tag = Val(Jacobian) + x = ForwardDiff.value(d) + partials = ForwardDiff.partials(d) + val = max(x, r) + deriv = 1 + return ForwardDiff.dual_definition_retval(tag, val, deriv, partials) +end + +# @inline function Base.clamp(d::ForwardDiff.Dual{Jacobian}, r1::FT, r2::FT) where {FT} +# tag = Val(Jacobian) +# x = ForwardDiff.value(d) +# partials = ForwardDiff.partials(d) +# val = clamp(x, r1, r2) +# deriv = 1 +# return ForwardDiff.dual_definition_retval(tag, val, deriv, partials) +# end + # Ignore all derivative information when comparing Duals to other Numbers. This # ensures that conditional statements are always equivalent for Duals and Reals. for func in (:iszero,)