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

Side effect of notch_approximation_law.stress #130

Closed
maierbn opened this issue Nov 12, 2024 · 4 comments
Closed

Side effect of notch_approximation_law.stress #130

maierbn opened this issue Nov 12, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@maierbn
Copy link
Contributor

maierbn commented Nov 12, 2024

Describe the bug
After call to notch_approximation_law.stress(value), the value object is sometimes changed. This is an unwanted side effect of this function.

To Reproduce
Hard to reproduce, it was observed in _compute_hcm_RAM where we have:

extended_neuber = pylife.materiallaws.notch_approximation_law.ExtendedNeuber(E, K_prime, n_prime, K_p)
extended_neuber_binned = pylife.materiallaws.notch_approximation_law.Binned(
        extended_neuber, maximum_absolute_load, 100)

This calls materiallaws.notch_approximation_law.Binned._create_bins_single_assessment_point where self._lut_primary_branch.load is changed during

self._lut_primary_branch.stress \
            = self._notch_approximation_law.stress(self._lut_primary_branch.load)

Expected result
self._notch_approximation_law.stress does not change the argument, self._lut_primary_branch.load in this case.

Environment (please complete the following information):

  • OS: Windows 11
  • How installed: pip
  • Version: develop branch

Additional context
The problem was tracked back and it seems scipy.optimize.newton(func, x0) changes x0 if it is an object like a pd.Series.

@maierbn
Copy link
Contributor Author

maierbn commented Nov 18, 2024

The issue arises with numpy>=2, even when using Python 3.12 (it is not specific to Python 3.13).

If you have a Python project that uses numpy version 2 and you import the released pylife (which is only tested with numpy 1), certain results—specifically those utilizing the HCM algorithm—will be incorrect. There won’t be any runtime errors, but the computed values will be wrong.

@maierbn
Copy link
Contributor Author

maierbn commented Nov 18, 2024

Using the fix with copy(x0) will make it work also for numpy 2 (at least in the cases in my setup)

@johannes-mueller
Copy link
Member

Closed as of #139

@maierbn
Copy link
Contributor Author

maierbn commented Dec 2, 2024

I can confirm that the issue is now fixed with #139 (using np.asarray instead of copy(x0))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants