-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add the ability to store the trace for nonlinear solve algorithms #292
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Logging the Solve Process | ||
|
||
All NonlinearSolve.jl native solvers allow storing and displaying the trace of the nonlinear | ||
solve process. This is controlled by 3 keyword arguments to `solve`: | ||
|
||
1. `show_trace`: Must be `Val(true)` or `Val(false)`. This controls whether the trace is | ||
displayed to the console. (Defaults to `Val(false)`) | ||
2. `trace_level`: Needs to be one of Trace Objects: [`TraceMinimal`](@ref), | ||
[`TraceWithJacobianConditionNumber`](@ref), or [`TraceAll`](@ref). This controls the | ||
level of detail of the trace. (Defaults to `TraceMinimal()`) | ||
3. `store_trace`: Must be `Val(true)` or `Val(false)`. This controls whether the trace is | ||
stored in the solution object. (Defaults to `Val(false)`) | ||
|
||
## Example Usage | ||
|
||
```@example tracing | ||
using ModelingToolkit, NonlinearSolve | ||
@variables x y z | ||
@parameters σ ρ β | ||
# Define a nonlinear system | ||
eqs = [0 ~ σ * (y - x), | ||
0 ~ x * (ρ - z) - y, | ||
0 ~ x * y - β * z] | ||
@named ns = NonlinearSystem(eqs, [x, y, z], [σ, ρ, β]) | ||
u0 = [x => 1.0, y => 0.0, z => 0.0] | ||
ps = [σ => 10.0 ρ => 26.0 β => 8 / 3] | ||
prob = NonlinearProblem(ns, u0, ps) | ||
solve(prob) | ||
``` | ||
|
||
This produced the output, but it is hard to diagnose what is going on. We can turn on | ||
the trace to see what is happening: | ||
|
||
```@example tracing | ||
solve(prob; show_trace = Val(true), trace_level = TraceAll(10)) | ||
``` | ||
|
||
You can also store the trace in the solution object: | ||
|
||
```@example tracing | ||
sol = solve(prob; trace_level = TraceAll(), store_trace = Val(true)); | ||
sol.trace | ||
``` | ||
|
||
!!! note | ||
|
||
For `iteration == 0` only the `norm(fu, Inf)` is guaranteed to be meaningful. The other | ||
values being meaningful are solver dependent. | ||
|
||
## API | ||
|
||
```@docs | ||
TraceMinimal | ||
TraceWithJacobianConditionNumber | ||
TraceAll | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We definitely need to update https://docs.sciml.ai/NonlinearSolve/stable/basics/solve/#solver_options as well.