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

feat: add function to parse variable from string #3224

Merged
merged 6 commits into from
Nov 20, 2024

Conversation

AayushSabharwal
Copy link
Member

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

Add any other context about the problem here.

"""
$(TYPEDSIGNATURES)

Return the variable in `sys` referred to by its string representation `str`.
Copy link
Member

Choose a reason for hiding this comment

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

add it to the docs

maybe_dummy_var = namespacedvar | namespacedvar "(t)" |
namespacedvar "(t)" "ˍ" ts | namespacedvar "ˍ" ts |
namespacedvar "ˍ" ts "(t)"
ts = "t" | "t" ts
Copy link
Member

Choose a reason for hiding this comment

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

nameof(independent_variable(sys))?

@AayushSabharwal
Copy link
Member Author

Codecov is at it again

# I'd write a regex to validate `str`, but https://xkcd.com/1171/
str = strip(str)
derivative_level = 0
while startswith(str, "D(") && endswith(str, ")")
Copy link
Member

Choose a reason for hiding this comment

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

We may need to validate that D is also the differential?

Copy link
Member Author

@AayushSabharwal AayushSabharwal Nov 20, 2024

Choose a reason for hiding this comment

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

D never shows up in expressions, it always prints as Differential(t)(x(t)). In the interest of concision, I assumed that D refers to the derivative with respect to the independent variable. I could also add a case that handles Differential(t)(x(t)) and validates that the independent variable matches?

Copy link
Member

Choose a reason for hiding this comment

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

Okay

@ChrisRackauckas ChrisRackauckas merged commit 21dff0c into SciML:master Nov 20, 2024
32 of 39 checks passed
@AayushSabharwal AayushSabharwal deleted the as/parse-string branch November 20, 2024 14:37
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.

2 participants