Skip to content

Raise clear errors when reading an empty log file - #711

Open
raashish1601 wants to merge 1 commit into
optimagic-dev:mainfrom
raashish1601:fix/469-empty-log-errors
Open

raashish1601 wants to merge 1 commit into
optimagic-dev:mainfrom
raashish1601:fix/469-empty-log-errors

Conversation

@raashish1601

Copy link
Copy Markdown

What problem do you want to solve?

Closes #469.

Reading a log file that has no entries failed with errors that don't explain the problem:

  • SQLiteLogReader.read_history() and read_multistart_history() raised IndexError: index 0 is out of bounds for axis 0 with size 0 from numpy.
  • read_start_params() raised IndexError: list index out of range.
  • criterion_plot(path) and params_plot(path) raised KeyError: 'direction'.

Now these raise a ValueError that says the log does not contain any function evaluations or any optimization problem. The plot functions also include the path of the log file in the message. read_iteration already had a clear message for this case, so I left it as is.

I added tests for the reader methods and for both plot functions with an empty database. tests/optimagic/logging/test_logger.py and tests/optimagic/visualization/test_history_plots.py pass locally (except the bokeh/altair backend tests, which need packages I don't have installed). ruff check and ruff format pass.

Todo

  • Target the right branch and pick an appropriate title.
  • Put Closes #XXXX in the first PR comment to auto-close the relevant issue once
    the PR is accepted. This is not applicable if there is no corresponding issue.

Reading the history or start params from a log without entries failed
with an IndexError from numpy or a KeyError in criterion_plot and
params_plot. Raise a ValueError that says the log is empty instead.

Closes optimagic-dev#469.

This branch has not been deployed

No deployments
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.

Improve error messages for empty log files

1 participant