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

darwin aarch64 skrf/calibration/tests/test_calibration.py failing with divide by zero (determinate calculations) #972

Open
ghost opened this issue Nov 9, 2023 · 4 comments
Labels
Is it a bug? To be confirmed if it is a bug or not

Comments

@ghost
Copy link

ghost commented Nov 9, 2023

Describe the bug
updating to scikit-rf version 0.29.1 PR NixOS/nixpkgs#266389 fails in the unit test skrf/calibration/tests/test_calibration.py with divide by zero errors.

numpy version is: 1.25.2, python is 3.11, darwin (macos) aarch64

unitfail.txt

1st failure pasted inline.

FAILED skrf/calibration/tests/test_calibration.py::DetermineTest::test_determine_reflect_matched_thru_and_line - RuntimeWarning: divide by zero encountered in det
FAILED skrf/calibration/tests/test_calibration.py::DetermineTest::test_determine_reflect_matched_thru_and_line_ideal_reflect - RuntimeWarning: divide by zero encountered in det
FAILED skrf/calibration/tests/test_calibration.py::DetermineTest::test_determine_reflect_regression - RuntimeWarning: divide by zero encountered in det
=================================== FAILURES ===================================
__________ DetermineTest.test_determine_reflect_matched_thru_and_line __________
self = <test_calibration.DetermineTest testMethod=test_determine_reflect_matched_thru_and_line>
    def test_determine_reflect_matched_thru_and_line(self):
        freq = rf.F(.25, .7, 40, unit = 'GHz')
        medium = Coaxial.from_attenuation_VF(freq, att = 3.0, VF = .69)
    
        thru = medium.line(0, 'm')
        line = medium.line(0.12, 'm')
        short = medium.short()
    
        rng = npy.random.default_rng(12)
        short.s[:, 0, 0] = short.s[:, 0, 0]+rng.uniform(-.02, 0.02, freq.f.size) + rng.uniform(-.02, 0.02, freq.f.size)*1j
    
>       r = determine_reflect(thru, rf.two_port_reflect(short, short), line)
skrf/calibration/tests/test_calibration.py:101: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
skrf/calibration/calibration.py:6406: in determine_reflect
    d = -det(thru_m.s)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
a = array([[[5.e-08+0.j, 1.e+00+0.j],
        [1.e+00+0.j, 5.e-08+0.j]],
       [[5.e-08+0.j, 1.e+00+0.j],
        [1.e+0... 1.e+00+0.j],
        [1.e+00+0.j, 5.e-08+0.j]],
       [[5.e-08+0.j, 1.e+00+0.j],
        [1.e+00+0.j, 5.e-08+0.j]]])
    @array_function_dispatch(_unary_dispatcher)
    def det(a):
        """
        Compute the determinant of an array.
    
        Parameters
        ----------
        a : (..., M, M) array_like
            Input array to compute determinants for.
    
        Returns
        -------
        det : (...) array_like
            Determinant of `a`.
    
        See Also
        --------
        slogdet : Another way to represent the determinant, more suitable
          for large matrices where underflow/overflow may occur.
        scipy.linalg.det : Similar function in SciPy.
    
        Notes
        -----
    
        .. versionadded:: 1.8.0
    
        Broadcasting rules apply, see the `numpy.linalg` documentation for
        details.
    
        The determinant is computed via LU factorization using the LAPACK
        routine ``z/dgetrf``.
    
        Examples
        --------
        The determinant of a 2-D array [[a, b], [c, d]] is ad - bc:
    
        >>> a = np.array([[1, 2], [3, 4]])
        >>> np.linalg.det(a)
        -2.0 # may vary
    
        Computing determinants for a stack of matrices:
    
        >>> a = np.array([ [[1, 2], [3, 4]], [[1, 2], [2, 1]], [[1, 3], [3, 1]] ])
        >>> a.shape
        (3, 2, 2)
        >>> np.linalg.det(a)
        array([-2., -3., -8.])
    
        """
        a = asarray(a)
        _assert_stacked_2d(a)
        _assert_stacked_square(a)
        t, result_t = _commonType(a)
        signature = 'D->D' if isComplexType(t) else 'd->d'
>       r = _umath_linalg.det(a, signature=signature)
E       RuntimeWarning: divide by zero encountered in det

/nix/store/afrric2fpgzq45bvpn5rabs26v02nn3w-python3.11-numpy-1.25.2/lib/python3.11/site-packages/numpy/linalg/linalg.py:2180: RuntimeWarning

To Reproduce
Steps to reproduce the behavior:

Expected behavior
A clear and concise description of what you expected to happen.

Data
If applicable, add the data leading to the issue (a minimum example is appreciated)

Screenshots
If applicable, add screenshots to help explain your problem.

System

  • OS: macos aarch64
  • scikit-rf version 0.29.1

Additional context
Add any other context about the problem here if relevant.
numpy version is: 1.25.2
python is 3.11

@ghost ghost changed the title darwin aarch64 skrf/calibration/tests/test_calibration.py failing with devide by zero (determinate calcualations) darwin aarch64 skrf/calibration/tests/test_calibration.py failing with divide by zero (determinate calcualations) Nov 9, 2023
@ghost ghost changed the title darwin aarch64 skrf/calibration/tests/test_calibration.py failing with divide by zero (determinate calcualations) darwin aarch64 skrf/calibration/tests/test_calibration.py failing with divide by zero (determinate calculations) Nov 9, 2023
@ghost
Copy link
Author

ghost commented Nov 10, 2023

on macos aarch64 this simplified code produces a divide by zero warning but runs fine on x64 linux -- similar to the failing unit tests above.

#!/usr/bin/env python3
import numpy as np
print(np.__version__)
a = np.array([[5.e-8+0.j, 1+0.j], [1+0.j, 5.e-8+0.j]])
print(a)
print(np.linalg.det(a))
./test.py
1.25.2
[[5.e-08+0.j 1.e+00+0.j]
 [1.e+00+0.j 5.e-08+0.j]]
/nix/store/rpdx49knxarbr4lmkwfi5l0461lyp6bd-python3-3.11.6-env/lib/python3.11/site-packages/numpy/linalg/linalg.py:2180: RuntimeWarning: divide by zero encountered in det
  r = _umath_linalg.det(a, signature=signature)
/nix/store/rpdx49knxarbr4lmkwfi5l0461lyp6bd-python3-3.11.6-env/lib/python3.11/site-packages/numpy/linalg/linalg.py:2180: RuntimeWarning: invalid value encountered in det
  r = _umath_linalg.det(a, signature=signature)

@pbsds
Copy link

pbsds commented Nov 10, 2023

note to future self: re-enable the failing test in nixpkgs if a fix is found

@jhillairet jhillairet added the Is it a bug? To be confirmed if it is a bug or not label Nov 11, 2023
@FranzForstmayr
Copy link
Collaborator

This should be reported to https://github.com/numpy/numpy itself, but this probably related numpy/numpy#22025.

@FranzForstmayr
Copy link
Collaborator

Nevertheless we could modify the unit test slightly to avoid this issue. I'm afraid we are not able to find the root cause here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Is it a bug? To be confirmed if it is a bug or not
Projects
None yet
Development

No branches or pull requests

3 participants