Skip to content
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

Support conditional statements in @mtkmodel #2319

Merged
merged 9 commits into from
Nov 29, 2023

Conversation

ven-k
Copy link
Member

@ven-k ven-k commented Oct 16, 2023

This PR adds support for

  • Conditional default values
@mtkmodel A begin
    ...
    @parameters begin
        a = condition ? 1 : 0
    end
end
  • Conditional equations and components inside the respective blocks
    • Inside @equations
    • Inside @components
    • Inside @parameters and @variables
@mtkmodel A begin
    ...
    @components begin
       if condition1
            b = B()
       end
    end
    @equations begin
       if condition2
            a ~ 0
       end
    end
end
  • If branch at top level
    • Equations
    • Components
    • Parameters
@mtkmodel A begin
    ...
    if condition
        @components begin
             b = B()
        end
        @equations begin
                a ~ 0
        end
    end
end
  • Adds relevant docs.

@ChrisRackauckas
Copy link
Member

Should we also generate events here or lower @YingboMa ?

@baggepinnen
Copy link
Contributor

I guess it depends on whether condition is a structural parameter or a symbolic expression. It'd be nice to support both, since structural parameters are often used to determine which equations to include.

@ven-k ven-k force-pushed the vkb/if-else-ladder branch from a32b0f0 to 2c1cdf8 Compare October 30, 2023 12:45
@ven-k ven-k marked this pull request as ready for review October 30, 2023 12:45
@ven-k ven-k force-pushed the vkb/if-else-ladder branch from 2c1cdf8 to 53d609b Compare October 31, 2023 18:19
@ven-k
Copy link
Member Author

ven-k commented Nov 4, 2023

Bump

@YingboMa
Copy link
Member

YingboMa commented Nov 7, 2023

The MTKStdlib failure looks real. Also, could you merge master back to this branch and run formatter?

`@parameters`,`@variables`, `@components` in the `@mtkmodel` and
`@components`.
…d conditional default values to parameters and variables
…ds compatible

- all variables are added as a key and `:condition` is added as a metadata for the conditional variables.
- The `:condition` contains entire if-else block info as a tuple of (condition-branch, condition, variables-if-correct, variable-if-condition-isn't-met).
- variable-if-condition-isn't-met is nothing or tuple similar to the one above.
- and ternary conditional statements at the top level of the block
- adds relevant tests
@ven-k ven-k force-pushed the vkb/if-else-ladder branch from 53d609b to 8b75e01 Compare November 19, 2023 18:47
@ven-k
Copy link
Member Author

ven-k commented Nov 29, 2023

@YingboMa I've rebased and have fixed issues that threw error in MTKStdlib tests. This can be reviewed.

Copy link
Member

@YingboMa YingboMa left a comment

Choose a reason for hiding this comment

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

This looks really good!

@YingboMa YingboMa merged commit 9ff8d74 into SciML:master Nov 29, 2023
16 of 19 checks passed
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.

4 participants