Skip to content

Provision to enforce types in parameters, variables and structural_parameters in @mtkmodel #2500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 28, 2024

Conversation

ven-k
Copy link
Member

@ven-k ven-k commented Feb 27, 2024

Closes #2491

Check that specified default for a variable is of specified type.
Add types to corresponding keyword arg.

While here, fix the missing metadata of structural_parameters in model-structure.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Note that @variables t k(t)::Int = 1.5 works just fine. So here, @mtkmodel enforces its own checks for defaults and restricts users providing incorrect input by adding types to the keyword argument.

:components => [[:model_a, :ModelA]]
:variables => Dict{Symbol, Dict{Symbol, Any}}(:v=>Dict(:default=>:v_var), :v_array=>Dict(:size=>(2, 3)))
:icon => URI("https://github.com/SciML/SciMLDocs/blob/main/docs/src/assets/logo.png")
:kwargs => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :v=>Dict{Symbol, Union{Nothing, Symbol}}(:value=>:v_var, :type=>nothing), :v_array=>Dict(:value=>nothing, :type=>nothing), :p1=>Dict(:value=>nothing))
Copy link
Member Author

@ven-k ven-k Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that, in structure dictionary,

:kwargs => Dict{Symbol, Any}(:f=>:sin, :v=>:v_var, :v_array=>nothing, :model_a__k_array=>nothing, :p1=>nothing)

is now modified to:

  :kwargs => Dict{Symbol, Dict}(:f=>Dict(:value=>:sin), :v=>Dict{Symbol, Union{Nothing, Symbol}}(:value=>:v_var, :type=>nothing), :v_array=>Dict(:value=>nothing, :type=>nothing), :p1=>Dict(:value=>nothing))

i.e kwargs dictionary has a sub-dictionary with :value and :type, to store the latter metadata.

As it was Any before, one could argue this is still not a breaking change.
However, note that the required changes can live without this, albeit with incomplete info.

@ChrisRackauckas should I drop this change or can this be added.

@ven-k
Copy link
Member Author

ven-k commented Feb 28, 2024

I've verified that model_parsing.jl tests pass locally. CI fails before that in an unrelated test (Optimization test) to this PR.

@ChrisRackauckas ChrisRackauckas merged commit c5bff6a into SciML:master Feb 28, 2024
@ven-k ven-k mentioned this pull request Feb 29, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@mtkmodel does not handle specification of variable type
2 participants