SciML / SciML/ModelingToolkitStandardLibrary.jl

SlewRateLimiter unexpected behaviour

Open
#390 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Julia
Stars
171
Forks
49
Avg merge
15h 50m
Merged PRs (30d)
10

Description

Describe the bug 🐞

SlewRateLimiter arguments cannot be passed as parameters.

Expected behavior

SlewRateLimiter arguments can be passed as parameters or as numerical values, achieving the same result.

Minimal Reproducible Example 👇

The code below shows a toy example in which arguments are passed to the SlewRateLimiter as numerical values, which indeed works.

@mtkmodel sistemslew begin

	@components begin

		source = Step(start_time = 2, height = 1)
		limiter = SlewRateLimiter(y_start=0.0, rising = 1, falling = -0.5, Td = 0.001) 

	end

	@equations begin

		connect(source.output,limiter.input)

	end

end

@mtkbuild systemlim = sistemslew()

However, if arguments are passed as parameters, @mtkbuild fails:


@mtkmodel sistemslew begin
	
	@parameters begin

		limittest = 1

	end
	
	@components begin

		source = Step(start_time = 2, height = 1)
		limiter = SlewRateLimiter(y_start=0.0, rising = limittest, falling = -0.5, Td = 0.001) 

	end

	@equations begin

		connect(source.output,limiter.input)

	end

end

@mtkbuild systemlim = sistemslew()

Error & Stacktrace ⚠️


TypeError: non-boolean (SymbolicUtils.BasicSymbolic{Bool}) used in boolean context

Stack trace
Here is what happened, the most recent locations are first:

macro expansion
from 
nonlinear.jl:105
(::ModelingToolkitStandardLibrary.Blocks.var"#137#138")()
from 
ModelingToolkitStandardLibrary → abstractsystem.jl:2436
 
SlewRateLimiter(; name::Symbol, y_start::Float64, rising::Symbolics.Num, falling::Float64, Td::Float64)
from 
ModelingToolkitStandardLibrary → abstractsystem.jl:2436
 
macro expansion
from 
abstractsystem.jl:2268
__sistemslew__(; name::Symbol, limittest::ModelingToolkit.NoValue, source__start_time::Nothing, source__height::Nothing, limiter__y_start::Nothing, limiter__rising::Nothing, limiter__falling::Nothing, limiter__Td::Nothing)
from 
julia → model_parsing.jl:920
 
__sistemslew__
from 
model_parsing.jl:140
Model
from 
model_parsing.jl:25
macro expansion
from 
abstractsystem.jl:2268
from 
[This cell: line 1](http://localhost:1234/edit?id=9d589f3e-2987-11f0-1bbe-878a80eda722#0e8412f3-ab33-4831-9382-0eaa224a1074)
[@mtkbuild systemlim = sistemslew()](http://localhost:1234/edit?id=9d589f3e-2987-11f0-1bbe-878a80eda722#0e8412f3-ab33-4831-9382-0eaa224a1074)

Additional context

I wonder whether this is a bug or if there is something I am overlooking regarding the operation of this block.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SlewRateLimiter constructor and reproduce the two @mtkbuild examples, comparing the numeric and parameterized rising arguments. The stack trace points to nonlinear.jl, abstractsystem.jl, and model_parsing.jl; done means the parameterized example builds with the same behavior as the numeric version.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.