Skip to content

Commit

Permalink
Don't log NaN errors and limit output to top 5 (#1836)
Browse files Browse the repository at this point in the history
Fixes #1833

HWS output looks like this before, and no output after.
The `invalid_unstable` test model still logs though, as captured by
tests.

```

┌ Info: Convergence bottlenecks in descending order of severity:
│   Pump #2019 = NaN
│   Pump #2130 = NaN
│   Pump #2315 = NaN
│   Pump #2637 = NaN
│   Pump #3995 = NaN
│   Pump #4536 = NaN
│   Pump #6128 = NaN
│   Pump #6866 = NaN
│   Pump #9633 = NaN
│   Pump #10704 = NaN
│   Pump #10710 = NaN
│   Pump #10711 = NaN
│   Pump #10712 = NaN
│   Pump #10713 = NaN
│   Pump #10714 = NaN
│   Pump #10715 = NaN
│   Pump #10716 = NaN
│   Pump #10717 = NaN
│   Outlet #6692 = NaN
│   Outlet #7679 = NaN
│   Outlet #10702 = NaN
│   Outlet #10703 = NaN
│   UserDemand #1000015 = NaN
│   UserDemand #1000016 = NaN
│   UserDemand #1000017 = NaN
│   UserDemand #1000018 = NaN
│   UserDemand #1000019 = NaN
│   UserDemand #1000020 = NaN
│   UserDemand #1000021 = NaN
│   UserDemand #1000022 = NaN
│   UserDemand #1000038 = NaN
│   UserDemand #1000040 = NaN
│   UserDemand #1000042 = NaN
│   Basin #529 = NaN
│   Basin #670 = NaN
│   Basin #905 = NaN
│   Basin #1041 = NaN
│   Basin #1340 = NaN
│   Basin #1369 = NaN
│   Basin #1514 = NaN
│   Basin #1676 = NaN
│   Basin #1709 = NaN
│   Basin #1873 = NaN
│   Basin #2028 = NaN
│   Basin #2232 = NaN
│   Basin #2255 = NaN
│   Basin #2323 = NaN
│   Basin #2336 = NaN
│   Basin #2381 = NaN
│   Basin #2468 = NaN
│   Basin #2496 = NaN
│   Basin #2522 = NaN
│   Basin #2590 = NaN
│   Basin #2749 = NaN
│   Basin #2968 = NaN
│   Basin #3016 = NaN
│   Basin #3090 = NaN
│   Basin #3302 = NaN
│   Basin #3364 = NaN
│   Basin #3448 = NaN
│   Basin #3543 = NaN
│   Basin #3584 = NaN
│   Basin #3721 = NaN
│   Basin #3899 = NaN
│   Basin #4024 = NaN
│   Basin #4134 = NaN
│   Basin #4184 = NaN
│   Basin #4279 = NaN
│   Basin #4339 = NaN
│   Basin #4473 = NaN
│   Basin #4570 = NaN
│   Basin #4714 = NaN
│   Basin #4796 = NaN
│   Basin #4830 = NaN
│   Basin #4838 = NaN
│   Basin #5048 = NaN
│   Basin #5097 = NaN
│   Basin #5207 = NaN
│   Basin #5322 = NaN
│   Basin #5371 = NaN
│   Basin #5381 = NaN
│   Basin #5472 = NaN
│   Basin #5498 = NaN
│   Basin #5505 = NaN
│   Basin #5530 = NaN
│   Basin #5616 = NaN
│   Basin #5909 = NaN
│   Basin #5978 = NaN
│   Basin #5999 = NaN
│   Basin #6017 = NaN
│   Basin #6077 = NaN
│   Basin #6101 = NaN
│   Basin #6164 = NaN
│   Basin #6224 = NaN
│   Basin #6273 = NaN
│   Basin #6327 = NaN
│   Basin #6364 = NaN
│   Basin #6401 = NaN
│   Basin #6419 = NaN
│   Basin #6428 = NaN
│   Basin #6437 = NaN
│   Basin #6473 = NaN
│   Basin #6503 = NaN
│   Basin #6582 = NaN
│   Basin #6757 = NaN
│   Basin #6885 = NaN
│   Basin #6926 = NaN
│   Basin #6945 = NaN
│   Basin #6972 = NaN
│   Basin #7053 = NaN
│   Basin #7087 = NaN
│   Basin #7101 = NaN
│   Basin #7117 = NaN
│   Basin #7164 = NaN
│   Basin #7214 = NaN
│   Basin #7310 = NaN
│   Basin #7385 = NaN
│   Basin #7400 = NaN
│   Basin #7417 = NaN
│   Basin #7484 = NaN
│   Basin #7597 = NaN
│   Basin #7615 = NaN
│   Basin #7668 = NaN
│   Basin #7706 = NaN
│   Basin #7843 = NaN
│   Basin #7909 = NaN
│   Basin #8014 = NaN
│   Basin #8020 = NaN
│   Basin #8049 = NaN
│   Basin #8059 = NaN
│   Basin #8071 = NaN
│   Basin #8234 = NaN
│   Basin #8257 = NaN
│   Basin #8340 = NaN
│   Basin #8364 = NaN
│   Basin #8559 = NaN
│   Basin #8685 = NaN
│   Basin #8717 = NaN
│   Basin #8757 = NaN
│   Basin #8786 = NaN
│   Basin #8817 = NaN
│   Basin #8921 = NaN
│   Basin #9033 = NaN
│   Basin #9086 = NaN
│   Basin #9123 = NaN
│   Basin #9144 = NaN
│   Basin #9185 = NaN
│   Basin #9209 = NaN
│   Basin #9358 = NaN
│   Basin #9406 = NaN
│   Basin #9430 = NaN
│   Basin #9484 = NaN
│   Basin #9586 = NaN
│   Basin #9627 = NaN
│   Basin #9830 = NaN
│   Basin #9885 = NaN
│   Basin #9899 = NaN
│   Basin #9906 = NaN
│   Basin #9954 = NaN
│   Basin #10040 = NaN
│   Basin #10107 = NaN
│   Basin #10184 = NaN
│   Basin #10202 = NaN
│   Basin #10308 = NaN
│   Basin #10321 = NaN
│   Basin #10343 = NaN
│   Basin #10583 = NaN
│   Basin #10587 = NaN
│   Basin #10634 = NaN
└   Basin #10659 = NaN
```
  • Loading branch information
visr authored Sep 23, 2024
1 parent bf1e3a9 commit f5b9dba
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions core/src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ function log_bottlenecks(model; converged::Bool)
# Indicate convergence bottlenecks if possible with the current algorithm
if hasproperty(cache, :nlsolver)
flow_error = @. abs(cache.nlsolver.cache.atmp / u)
perm = sortperm(flow_error; rev = true)
errors = Pair{Symbol, Float64}[]
for i in perm
error_count = 0
max_errors = 5
# Iterate over the errors in descending order
for i in sortperm(flow_error; rev = true)
node_id = Symbol(id_from_state_index(p, u, i))
error = flow_error[i]
if error < model.config.solver.reltol
isnan(error) && continue # NaN are sorted as largest
# Stop reporting errors if they are too small or too many
if error < model.config.solver.reltol || error_count >= max_errors
break
end
push!(errors, node_id => error)
error_count += 1
end
if !isempty(errors)
@logmsg level "Convergence bottlenecks in descending order of severity:" errors...
Expand Down

0 comments on commit f5b9dba

Please sign in to comment.