From 84eb6799d8c0713fdb43a027d0feae1957a0347c Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 01:25:35 -0500 Subject: [PATCH 1/6] Remove unnecessary utility functions --- src/ModelingToolkit.jl | 1 - src/equations.jl | 1 - src/operations.jl | 16 ---------------- src/systems/diffeqs/first_order_transform.jl | 6 +----- src/utils.jl | 6 ------ 5 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index d3e5651681..933b85ffc5 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -15,7 +15,6 @@ include("variables.jl") Base.promote_rule(::Type{T},::Type{T2}) where {T<:Number,T2<:Expression} = Expression Base.zero(::Type{<:Expression}) = Constant(0) Base.one(::Type{<:Expression}) = Constant(1) -Base.convert(::Type{Variable},x::Int64) = Constant(x) function caclulate_jacobian end diff --git a/src/equations.jl b/src/equations.jl index 41a7051c4e..5163e606fa 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -5,7 +5,6 @@ struct Equation lhs::Expression rhs::Expression end -Base.broadcastable(eq::Equation) = Ref(eq) Base.:(==)(a::Equation, b::Equation) = (a.lhs, a.rhs) == (b.lhs, b.rhs) Base.:~(lhs::Expression, rhs::Expression) = Equation(lhs, rhs) diff --git a/src/operations.jl b/src/operations.jl index 9880f7ef33..ad307d0760 100644 --- a/src/operations.jl +++ b/src/operations.jl @@ -19,22 +19,6 @@ Base.convert(::Type{Expr}, O::Operation) = build_expr(:call, Any[Symbol(O.op); convert.(Expr, O.args)]) Base.show(io::IO, O::Operation) = print(io, convert(Expr, O)) - -""" -find_replace(O::Operation, x::Expression, y::Expression) - -Finds the expression `x` in Operation `O` and replaces it with the Expression `y` -""" -function find_replace!(O::Operation, x::Expression, y::Expression) - for i in eachindex(O.args) - if isequal(O.args[i], x) - O.args[i] = y - elseif typeof(O.args[i]) <: Operation - find_replace!(O.args[i],x,y) - end - end -end - # For inv Base.convert(::Type{Operation}, x::Number) = Operation(identity, Expression[Constant(x)]) Base.convert(::Type{Operation}, x::Operation) = x diff --git a/src/systems/diffeqs/first_order_transform.jl b/src/systems/diffeqs/first_order_transform.jl index 277dbd202e..aa3f1d6255 100644 --- a/src/systems/diffeqs/first_order_transform.jl +++ b/src/systems/diffeqs/first_order_transform.jl @@ -1,5 +1,3 @@ -extract_idv(eq::DiffEq) = eq.D.x - function lower_varname(D::Differential, x; lower=false) order = lower ? D.order-1 : D.order return lower_varname(x, D.x, order) @@ -21,7 +19,7 @@ function ode_order_lowering(eqs, iv) new_eqs = similar(eqs, DiffEq) for (i, eq) ∈ enumerate(eqs) - var, maxorder = extract_var_order(eq) + var, maxorder = eq.var, eq.D.order maxorder == 1 && continue # fast pass if maxorder > get(var_order, var, 0) var_order[var] = maxorder @@ -51,6 +49,4 @@ function rename(O::Expression) return Operation(O.op, rename.(O.args)) end -extract_var_order(eq::DiffEq) = (eq.var, eq.D.order) - export ode_order_lowering diff --git a/src/utils.jl b/src/utils.jl index 744a91f4e2..2ca78afc09 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -17,7 +17,6 @@ function build_expr(head::Symbol, args) append!(ex.args, args) ex end -expr_arr_to_block(exprs) = build_expr(:block, exprs) # used in parsing isblock(x) = length(x) == 1 && x[1] isa Expr && x[1].head == :block @@ -31,11 +30,6 @@ function flatten_expr!(x) x end -function partition(f, xs) - idxs = map(f, xs) - return (xs[idxs], xs[(!).(idxs)]) -end - is_constant(::Constant) = true is_constant(::Any) = false From 50c65ad382d851f6edef20257612255fb2681234 Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 01:27:23 -0500 Subject: [PATCH 2/6] Various cleanup --- src/ModelingToolkit.jl | 19 +++++++++++-------- src/operations.jl | 3 +-- src/systems/systems.jl | 30 ------------------------------ src/utils.jl | 24 ++++++++++++++++++++++++ test/derivatives.jl | 2 +- test/system_construction.jl | 8 ++++---- 6 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 src/systems/systems.jl diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index 933b85ffc5..5c519c743c 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -7,23 +7,23 @@ using MacroTools import MacroTools: splitdef, combinedef abstract type Expression <: Number end -abstract type AbstractOperation <: Expression end -abstract type AbstractComponent <: Expression end +abstract type AbstractComponent end +abstract type AbstractSystem end -include("variables.jl") - -Base.promote_rule(::Type{T},::Type{T2}) where {T<:Number,T2<:Expression} = Expression +Base.promote_rule(::Type{<:Number},::Type{<:Expression}) = Expression Base.zero(::Type{<:Expression}) = Constant(0) Base.one(::Type{<:Expression}) = Constant(1) -function caclulate_jacobian end +function calculate_jacobian end +function generate_jacobian end +function generate_function end @enum FunctionVersion ArrayFunction=1 SArrayFunction=2 +include("variables.jl") include("operations.jl") include("differentials.jl") include("equations.jl") -include("systems/systems.jl") include("systems/diffeqs/diffeqsystem.jl") include("systems/diffeqs/first_order_transform.jl") include("systems/nonlinear/nonlinear_system.jl") @@ -31,6 +31,9 @@ include("function_registration.jl") include("simplify.jl") include("utils.jl") -export Operation, Expression, AbstractComponent, AbstractDomain +export Operation, Expression, AbstractComponent +export calculate_jacobian, generate_jacobian, generate_function +export ArrayFunction, SArrayFunction export @register + end # module diff --git a/src/operations.jl b/src/operations.jl index ad307d0760..f024b848e3 100644 --- a/src/operations.jl +++ b/src/operations.jl @@ -1,5 +1,4 @@ -# Parameterize by T so that way it can be Vector{Expression} which is defined after -struct Operation <: AbstractOperation +struct Operation <: Expression op::Function args::Vector{Expression} end diff --git a/src/systems/systems.jl b/src/systems/systems.jl deleted file mode 100644 index 6d8b1b4f0c..0000000000 --- a/src/systems/systems.jl +++ /dev/null @@ -1,30 +0,0 @@ -export generate_jacobian, generate_function - - -abstract type AbstractSystem end - -function generate_jacobian end -function generate_function end - -function build_function(rhss, vs, ps, args = (); version::FunctionVersion) - var_pairs = [(u.name, :(u[$i])) for (i, u) ∈ enumerate(vs)] - param_pairs = [(p.name, :(p[$i])) for (i, p) ∈ enumerate(ps)] - (ls, rs) = zip(var_pairs..., param_pairs...) - - var_eqs = Expr(:(=), build_expr(:tuple, ls), build_expr(:tuple, rs)) - - if version === ArrayFunction - X = gensym() - sys_exprs = [:($X[$i] = $(convert(Expr, rhs))) for (i, rhs) ∈ enumerate(rhss)] - let_expr = Expr(:let, var_eqs, build_expr(:block, sys_exprs)) - :(($X,u,p,$(args...)) -> $let_expr) - elseif version === SArrayFunction - sys_expr = build_expr(:tuple, [convert(Expr, rhs) for rhs ∈ rhss]) - let_expr = Expr(:let, var_eqs, sys_expr) - :((u,p,$(args...)) -> begin - X = $let_expr - T = StaticArrays.similar_type(typeof(u), eltype(X)) - T(X) - end) - end -end diff --git a/src/utils.jl b/src/utils.jl index 2ca78afc09..d9f2935c5d 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -30,6 +30,30 @@ function flatten_expr!(x) x end +function build_function(rhss, vs, ps, args = (); version::FunctionVersion) + var_pairs = [(u.name, :(u[$i])) for (i, u) ∈ enumerate(vs)] + param_pairs = [(p.name, :(p[$i])) for (i, p) ∈ enumerate(ps)] + (ls, rs) = zip(var_pairs..., param_pairs...) + + var_eqs = Expr(:(=), build_expr(:tuple, ls), build_expr(:tuple, rs)) + + if version === ArrayFunction + X = gensym() + sys_exprs = [:($X[$i] = $(convert(Expr, rhs))) for (i, rhs) ∈ enumerate(rhss)] + let_expr = Expr(:let, var_eqs, build_expr(:block, sys_exprs)) + :(($X,u,p,$(args...)) -> $let_expr) + elseif version === SArrayFunction + sys_expr = build_expr(:tuple, [convert(Expr, rhs) for rhs ∈ rhss]) + let_expr = Expr(:let, var_eqs, sys_expr) + :((u,p,$(args...)) -> begin + X = $let_expr + T = StaticArrays.similar_type(typeof(u), eltype(X)) + T(X) + end) + end +end + + is_constant(::Constant) = true is_constant(::Any) = false diff --git a/test/derivatives.jl b/test/derivatives.jl index 2ff68f6b09..2f960b9edd 100644 --- a/test/derivatives.jl +++ b/test/derivatives.jl @@ -25,7 +25,7 @@ eqs = [0 ~ σ*(y-x), 0 ~ x*(ρ-z)-y, 0 ~ x*y - β*z] sys = NonlinearSystem(eqs,[x,y,z],[σ,ρ,β]) -jac = ModelingToolkit.calculate_jacobian(sys) +jac = calculate_jacobian(sys) @test jac[1,1] == σ*-1 @test jac[1,2] == σ @test jac[1,3] == 0 diff --git a/test/system_construction.jl b/test/system_construction.jl index 6225f6f43a..7fa89c2a08 100644 --- a/test/system_construction.jl +++ b/test/system_construction.jl @@ -14,7 +14,7 @@ de = DiffEqSystem(eqs,t,[x,y,z],[σ,ρ,β]) generate_function(de) generate_function(de;version=ModelingToolkit.SArrayFunction) jac_expr = generate_jacobian(de) -jac = ModelingToolkit.calculate_jacobian(de) +jac = calculate_jacobian(de) f = ODEFunction(de) ModelingToolkit.generate_ode_iW(de) @@ -67,7 +67,7 @@ eqs = [D(x) ~ σ*a, D(z) ~ x*y - β*z] de = DiffEqSystem(eqs,t,[x,y,z],[σ,ρ,β]) generate_function(de) -jac = ModelingToolkit.calculate_jacobian(de) +jac = calculate_jacobian(de) f = ODEFunction(de) # Define a nonlinear system @@ -108,7 +108,7 @@ eqs = [0 ~ σ*(y-x), 0 ~ x*(ρ-z)-y, 0 ~ x*y - β*z] ns = NonlinearSystem(eqs, [x,y,z], [σ,ρ,β]) -jac = ModelingToolkit.calculate_jacobian(ns) +jac = calculate_jacobian(ns) @testset "nlsys jacobian" begin @test jac[1,1] == σ * -1 @test jac[1,2] == σ @@ -131,5 +131,5 @@ eqs = [0 ~ σ*a, 0 ~ x*y - β*z] ns = NonlinearSystem(eqs,[x,y,z],[σ,ρ,β]) nlsys_func = generate_function(ns) -jac = ModelingToolkit.calculate_jacobian(ns) +jac = calculate_jacobian(ns) jac = generate_jacobian(ns) From 285e5825818ced16ed5b4dab791988aa11222a49 Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 01:30:07 -0500 Subject: [PATCH 3/6] Remove internal tests Only user-facing API should be tested. --- test/internal.jl | 19 ------------------- test/runtests.jl | 1 - 2 files changed, 20 deletions(-) delete mode 100644 test/internal.jl diff --git a/test/internal.jl b/test/internal.jl deleted file mode 100644 index 94c77a9a51..0000000000 --- a/test/internal.jl +++ /dev/null @@ -1,19 +0,0 @@ -using ModelingToolkit -using Test - -# `Expr`, `Number` -> `Operation` -@Param a -@Param b -@Unknown x(t) y() -@test convert(Expression, 2) == 2 -expr = :(-inv(2sqrt(+($a, $b)))) -op = Operation(-, [Operation(inv, - [Operation(*, [2, Operation(sqrt, - [Operation(+, [a, b])])])])]) -@test convert(Expression, expr) == op -expr1 = :($x^($y-1)) -op1 = Operation(^, [x, Operation(-, [y, 1])]) -@test convert(Expression, expr1) == op1 - -@test_throws ArgumentError convert(Expression, :([a, b])) -@test_throws ArgumentError convert(Expression, :(a ? b : c)) diff --git a/test/runtests.jl b/test/runtests.jl index c7954083bf..90bf45439e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,6 @@ using ModelingToolkit, Test @testset "Parsing Test" begin include("variable_parsing.jl") end @testset "Basic Variables and Operations" begin include("basic_variables_and_operations.jl") end @testset "Differentiation Test" begin include("derivatives.jl") end -@testset "Internal Test" begin include("internal.jl") end @testset "Simplify Test" begin include("simplify.jl") end @testset "Ambiguity Test" begin include("ambiguity.jl") end @testset "Components Test" begin include("components.jl") end From 7dcd418ccd5f64372bba7b0be30d712b32eef676 Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 01:43:03 -0500 Subject: [PATCH 4/6] Replace Variable subtype with known --- README.md | 10 +++++----- src/equations.jl | 7 ++++--- src/systems/diffeqs/first_order_transform.jl | 2 +- src/systems/nonlinear/nonlinear_system.jl | 2 +- src/variables.jl | 21 ++++++++++++-------- test/basic_variables_and_operations.jl | 2 +- test/variable_parsing.jl | 6 +++--- 7 files changed, 28 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f5d08b3548..2073663147 100644 --- a/README.md +++ b/README.md @@ -136,8 +136,8 @@ context-aware single variable of the IR. Its fields are described as follows: - `name`: the name of the `Variable`. Note that this is not necessarily the same as the name of the Julia variable. But this symbol itself is considered the core identifier of the `Variable` in the sense of equality. -- `subtype`: the main denotation of context. Variables within systems - are grouped according to their `subtype`. +- `known`: the main denotation of context, storing whether or not the value of + the variable is known. - `dependents`: the vector of variables on which the current variable is dependent. For example, `u(t,x)` has dependents `[t,x]`. Derivatives thus require this information in order to simplify down. @@ -252,9 +252,9 @@ is syntactic sugar for: ```julia t = Parameter(:t) -x = Unknown(:x, dependents = [t]) -y = Unknown(:y, dependents = [t]) -z = Unknown(:z, dependents = [t]) +x = Unknown(:x, [t]) +y = Unknown(:y, [t]) +z = Unknown(:z, [t]) D = Differential(t) σ = Parameter(:σ) ρ = Parameter(:ρ) diff --git a/src/equations.jl b/src/equations.jl index 5163e606fa..e721eb70f9 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -12,9 +12,10 @@ Base.:~(lhs::Expression, rhs::Number ) = Equation(lhs, rhs) Base.:~(lhs::Number , rhs::Expression) = Equation(lhs, rhs) -_is_dependent(x::Variable) = x.subtype === :Unknown && !isempty(x.dependents) -_is_parameter(iv) = x -> x.subtype === :Parameter && x ≠ iv -_subtype(subtype::Symbol) = x -> x.subtype === subtype +_is_dependent(x::Variable) = !x.known && !isempty(x.dependents) +_is_parameter(iv) = x -> x.known && x ≠ iv +_is_known(x::Variable) = x.known +_is_unknown(x::Variable) = !x.known function extract_elements(eqs, predicates) result = [Variable[] for p ∈ predicates] diff --git a/src/systems/diffeqs/first_order_transform.jl b/src/systems/diffeqs/first_order_transform.jl index aa3f1d6255..b2ed598195 100644 --- a/src/systems/diffeqs/first_order_transform.jl +++ b/src/systems/diffeqs/first_order_transform.jl @@ -5,7 +5,7 @@ end function lower_varname(var::Variable, idv, order::Int) sym = var.name name = order == 0 ? sym : Symbol(sym, :_, string(idv.name)^order) - return Variable(name, var.subtype, var.dependents) + return Variable(name, var.known, var.dependents) end function ode_order_lowering(sys::DiffEqSystem) diff --git a/src/systems/nonlinear/nonlinear_system.jl b/src/systems/nonlinear/nonlinear_system.jl index a855e90f2f..ce8c0da00f 100644 --- a/src/systems/nonlinear/nonlinear_system.jl +++ b/src/systems/nonlinear/nonlinear_system.jl @@ -18,7 +18,7 @@ struct NonlinearSystem <: AbstractSystem end function NonlinearSystem(eqs) - vs, ps = extract_elements(eqs, [_subtype(:Unknown), _subtype(:Parameter)]) + vs, ps = extract_elements(eqs, [_is_unknown, _is_known]) NonlinearSystem(eqs, vs, ps) end diff --git a/src/variables.jl b/src/variables.jl index e96b857760..473a35409b 100644 --- a/src/variables.jl +++ b/src/variables.jl @@ -3,12 +3,12 @@ export Variable, Unknown, Parameter, @Unknown, @Param struct Variable <: Expression name::Symbol - subtype::Symbol + known::Bool dependents::Vector{Variable} end -Parameter(name; dependents = Variable[]) = Variable(name, :Parameter, dependents) -Unknown(name; dependents = Variable[]) = Variable(name, :Unknown, dependents) +Parameter(name, dependents = Variable[]) = Variable(name, true, dependents) +Unknown(name, dependents = Variable[]) = Variable(name, false, dependents) struct Constant <: Expression @@ -22,7 +22,7 @@ Base.isone(ex::Expression) = isa(ex, Constant) && isone(ex.value) # Variables use isequal for equality since == is an Operation -Base.:(==)(x::Variable, y::Variable) = (x.name, x.subtype) == (y.name, y.subtype) +Base.:(==)(x::Variable, y::Variable) = (x.name, x.known) == (y.name, y.known) Base.:(==)(::Variable, ::Number) = false Base.:(==)(::Number, ::Variable) = false Base.:(==)(::Variable, ::Constant) = false @@ -32,13 +32,18 @@ Base.:(==)(n::Number, c::Constant) = c.value == n Base.:(==)(a::Constant, b::Constant) = a.value == b.value function Base.convert(::Type{Expr}, x::Variable) - x.subtype === :Parameter || return x.name - isempty(x.dependents) && return x.name + x.known || return x.name + isempty(x.dependents) && return x.name return :($(x.name)($(convert.(Expr, x.dependents)...))) end Base.convert(::Type{Expr}, c::Constant) = c.value -Base.show(io::IO, x::Variable) = print(io, x.subtype, '(', x.name, ')') +function Base.show(io::IO, x::Variable) + subtype = x.known ? :Parameter : :Unknown + print(io, subtype, '(', repr(x.name)) + isempty(x.dependents) || print(io, ", ", x.dependents) + print(io, ')') +end # Build variables more easily function _parse_vars(macroname, fun, x) @@ -65,7 +70,7 @@ function _parse_vars(macroname, fun, x) end push!(var_names, var_name) - expr = :($var_name = $fun($(Meta.quot(var_name)), dependents = $dependents)) + expr = :($var_name = $fun($(Meta.quot(var_name)), $dependents)) push!(ex.args, expr) end push!(ex.args, build_expr(:tuple, var_names)) diff --git a/test/basic_variables_and_operations.jl b/test/basic_variables_and_operations.jl index f65e9efdb1..3ca9ef871b 100644 --- a/test/basic_variables_and_operations.jl +++ b/test/basic_variables_and_operations.jl @@ -7,7 +7,7 @@ using Test # Default values p = Parameter(:p) -u = Unknown(:u, dependents = [t]) +u = Unknown(:u, [t]) σ*(y-x) D(x) diff --git a/test/variable_parsing.jl b/test/variable_parsing.jl index 9f9bafa65a..95080830a2 100644 --- a/test/variable_parsing.jl +++ b/test/variable_parsing.jl @@ -5,9 +5,9 @@ using Test @Unknown x(t) @Unknown y(t) @Unknown z(t) -x1 = Unknown(:x ,dependents = [t]) -y1 = Unknown(:y ,dependents = [t]) -z1 = Unknown(:z ,dependents = [t]) +x1 = Unknown(:x, [t]) +y1 = Unknown(:y, [t]) +z1 = Unknown(:z, [t]) @test x1 == x @test y1 == y @test z1 == z From 4023dd2d428a398d42c6fb7a18880377db66e1cd Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 01:56:58 -0500 Subject: [PATCH 5/6] Remove Components Will be reintroduced fully in the future. --- src/ModelingToolkit.jl | 1 - test/components.jl | 28 ---------------------------- test/runtests.jl | 1 - 3 files changed, 30 deletions(-) delete mode 100644 test/components.jl diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl index 5c519c743c..56693a3441 100644 --- a/src/ModelingToolkit.jl +++ b/src/ModelingToolkit.jl @@ -7,7 +7,6 @@ using MacroTools import MacroTools: splitdef, combinedef abstract type Expression <: Number end -abstract type AbstractComponent end abstract type AbstractSystem end Base.promote_rule(::Type{<:Number},::Type{<:Expression}) = Expression diff --git a/test/components.jl b/test/components.jl deleted file mode 100644 index bf8bb3151d..0000000000 --- a/test/components.jl +++ /dev/null @@ -1,28 +0,0 @@ -using ModelingToolkit -using Test - -struct Lorenz <: AbstractComponent - x::Variable - y::Variable - z::Variable - σ::Variable - ρ::Variable - β::Variable - eqs::Vector{Equation} -end -function generate_lorenz_eqs(t,x,y,z,σ,ρ,β) - D = Differential(t) - [D(x) ~ σ*(y-x) - D(y) ~ x*(ρ-z)-y - D(z) ~ x*y - β*z] -end -function Lorenz(t) - @Unknown x(t) y(t) z(t) - @Param σ ρ β - Lorenz(x, y, z, σ, ρ, β, generate_lorenz_eqs(t, x, y, z, σ, ρ, β)) -end - -@Param t -lz1 = Lorenz(t) -lz2 = Lorenz(t) -lz1.x ~ lz2.x diff --git a/test/runtests.jl b/test/runtests.jl index 90bf45439e..60a2a2c083 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -5,5 +5,4 @@ using ModelingToolkit, Test @testset "Differentiation Test" begin include("derivatives.jl") end @testset "Simplify Test" begin include("simplify.jl") end @testset "Ambiguity Test" begin include("ambiguity.jl") end -@testset "Components Test" begin include("components.jl") end @testset "System Construction Test" begin include("system_construction.jl") end From 2547a4e341d1072f0ff176ab6554b0ea63fafcb8 Mon Sep 17 00:00:00 2001 From: Harrison Grodin Date: Sun, 3 Feb 2019 02:00:30 -0500 Subject: [PATCH 6/6] Remove unnecessary tests --- test/ambiguity.jl | 11 ----------- test/basic_variables_and_operations.jl | 17 ----------------- test/derivatives.jl | 9 ++++++--- test/runtests.jl | 2 -- 4 files changed, 6 insertions(+), 33 deletions(-) delete mode 100644 test/ambiguity.jl delete mode 100644 test/basic_variables_and_operations.jl diff --git a/test/ambiguity.jl b/test/ambiguity.jl deleted file mode 100644 index 3c461152a2..0000000000 --- a/test/ambiguity.jl +++ /dev/null @@ -1,11 +0,0 @@ -using ModelingToolkit -using Test - -@Param t -@Unknown x(t) y(t) z(t) - -struct __MyType__ end -Base.:~(::__MyType__,::Number) = 2 -Base.:~(::__MyType__,::Any) = 2 -x ~ 2x + y -x ~ 2 diff --git a/test/basic_variables_and_operations.jl b/test/basic_variables_and_operations.jl deleted file mode 100644 index 3ca9ef871b..0000000000 --- a/test/basic_variables_and_operations.jl +++ /dev/null @@ -1,17 +0,0 @@ -using ModelingToolkit -using Test - -@Param t σ ρ β -@Unknown x(t) y(t) z(t) -@Deriv D'~t - -# Default values -p = Parameter(:p) -u = Unknown(:u, [t]) - -σ*(y-x) -D(x) -D(x) ~ -σ*(y-x) -D(y) ~ x*(ρ-z)-sin(y) - -@test D(t) == 1 diff --git a/test/derivatives.jl b/test/derivatives.jl index 2f960b9edd..b9b346311d 100644 --- a/test/derivatives.jl +++ b/test/derivatives.jl @@ -4,11 +4,14 @@ using Test # Derivatives @Param t σ ρ β @Unknown x(t) y(t) z(t) -@Deriv D'~t -dsin = D(sin(t)) -expand_derivatives(dsin) +@Deriv D'~t D2''~t + +@test expand_derivatives(D(t)) == 1 +@test expand_derivatives(D(D(t))) == 0 +dsin = D(sin(t)) @test expand_derivatives(dsin) == cos(t) + dcsch = D(csch(t)) @test expand_derivatives(dcsch) == simplify_constants(coth(t) * csch(t) * -1) diff --git a/test/runtests.jl b/test/runtests.jl index 60a2a2c083..00a80ece02 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,6 @@ using ModelingToolkit, Test @testset "Parsing Test" begin include("variable_parsing.jl") end -@testset "Basic Variables and Operations" begin include("basic_variables_and_operations.jl") end @testset "Differentiation Test" begin include("derivatives.jl") end @testset "Simplify Test" begin include("simplify.jl") end -@testset "Ambiguity Test" begin include("ambiguity.jl") end @testset "System Construction Test" begin include("system_construction.jl") end