iminuit icon indicating copy to clipboard operation
iminuit copied to clipboard

ci: add pyodide build

Open henryiii opened this issue 1 year ago • 4 comments

Testing this.

henryiii avatar May 31 '24 16:05 henryiii

This is the only failing part, don't know if it's directly pyodide's fault:

  ______________________ test_NormalConstraint_bad_input_4 _______________________
      def test_NormalConstraint_bad_input_4():
  >       with pytest.raises(ValueError, match="positive definite"):
  E       Failed: DID NOT RAISE <class 'ValueError'>
  /home/runner/work/iminuit/iminuit/tests/test_cost.py:1573: Failed
  ______________________ test_NormalConstraint_bad_input_5 _______________________
      def test_NormalConstraint_bad_input_5():
          n = NormalConstraint(["a", "b"], [1, 2], [[1, 0], [0, 1]])
      
  >       with pytest.raises(ValueError, match="positive definite"):
  E       Failed: DID NOT RAISE <class 'ValueError'>
  /home/runner/work/iminuit/iminuit/tests/test_cost.py:1580: Failed
  ____________________________ test_positive_definite ____________________________
      def test_positive_definite():
          assert util.is_positive_definite([[1, 0], [0, 1]])
  >       assert not util.is_positive_definite([[1, 1], [1, 1]])
  E       assert not True
  E        +  where True = <function is_positive_definite at 0x2898118>([[1, 1], [1, 1]])
  E        +    where <function is_positive_definite at 0x2898118> = util.is_positive_definite
  /home/runner/work/iminuit/iminuit/tests/test_util.py:776: AssertionError

henryiii avatar Jun 08 '24 06:06 henryiii

This is the only failing part, don't know if it's directly pyodide's fault:

  ______________________ test_NormalConstraint_bad_input_4 _______________________
      def test_NormalConstraint_bad_input_4():
  >       with pytest.raises(ValueError, match="positive definite"):
  E       Failed: DID NOT RAISE <class 'ValueError'>
  /home/runner/work/iminuit/iminuit/tests/test_cost.py:1573: Failed
  ______________________ test_NormalConstraint_bad_input_5 _______________________
      def test_NormalConstraint_bad_input_5():
          n = NormalConstraint(["a", "b"], [1, 2], [[1, 0], [0, 1]])
      
  >       with pytest.raises(ValueError, match="positive definite"):
  E       Failed: DID NOT RAISE <class 'ValueError'>
  /home/runner/work/iminuit/iminuit/tests/test_cost.py:1580: Failed
  ____________________________ test_positive_definite ____________________________
      def test_positive_definite():
          assert util.is_positive_definite([[1, 0], [0, 1]])
  >       assert not util.is_positive_definite([[1, 1], [1, 1]])
  E       assert not True
  E        +  where True = <function is_positive_definite at 0x2898118>([[1, 1], [1, 1]])
  E        +    where <function is_positive_definite at 0x2898118> = util.is_positive_definite
  /home/runner/work/iminuit/iminuit/tests/test_util.py:776: AssertionError

The two errors seem related to util.is_positive_definite, which is implemented as follows:

    m = np.atleast_2d(m)
    if np.all(m.T == m):
        # maybe check this first https://en.wikipedia.org/wiki/Diagonally_dominant_matrix
        # and only try cholesky if that fails
        try:
            np.linalg.cholesky(m)
        except np.linalg.LinAlgError:
            return False
        return True
    return False

This returns true in those failing cases although it should return false. Apparently, np.linalg.cholesky(m) is not raising LinAlgError on Pyiodide.

HDembinski avatar Jun 10 '24 11:06 HDembinski

Perhaps the line np.linalg.cholesky(m) is non-blocking in Pyiodide. This code assumes it is blocking, like any other normal Python statement.

HDembinski avatar Jun 10 '24 11:06 HDembinski

I bet NumPy is compiled with exceptions turned off; maybe this function actually raises the exception from the compiled code?

I'll look into this and report to pyodide with what I find. The snippet above is extremely helpful, thank you!

henryiii avatar Jun 10 '24 14:06 henryiii

@henryiii I made a patch which may work around the failing test in pyodide, but I cannot test it because the pyodide build now fails because of some build-system issue. I am closing this PR now, you can reopen it when you find the time to finish this.

HDembinski avatar Jul 30 '24 16:07 HDembinski