From 471e5c27936e1b8baab49cb510e9a9c9a5b6df2c Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Wed, 9 Oct 2024 13:19:56 +0530 Subject: [PATCH] fix: fix unnecessary `oneunit` call in `get_unit` --- src/systems/unit_check.jl | 2 +- test/units.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/systems/unit_check.jl b/src/systems/unit_check.jl index 5035a22b5e..d3a8db7b77 100644 --- a/src/systems/unit_check.jl +++ b/src/systems/unit_check.jl @@ -77,7 +77,7 @@ get_unit(x::SciMLBase.NullParameters) = unitless get_unit(op::typeof(instream), args) = get_unit(args[1]) function get_unit(op, args) # Fallback - result = oneunit(op(get_unit.(args)...)) + result = op(get_unit.(args)...) try get_unit(result) catch diff --git a/test/units.jl b/test/units.jl index ff0cd42ac3..e279166d62 100644 --- a/test/units.jl +++ b/test/units.jl @@ -240,3 +240,10 @@ sys = complete(sys) @test isequal(ModelingToolkit.getdefault(sys.pt.a), sys.v * sys.τ) @test ModelingToolkit.getdefault(sys.v) ≈ 2.0 @test ModelingToolkit.getdefault(sys.τ) ≈ 3.0 + +@testset "Issue#3017" begin + @constants c = 1 [unit = us"mol/nmol"] + @variables k(t) [unit = us"mol/nmol"] + @test ModelingToolkit.get_unit(c) == ModelingToolkit.get_unit(-c) + @test_nowarn NonlinearSystem([k ~ c], [k], []; name=:example) +end