pyPESTO icon indicating copy to clipboard operation
pyPESTO copied to clipboard

Flaky test `test_pipeline[Metropolis-rosenbrock]`

Open dweindl opened this issue 4 years ago • 0 comments

Can this be handled more gracefully, or can we add some random seed, so this does not happen in the test? https://github.com/ICB-DCM/pyPESTO/runs/5881283280?check_suite_focus=true

_____________________ test_pipeline[Metropolis-rosenbrock] _____________________

sampler = <pypesto.sample.metropolis.MetropolisSampler object at 0x7efeebbeeca0>
problem = <pypesto.problem.Problem object at 0x7efeebbe4d60>

    def test_pipeline(sampler, problem):
        """Check that a typical pipeline runs through."""
        # optimization
        optimizer = optimize.ScipyOptimizer(options={'maxiter': 10})
        result = optimize.minimize(
            problem=problem,
            n_starts=3,
            optimizer=optimizer,
            filename=None,
            progress_bar=False,
        )
    
        # sample
        result = sample.sample(
            problem=problem,
            sampler=sampler,
            n_samples=100,
            result=result,
            filename=None,
        )
        # remove warnings in test/sample/test_sample.
        # Warning here: pypesto/visualize/sampling.py:1104
        # geweke test
        sample.geweke_test(result=result)
    
        # some plot
>       visualize.sampling_1d_marginals(result)

test/sample/test_sample.py:230: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pypesto/visualize/sampling.py:1091: in sampling_1d_marginals
    sns.histplot(
.tox/base/lib/python3.8/site-packages/seaborn/distributions.py:1462: in histplot
    p.plot_univariate_histogram(
.tox/base/lib/python3.8/site-packages/seaborn/distributions.py:418: in plot_univariate_histogram
    densities = self._compute_univariate_density(
.tox/base/lib/python3.8/site-packages/seaborn/distributions.py:326: in _compute_univariate_density
    density, support = estimator(observations, weights=weights)
.tox/base/lib/python3.8/site-packages/seaborn/_statistics.py:187: in __call__
    return self._eval_univariate(x1, weights)
.tox/base/lib/python3.8/site-packages/seaborn/_statistics.py:146: in _eval_univariate
    support = self.define_support(x, cache=False)
.tox/base/lib/python3.8/site-packages/seaborn/_statistics.py:119: in define_support
    support = self._define_support_univariate(x1, weights)
.tox/base/lib/python3.8/site-packages/seaborn/_statistics.py:91: in _define_support_univariate
    kde = self._fit(x, weights)
.tox/base/lib/python3.8/site-packages/seaborn/_statistics.py:137: in _fit
    kde = stats.gaussian_kde(fit_data, **fit_kws)
.tox/base/lib/python3.8/site-packages/scipy/stats/_kde.py:207: in __init__
    self.set_bandwidth(bw_method=bw_method)
.tox/base/lib/python3.8/site-packages/scipy/stats/_kde.py:555: in set_bandwidth
    self._compute_covariance()
.tox/base/lib/python3.8/site-packages/scipy/stats/_kde.py:567: in _compute_covariance
    self._data_inv_cov = linalg.inv(self._data_covariance)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = array([[0.]]), overwrite_a = False, check_finite = True

    def inv(a, overwrite_a=False, check_finite=True):
        """
        Compute the inverse of a matrix.
    
        Parameters
        ----------
        a : array_like
            Square matrix to be inverted.
        overwrite_a : bool, optional
            Discard data in `a` (may improve performance). Default is False.
        check_finite : bool, optional
            Whether to check that the input matrix contains only finite numbers.
            Disabling may give a performance gain, but may result in problems
            (crashes, non-termination) if the inputs do contain infinities or NaNs.
    
        Returns
        -------
        ainv : ndarray
            Inverse of the matrix `a`.
    
        Raises
        ------
        LinAlgError
            If `a` is singular.
        ValueError
            If `a` is not square, or not 2D.
    
        Examples
        --------
        >>> from scipy import linalg
        >>> a = np.array([[1., 2.], [3., 4.]])
        >>> linalg.inv(a)
        array([[-2. ,  1. ],
               [ 1.5, -0.5]])
        >>> np.dot(a, linalg.inv(a))
        array([[ 1.,  0.],
               [ 0.,  1.]])
    
        """
        a1 = _asarray_validated(a, check_finite=check_finite)
        if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
            raise ValueError('expected square matrix')
        overwrite_a = overwrite_a or _datacopied(a1, a)
        # XXX: I found no advantage or disadvantage of using finv.
    #     finv, = get_flinalg_funcs(('inv',),(a1,))
    #     if finv is not None:
    #         a_inv,info = finv(a1,overwrite_a=overwrite_a)
    #         if info==0:
    #             return a_inv
    #         if info>0: raise LinAlgError, "singular matrix"
    #         if info<0: raise ValueError('illegal value in %d-th argument of '
    #                                     'internal inv.getrf|getri'%(-info))
        getrf, getri, getri_lwork = get_lapack_funcs(('getrf', 'getri',
                                                      'getri_lwork'),
                                                     (a1,))
        lu, piv, info = getrf(a1, overwrite_a=overwrite_a)
        if info == 0:
            lwork = _compute_lwork(getri_lwork, a1.shape[0])
    
            # XXX: the following line fixes curious SEGFAULT when
            # benchmarking 500x500 matrix inverse. This seems to
            # be a bug in LAPACK ?getri routine because if lwork is
            # minimal (when using lwork[0] instead of lwork[1]) then
            # all tests pass. Further investigation is required if
            # more such SEGFAULTs occur.
            lwork = int(1.01 * lwork)
            inv_a, info = getri(lu, piv, lwork=lwork, overwrite_lu=1)
        if info > 0:
>           raise LinAlgError("singular matrix")
E           numpy.linalg.LinAlgError: singular matrix

.tox/base/lib/python3.8/site-packages/scipy/linalg/_basic.py:968: LinAlgError

dweindl avatar Apr 08 '22 07:04 dweindl