Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kvr2007 opened this issue Oct 25, 2024 · 1 comment
Open

Comments

@kvr2007
Copy link

kvr2007 commented Oct 25, 2024

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
Copy link

artygo8 commented Nov 13, 2024

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

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

No branches or pull requests

2 participants