[Python] Debugging scipy.minimize

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to "minimize" using SLSQP in scipy module. With a lot of difficulty, I am trying to implement some constraints. I am encountering some strange error, thus unable to debug. My favourite way to debug is by using watchlists/break-points. I got the following error:

    File "d:\i.PhD\H.Synthetic Model\3LayerModel\CRMPL\crmpl_functions_class.*emphasized text*py", line 471, in fit_model
    res = minimize(self.loss_function, x0,args = (input_series, ilt,bhpgrad,q_obs), \
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\i.PhD\H.Synthetic Model\3LayerModel\CRMPL\.venv\.venv\Lib\site-packages\scipy\optimize\_minimize.py", line 743, in minimize
    res = _minimize_slsqp(fun, x0, args, jac, bounds,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\i.PhD\H.Synthetic Model\3LayerModel\CRMPL\.venv\.venv\Lib\site-packages\scipy\optimize\_slsqp_py.py", line 423, in _minimize_slsqp
    c = _eval_constraint(x, cons)
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\i.PhD\H.Synthetic Model\3LayerModel\CRMPL\.venv\.venv\Lib\site-packages\scipy\optimize\_slsqp_py.py", line 473, in _eval_constraint
    c_eq = concatenate([atleast_1d(con['fun'](x, *con['args']))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 1 dimension(s) and the array at index 1 has 2 dimension(s)


    Note that I implemented three sets of constraints. However, I am not able to debug the origin of this error.

    What is the cause of the error and how do I fix it?

    Continue reading...

Compartilhe esta Página