Skip to content

Write results also on an interrupt or crash#2191

Merged
SouthEndMusic merged 1 commit intomainfrom
always-write-results
Mar 31, 2025
Merged

Write results also on an interrupt or crash#2191
SouthEndMusic merged 1 commit intomainfrom
always-write-results

Conversation

@visr
Copy link
Member

@visr visr commented Mar 31, 2025

See #2177 (comment)

Instead of calling run(config) this replaces it with the contents of that function:

Ribasim/core/src/main.jl

Lines 10 to 15 in e81fa39

function run(config::Config)::Model
model = Model(config)
solve!(model)
write_results(model)
return model
end

Such that we can solve! in a try and call write_results whether it crashes or not.
I don't know how we can easily test it. Perhaps not worth the effort? I tested it on a model that hangs, which I killed with ctrl+c. This works great for that, allowing you to inspect results right up to the hang.

@visr visr marked this pull request as ready for review March 31, 2025 11:15
@SouthEndMusic SouthEndMusic merged commit e030026 into main Mar 31, 2025
20 checks passed
@SouthEndMusic SouthEndMusic deleted the always-write-results branch March 31, 2025 14:22
@visr visr mentioned this pull request Apr 1, 2025
visr added a commit that referenced this pull request Apr 2, 2025
This is a follow-up of #2191. An issue with that is that it logged a
warning about crashing simulations also when it succeeded. Also it
didn't log the bottlenecks when you interrupt a (hanging) simulation.

Now it does both, this is what is shown when interrupting a simulation,
stacktrace is clipped off:

```
┌ Info: Starting a Ribasim simulation.
│   toml_path = c:\Users\visser_mn\Downloads\lhm-sel\lhm-sel.toml
│   cli.ribasim_version = 2025.2.0
│   starttime = 2020-01-01T00:00:00
│   endtime = 2021-01-01T00:00:00
└ @ Ribasim C:\ProgramData\DevDrives\repo\ribasim\Ribasim\core\src\main.jl:40
┌ Warning: Simulation crashed or interrupted.
└ @ Ribasim C:\ProgramData\DevDrives\repo\ribasim\Ribasim\core\src\main.jl:51
┌ Warning: Convergence bottlenecks in descending order of severity:
│   Outlet #591225 = 48782.889544290454
│   Outlet #591226 = 48782.889544290454
│   ManningResistance #340784 = 0.04819449424793999
│   Pump #340303 = 0.045638255628477994
│   Pump #340194 = 0.04563825461806383
└ @ Ribasim C:\ProgramData\DevDrives\repo\ribasim\Ribasim\core\src\logging.jl:55
ERROR: InterruptException:
Stacktrace:
  [1] bracketstrictlymontonic(v::Vector{Float64}, x::Float64, guess::Int64, o::Base.Order.ForwardOrdering)
```

This implements `Base.success(::Model)::Bool`. Before we checked the
SciML retcode. I noticed that the retcode of an ongoing simulation that
gets interrupted is also successfull. So now we check both the retcode
and if it `is_finished`.
@visr visr mentioned this pull request Apr 14, 2025
visr added a commit that referenced this pull request Apr 15, 2025
## [v2025.3.0] - 2025-04-14

The only breaking change in this release is to disallow connecting a
single FlowBoundary to multiple Basins.
There are large improvements in the ability to visualize results on the
map in QGIS.
We also welcome the Junction node to the family, which will help laying
out networks in a recognizable manner.

### Added
- Add spatio-temporal results layers to QGIS.
[#2208](#2208)
- Add topological (straight line) link view toggle to QGIS.
[#2208](#2208)
- Added [Junction](https://ribasim.org/reference/node/junction.html)
node type. [#2175](#2175)
- Write results and log bottlenecks also on an interrupt or crash.
[#2191](#2191)
[#2200](#2200)
- Log computation time and save it to `solver_stats.arrow`.
[#2209](https://github.com/Deltares/Ribasim/pull/)
- Experimental support for writing the model network and results into
files used by Delft-FEWS,
[`model.to_fews`](`https://ribasim.org/reference/python/Model.html#ribasim.Model.to_fews`).
[#2161](#2161)
- Document
[`results/concentration.arrow`](https://ribasim.org/reference/usage.html#concentration---concentration.arrow).
[#2165](#2165)

### Changed
- Allow max 1 outflow neighbour for FlowBoundary.
[#2192](#2192)
- Automatic differentiation is enabled by default again, `autodiff =
true`, leading to better performance.
[#2137](#2137)
[#2183](#2183)
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