From 26fc5118e988aa0e0a56ef2c57d2fec7916c3462 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Mon, 16 Mar 2020 22:04:55 -0400 Subject: [PATCH 1/3] Add diff rule for `one` --- src/differentials.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/differentials.jl b/src/differentials.jl index 4ec39ee81a..7418f19593 100644 --- a/src/differentials.jl +++ b/src/differentials.jl @@ -113,6 +113,7 @@ end derivative(::typeof(+), args::NTuple{N,Any}, ::Val) where {N} = 1 derivative(::typeof(*), args::NTuple{N,Any}, ::Val{i}) where {N,i} = Operation(*, deleteat!(collect(args), i)) +derivative(::typeof(one), args::Tuple{<:Any}, ::Val) = 0 function count_order(x) @assert !(x isa Symbol) "The variable $x must have an order of differentiation that is greater or equal to 1!" From 073e645e8ea6de6968f15d06e892ff8bfae7a662 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Mon, 16 Mar 2020 22:05:15 -0400 Subject: [PATCH 2/3] Add test --- test/derivatives.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/derivatives.jl b/test/derivatives.jl index 6938412188..515bc6ebb8 100644 --- a/test/derivatives.jl +++ b/test/derivatives.jl @@ -72,3 +72,13 @@ isequal(ModelingToolkit.derivative(Operation(+, [x*y, y, z]), 1), 1) Expression[ModelingToolkit.Constant(1) ModelingToolkit.Constant(0) Differential(t)(x) ModelingToolkit.Constant(1) ModelingToolkit.Constant(0) ModelingToolkit.Constant(0)]) + +# issue 252 +@variables beta, alpha, delta +@variables x1, x2, x3 + +# expression +tmp = beta * (alpha * exp(x1) * x2 ^ (alpha - 1) + 1 - delta) / x3 +# derivative w.r.t. x1 and x2 +t1 = ModelingToolkit.gradient(tmp, [x1, x2]) +@test_nowarn ModelingToolkit.gradient(t1[1], [beta]) From 4f523e6d5411a3d516d29ae85f4a2a9db0a85075 Mon Sep 17 00:00:00 2001 From: Yingbo Ma Date: Mon, 16 Mar 2020 22:06:57 -0400 Subject: [PATCH 3/3] New patch release --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1aeb164ae9..8e8a22db62 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ModelingToolkit" uuid = "961ee093-0014-501f-94e3-6117800e7a78" authors = ["Chris Rackauckas "] -version = "1.2.9" +version = "1.2.10" [deps] DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"