ICB-DCM / pyPESTO

python Parameter EStimation TOolbox
https://pypesto.readthedocs.io
BSD 3-Clause "New" or "Revised" License
220 stars 47 forks source link

Parameters plot error when result has `None` #1107

Open m-philipps opened 1 year ago

m-philipps commented 1 year ago

Bug description visualize.parameters fails with ValueError when some of the optimization starts failed, i.e. result.optimize_result[i]['x'] is None:

---> 17 pypesto.visualize.parameters(
     18     results=result, 
     19     start_indices="all", 
     20     reference=reference,
     21 )

File [~/Documents/pyPESTO/pypesto/visualize/parameters.py:121], in parameters(results, ax, parameter_indices, lb, ub, size, reference, colors, legends, balance_alpha, start_indices, scale_to_interval, plot_inner_parameters)
    118     lb, ub, xs = map(scale_parameters, (lb, ub, xs))
    120     # call lowlevel routine
--> 121     ax = parameters_lowlevel(
    122         xs=xs,
    123         fvals=fvals,
    124         lb=lb,
    125         ub=ub,
    126         x_labels=x_labels,
    127         ax=ax,
    128         size=size,
    129         colors=colors[j],
    130         legend_text=legends[j],
    131         balance_alpha=balance_alpha,
    132     )
    134 # parse and apply plotting options
    135 ref = create_references(references=reference)

File [~/Documents/pyPESTO/pypesto/visualize/parameters.py:272], in parameters_lowlevel(xs, fvals, lb, ub, x_labels, ax, size, colors, linestyle, legend_text, balance_alpha)
    238 """
    239 Plot parameters plot using list of parameters.
    240 
   (...)
    269     The plot axes.
    270 """
    271 # parse input
--> 272 xs = np.array(xs)
    273 fvals = np.array(fvals)
    274 # remove nan or inf values in fvals and xs

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (100,) + inhomogeneous part.

Expected behavior I would expect the parameters plot to be generated without the failed starts

Comment In the lower level process_start_indices delete_nan_inf is only used when start_indices is set to 'all_clustered' or 'first_cluster'

m-philipps commented 1 year ago

Is this the desired behaviour? If so I would add an informative Warning when there are failed starts in the start_indices. If not, I could use the delete_nan_inf function for all start_indices options

dweindl commented 1 year ago

Is this the desired behaviour?

No, I don't think so.

Yeah, some warning "Skipping result {id/idx} due to non-finite / missing parameter values" would make sense.

m-philipps commented 1 year ago

closed until reproduced

m-philipps commented 11 months ago

Reproducing the bug is fairly straightforward with an optimisation result with any failed start, i.e. fval = inf and x = None.

The issue is that the list of parameter vectors are converted to a numpy array before filtering out None and and the function for that, delete_nan_inf, assumes them to be a numpy array.

m-philipps commented 11 months ago

This appears to be specific to the way that each optimiser returns the values for x.