tBuLi / symfit

Symbolic Fitting; fitting as it should be.
http://symfit.readthedocs.org
MIT License
236 stars 19 forks source link

Crash with numpy version 1.15 and above (function np.product removed) #374

Open kvr2007 opened 1 month ago

kvr2007 commented 1 month ago

Hello!

First of all, great project, really wonderful to have it available as libre and open source code!

I was trying to run some of my scripts from 2022 in python3.12, and apparently numpy developers removed np.product at some point. So I get the following error when computing covariance matrix:

  File "...\site-packages\symfit\core\fit.py", line 574, in execute
    minimizer_ans.covariance_matrix = self.covariance_matrix(
                                      ^^^^^^^^^^^^^^^^^^^^^^^
  File ...\site-packages\symfit\core\fit.py", line 278, in covariance_matrix
    cov_matrix = self._covariance_matrix(best_fit_params,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\site-packages\symfit\core\fit.py", line 256, in _covariance_matrix
    raw_dof = np.sum([np.product(shape) for shape in self.data_shapes[1]])
                      ^^^^^^^^^^
  File "...\site-packages\numpy\__init__.py", line 428, in __getattr__
    raise AttributeError("module {!r} has no attribute "
AttributeError: module 'numpy' has no attribute 'product'

If I change np.product to np.prod all works as expected. I think it's the only place in all of symfit, where np.product is used. So I would suggest to change the code. Alternatively, one needs to fix the numpy version.

artygo8 commented 2 weeks ago

I had this issue too, and in the meantime, as a workaround, you can do something like that:

import numpy as np
from symfit import D, Eq, Fit, Model, parameters, variables

# MONKEY PATCH
np.product = np.prod