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

Don't log NaN errors and limit output to top 5 #1836

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ function log_bottlenecks(model; converged::Bool)
flow_error = @. abs(cache.nlsolver.cache.atmp / u)
perm = sortperm(flow_error; rev = true)
errors = Pair{Symbol, Float64}[]
error_count = 0
max_errors = 5
for i in perm
node_id = Symbol(id_from_state_index(p, u, i))
error = flow_error[i]
if error < model.config.solver.reltol
# 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)
if isnan(error)
continue
else
push!(errors, node_id => error)
error_count += 1
end
Copy link
Member

Choose a reason for hiding this comment

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

errors = Pair{Symbol, Float64}[]
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]
    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

That makes it more readable for me.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe max errors should not be set in the function but as a constant on top of the file.

end
if !isempty(errors)
@logmsg level "Convergence bottlenecks in descending order of severity:" errors...
Expand Down
Loading