Skip to content

feat: add assertions functionality #3364

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 11 commits into from
Feb 10, 2025
Merged
Prev Previous commit
Next Next commit
docs: update assertions documentation
  • Loading branch information
AayushSabharwal committed Feb 10, 2025
commit 3ca004e4b11e2513121c4e68f3d56ad6918effa2
20 changes: 18 additions & 2 deletions docs/src/basics/Debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,31 @@
```

The assertions must be an iterable of pairs, where the first element is the symbolic condition and
the second is the message to be logged when the condition fails.
the second is a message to be logged when the condition fails. All assertions are added to the
generated code and will cause the solver to reject steps that fail the assertions. For systems such
as the above where the assertion is guaranteed to eventually fail, the solver will likely exit
with a `dtmin` failure..

```@example debug
prob = ODEProblem(sys, [], (0.0, 10.0))
sol = solve(prob, Tsit5())
```

We can use `debug_system` to log the failing assertions in each call to the RHS function.

```@repl debug
dsys = debug_system(sys; functions = []);
dprob = ODEProblem(dsys, [], (0.0, 10.0));
dsol = solve(dprob, Tsit5());
```

Note the messages containing the failed assertion and corresponding message.
Note the logs containing the failed assertion and corresponding message. To temporarily disable
logging in a system returned from `debug_system`, use `ModelingToolkit.ASSERTION_LOG_VARIABLE`.

```@repl debug
dprob[ModelingToolkit.ASSERTION_LOG_VARIABLE] = false;
solve(drob, Tsit5());

Check warning on line 68 in docs/src/basics/Debugging.md

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"drob" should be "drop".
```

```@docs
debug_system
Expand Down
Loading