From a4891d636441ac79986b79683e1791da0df44280 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:37:05 -0400 Subject: [PATCH 1/7] Remove Tricks Tricks are for kids! (and since Julia 1.10, `static_hasmethod` is just `hasmethod`) --- src/differentiation/common.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/differentiation/common.jl b/src/differentiation/common.jl index 83fb438b..e1c04b3f 100644 --- a/src/differentiation/common.jl +++ b/src/differentiation/common.jl @@ -49,8 +49,8 @@ function JacFunctionWrapper(f::F, fu_, u, p, t; if deporder # Check this first else we were breaking things # In the next breaking release, we will fix the ordering of the checks - iip = static_hasmethod(f, typeof((fu, u))) - oop = static_hasmethod(f, typeof((u,))) + iip = hasmethod(f, typeof((fu, u))) + oop = hasmethod(f, typeof((u,))) if iip || oop if p !== nothing || t !== nothing Base.depwarn( @@ -74,8 +74,8 @@ function JacFunctionWrapper(f::F, fu_, u, p, t; end if t !== nothing - iip = static_hasmethod(f, typeof((fu, u, p, t))) - oop = static_hasmethod(f, typeof((u, p, t))) + iip = hasmethod(f, typeof((fu, u, p, t))) + oop = hasmethod(f, typeof((u, p, t))) if !iip && !oop throw(ArgumentError("""`p` and `t` provided but `f(u, p, t)` or `f(fu, u, p, t)` not defined for `f`!""")) @@ -83,8 +83,8 @@ function JacFunctionWrapper(f::F, fu_, u, p, t; return JacFunctionWrapper{iip, oop, 1, F, typeof(fu), typeof(p), typeof(t)}(f, fu, p, t) elseif p !== nothing - iip = static_hasmethod(f, typeof((fu, u, p))) - oop = static_hasmethod(f, typeof((u, p))) + iip = hasmethod(f, typeof((fu, u, p))) + oop = hasmethod(f, typeof((u, p))) if !iip && !oop throw(ArgumentError("""`p` is provided but `f(u, p)` or `f(fu, u, p)` not defined for `f`!""")) @@ -94,8 +94,8 @@ function JacFunctionWrapper(f::F, fu_, u, p, t; end if !deporder - iip = static_hasmethod(f, typeof((fu, u))) - oop = static_hasmethod(f, typeof((u,))) + iip = hasmethod(f, typeof((fu, u))) + oop = hasmethod(f, typeof((u,))) if !iip && !oop throw(ArgumentError("""`p` is provided but `f(u)` or `f(fu, u)` not defined for `f`!""")) From 572c9609bbf51094f3c13862152f8488c78f516a Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:38:03 -0400 Subject: [PATCH 2/7] remove Tricks --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index b1848a75..79256bed 100644 --- a/Project.toml +++ b/Project.toml @@ -24,7 +24,6 @@ Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" StaticArrayInterface = "0d7ed370-da01-4f52-bd93-41d350b8b718" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" -Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775" UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" VertexSafeGraphs = "19fa3120-7c27-5ec5-8db8-b0b0aa330d6f" From f1b7fe1cb6a2d624895318f64f30e9ce38500298 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:38:29 -0400 Subject: [PATCH 3/7] remove tricks --- src/SparseDiffTools.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SparseDiffTools.jl b/src/SparseDiffTools.jl index c7d3d979..b985abd1 100644 --- a/src/SparseDiffTools.jl +++ b/src/SparseDiffTools.jl @@ -22,7 +22,6 @@ using SciMLOperators, LinearAlgebra, Random import DataStructures: DisjointSets, find_root!, union! import SciMLOperators: update_coefficients, update_coefficients! import Setfield: @set! -import Tricks: Tricks, static_hasmethod import PackageExtensionCompat: @require_extensions function __init__() From edb18e94a05f4a2eaa004edd245f7df7f32fcaf6 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:39:18 -0400 Subject: [PATCH 4/7] remove tricks --- ext/SparseDiffToolsZygoteExt.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/SparseDiffToolsZygoteExt.jl b/ext/SparseDiffToolsZygoteExt.jl index 9f7d491a..4d5a3efd 100644 --- a/ext/SparseDiffToolsZygoteExt.jl +++ b/ext/SparseDiffToolsZygoteExt.jl @@ -5,7 +5,6 @@ import SparseDiffTools: SparseDiffTools, DeivVecTag, AutoDiffVJP, __test_backend import ForwardDiff: ForwardDiff, Dual, partials import SciMLOperators: update_coefficients, update_coefficients! import Setfield: @set! -import Tricks: static_hasmethod import SparseDiffTools: numback_hesvec!, numback_hesvec, autoback_hesvec!, autoback_hesvec, auto_vecjac!, @@ -101,7 +100,7 @@ end # VJP methods function auto_vecjac!(du, f::F, x, v) where {F} - !static_hasmethod(f, typeof((x,))) && + !hasmethod(f, typeof((x,))) && error("For inplace function use autodiff = AutoFiniteDiff()") du .= reshape(SparseDiffTools.auto_vecjac(f, x, v), size(du)) end @@ -113,7 +112,7 @@ end # overload operator interface function SparseDiffTools._vecjac(f::F, _, u, autodiff::AutoZygote) where {F} - !static_hasmethod(f, typeof((u,))) && + !hasmethod(f, typeof((u,))) && error("For inplace function use autodiff = AutoFiniteDiff()") pullback = Zygote.pullback(f, u) return AutoDiffVJP(f, u, (), autodiff, pullback) From 3cb5cbcc31adebf61634d1a92023d6da2ccdeb18 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:40:27 -0400 Subject: [PATCH 5/7] remove tricks --- src/differentiation/jaches_products.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/differentiation/jaches_products.jl b/src/differentiation/jaches_products.jl index fcc85a87..04c00917 100644 --- a/src/differentiation/jaches_products.jl +++ b/src/differentiation/jaches_products.jl @@ -212,7 +212,7 @@ function (L::FwdModeAutoDiffVecProd)(dv, v, p, t) end function Base.resize!(L::FwdModeAutoDiffVecProd, n::Integer) - static_hasmethod(resize!, typeof((L.f, n))) && resize!(L.f, n) + hasmethod(resize!, typeof((L.f, n))) && resize!(L.f, n) resize!(L.u, n) for v in L.cache @@ -304,7 +304,7 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing; (cache1, cache2, cache3), numauto_hesvec, numauto_hesvec! elseif autodiff isa AutoZygote - @assert static_hasmethod(autoback_hesvec, typeof((f, u, u))) "To use AutoZygote() AD, first load Zygote with `using Zygote`, or `import Zygote`" + @assert hasmethod(autoback_hesvec, typeof((f, u, u))) "To use AutoZygote() AD, first load Zygote with `using Zygote`, or `import Zygote`" cache1 = Dual{ typeof(ForwardDiff.Tag(tag, eltype(u))), eltype(u), 1 @@ -316,8 +316,8 @@ function HesVec(f, u::AbstractArray, p = nothing, t = nothing; error("Set autodiff to either AutoForwardDiff(), AutoZygote(), or AutoFiniteDiff()") end - outofplace = static_hasmethod(f, typeof((u,))) - isinplace = static_hasmethod(f, typeof((u,))) + outofplace = hasmethod(f, typeof((u,))) + isinplace = hasmethod(f, typeof((u,))) if !(isinplace) & !(outofplace) error("$f must have signature f(u).") @@ -347,8 +347,8 @@ function HesVecGrad(f, u::AbstractArray, p = nothing, t = nothing; error("Set autodiff to either AutoForwardDiff(), or AutoFiniteDiff()") end - outofplace = static_hasmethod(f, typeof((u,))) - isinplace = static_hasmethod(f, typeof((u, u))) + outofplace = hasmethod(f, typeof((u,))) + isinplace = hasmethod(f, typeof((u, u))) if !(isinplace) & !(outofplace) error("$f must have signature f(u), or f(du, u).") From db174cb6be8d81838e22f93a76a2e202d6ff98d5 Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:41:08 -0400 Subject: [PATCH 6/7] remove tricks --- src/differentiation/vecjac_products.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/differentiation/vecjac_products.jl b/src/differentiation/vecjac_products.jl index 4113e655..8ab0039b 100644 --- a/src/differentiation/vecjac_products.jl +++ b/src/differentiation/vecjac_products.jl @@ -152,7 +152,7 @@ function (L::AutoDiffVJP{<:AutoFiniteDiff})(dv, v, p, t; VJP_input = nothing) end function Base.resize!(L::AutoDiffVJP, n::Integer) - static_hasmethod(resize!, typeof((L.f, n))) && resize!(L.f, n) + hasmethod(resize!, typeof((L.f, n))) && resize!(L.f, n) resize!(L.u, n) for v in L.cache resize!(v, n) From 4601a5152320135da659f275cdad952865354a6e Mon Sep 17 00:00:00 2001 From: Oscar Smith Date: Wed, 9 Oct 2024 17:48:40 -0400 Subject: [PATCH 7/7] remove Tricks --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 79256bed..ec89a8b7 100644 --- a/Project.toml +++ b/Project.toml @@ -63,7 +63,6 @@ SparseArrays = "<0.0.1, 1" StaticArrayInterface = "1.3" StaticArrays = "1" Symbolics = "5.5, 6" -Tricks = "0.1.6" UnPack = "1" VertexSafeGraphs = "0.2" Zygote = "0.6"