Skip to content

Commit 16033d8

Browse files
Merge pull request #1225 from lamorton/bypass_unitless
Bypass unit checking if none of the variables/parameters have units.
2 parents 7d2c43b + 6fe5100 commit 16033d8

File tree

9 files changed

+9
-8
lines changed

9 files changed

+9
-8
lines changed

src/systems/control/controlsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ControlSystem <: AbstractControlSystem
7878
check_parameters(ps, iv)
7979
check_equations(deqs, iv)
8080
check_equations(observed, iv)
81-
check_units(deqs)
81+
all_dimensionless([dvs;ps;controls;iv]) || check_units(deqs)
8282
end
8383
new(loss, deqs, iv, dvs, controls, ps, observed, name, systems, defaults)
8484
end

src/systems/diffeqs/odesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct ODESystem <: AbstractODESystem
9393
check_variables(dvs,iv)
9494
check_parameters(ps,iv)
9595
check_equations(deqs,iv)
96-
check_units(deqs)
96+
all_dimensionless([dvs;ps;iv]) ||check_units(deqs)
9797
end
9898
new(deqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults, structure, connection_type, preface)
9999
end

src/systems/diffeqs/sdesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct SDESystem <: AbstractODESystem
9191
check_variables(dvs,iv)
9292
check_parameters(ps,iv)
9393
check_equations(deqs,iv)
94-
check_units(deqs,neqs)
94+
all_dimensionless([dvs;ps;iv]) || check_units(deqs,neqs)
9595
end
9696
new(deqs, neqs, iv, dvs, ps, var_to_name, ctrls, observed, tgrad, jac, ctrl_jac, Wfact, Wfact_t, name, systems, defaults, connection_type)
9797
end

src/systems/discrete_system/discrete_system.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct DiscreteSystem <: AbstractTimeDependentSystem
5858
if checks
5959
check_variables(dvs, iv)
6060
check_parameters(ps, iv)
61-
check_units(discreteEqs)
61+
all_dimensionless([dvs;ps;iv;ctrls]) ||check_units(discreteEqs)
6262
end
6363
new(discreteEqs, iv, dvs, ps, var_to_name, ctrls, observed, name, systems, default_u0, default_p)
6464
end

src/systems/jumps/jumpsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct JumpSystem{U <: ArrayPartition} <: AbstractTimeDependentSystem
5757
if checks
5858
check_variables(states, iv)
5959
check_parameters(ps, iv)
60-
check_units(ap,iv)
60+
all_dimensionless([states;ps;iv]) || check_units(ap,iv)
6161
end
6262
new{U}(ap, iv, states, ps, var_to_name, observed, name, systems, defaults, connection_type)
6363
end

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct NonlinearSystem <: AbstractTimeIndependentSystem
5656
connection_type::Any
5757
function NonlinearSystem(eqs, states, ps, var_to_name, observed, jac, name, systems, defaults, structure, connection_type; checks::Bool = true)
5858
if checks
59-
check_units(eqs)
59+
all_dimensionless([states;ps]) ||check_units(eqs)
6060
end
6161
new(eqs, states, ps, var_to_name, observed, jac, name, systems, defaults, structure, connection_type)
6262
end

src/systems/optimization/optimizationsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct OptimizationSystem <: AbstractTimeIndependentSystem
4646
check_units(op)
4747
check_units(observed)
4848
check_units(equality_constraints)
49-
check_units(inequality_constraints)
49+
all_dimensionless([states;ps]) || check_units(inequality_constraints)
5050
end
5151
new(op, states, ps, var_to_name, observed, equality_constraints, inequality_constraints, name, systems, defaults)
5252
end

src/systems/pde/pdesystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct PDESystem <: ModelingToolkit.AbstractMultivariateSystem
6868
name
6969
)
7070
if checks
71-
check_units(eqs)
71+
all_dimensionless([dvs;ivs;ps]) ||check_units(eqs)
7272
end
7373
new(eqs, bcs, domain, ivs, dvs, ps, defaults, connection_type, name)
7474
end

src/systems/validation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,4 @@ validate(term::Symbolics.SymbolicUtils.Symbolic) = safe_get_unit(term,"") !== no
156156

157157
"Throws error if units of equations are invalid."
158158
check_units(eqs...) = validate(eqs...) || throw(ValidationError("Some equations had invalid units. See warnings for details."))
159+
all_dimensionless(states) = all(map(x->safe_get_unit(x,"") in (unitless,nothing),states))

0 commit comments

Comments
 (0)