Skip to content

UnboundLocalError when stopping_criterion = None in convergence_plot(). #648

@r3kste

Description

@r3kste

Bug description

Passing stopping_criterion = None to convergence_plot() or process_benchmark_results() raises
UnboundLocalError: local variable 'is_converged' referenced before assignment, even though the API mentions that None can be passed.

To Reproduce

import plotly.io as pio

import optimagic as om

problems = om.get_benchmark_problems("example")
optimizers = [
    "nag_dfols",
    "scipy_neldermead",
    "scipy_truncated_newton",
]
results = om.run_benchmark(
    problems,
    optimizers,
)

fig = om.convergence_plot(
    problems=problems,
    results=results,
    n_cols=2,
    problem_subset=["rosenbrock_good_start", "box_3d"],
    stopping_criterion=None,
)

fig.show()

Expected behavior

The figure should be generated without any error. I am not sure whether the implementation is incorrect, or whether the docstring is outdated.

Additional Information

The error occurs in the _process_one_result() function in process_benchmark_results.py, due to the absence of logic to handle the case when stopping_criterion = None

Proposed Fix

This could be fixed by one of:

  1. The case of stopping_criterion = None should be handled in the _process_one_result(),
  2. The documentation should be updated to reflect that stopping_criterion can not be 'None'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions