Skip to content

Commit

Permalink
Merge pull request #1300 from AayushSabharwal/as/callables-fix
Browse files Browse the repository at this point in the history
fix: handle CallWithMetadata in var_from_nested_derivative
  • Loading branch information
ChrisRackauckas authored Oct 11, 2024
2 parents 6271c8b + ac511a2 commit af8a07c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- Core
- Downstream
- GroebnerExt
- SymPy
version:
- '1'
steps:
Expand Down
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ ForwardDiff = "0.10.36"
Groebner = "0.5, 0.6, 0.7"
IfElse = "0.1"
LaTeXStrings = "1.3"
LambertW = "1.0.0"
Latexify = "0.16"
LogExpFunctions = "0.3"
Lux = "1"
Expand Down Expand Up @@ -101,15 +102,15 @@ ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
LambertW = "984bce1d-4616-540c-a9ee-88d1112d94c9"
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "SymPy", "Random", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities"]
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "Random", "LambertW", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities"]
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ end

function var_from_nested_derivative(x,i=0)
x = unwrap(x)
if issym(x)
if issym(x) || x isa CallWithMetadata
(x, i)
elseif iscall(x)
operation(x) isa Differential ?
Expand Down
11 changes: 10 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ function activate_downstream_env()
Pkg.instantiate()
end

function activate_sympy_env()
Pkg.activate("sympy")
Pkg.develop(PackageSpec(path=dirname(@__DIR__)))
Pkg.instantiate()
end

if haskey(ENV, "BENCHMARK_ONLY")
include("benchmark.jl")
end
Expand Down Expand Up @@ -45,7 +51,6 @@ if GROUP == "All" || GROUP == "Core"
VERSION >= v"1.9" && @safetestset "Build Targets Test" begin include("build_targets.jl") end
@safetestset "Latexify Test" begin include("latexify.jl") end
@safetestset "Domain Test" begin include("domains.jl") end
@safetestset "SymPy Test" begin include("sympy.jl") end
@safetestset "Inequality Test" begin include("inequality.jl") end
@safetestset "Integral Test" begin include("integral.jl") end
@safetestset "CartesianIndex Test" begin include("cartesianindex.jl") end
Expand Down Expand Up @@ -80,3 +85,7 @@ if GROUP == "All" || GROUP == "Downstream"
@safetestset "ModelingToolkit Variable Utils Test" begin include("downstream/modeling_toolkit_utils.jl") end
end

if GROUP == "All" || GROUP == "SymPy"
activate_sympy_env()
@safetestset "SymPy Test" begin include("sympy.jl") end
end
3 changes: 3 additions & 0 deletions test/sympy/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
SymPy = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
11 changes: 10 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Symbolics
using Symbolics: symbolic_to_float
using Symbolics: symbolic_to_float, var_from_nested_derivative

@testset "get_variables" begin
@variables t x y z(t)
Expand Down Expand Up @@ -29,3 +29,12 @@ end
@test symbolic_to_float((big(1)//2)*√(279//4)) isa BigFloat
@test symbolic_to_float((-1//2)*√(279//4)) isa Float64
end

@testset "var_from_nested_derivative" begin
@variables t x(t) p(..)
D = Differential(t)
@test var_from_nested_derivative(x) == (x, 0)
@test var_from_nested_derivative(D(x)) == (x, 1)
@test var_from_nested_derivative(p) == (p, 0)
@test var_from_nested_derivative(D(p(x))) == (p(x), 1)
end

0 comments on commit af8a07c

Please sign in to comment.