Skip to content

Make VectorArrays iterable #1068

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

Merged
merged 3 commits into from
Aug 28, 2020
Merged

Make VectorArrays iterable #1068

merged 3 commits into from
Aug 28, 2020

Conversation

sdrave
Copy link
Member

@sdrave sdrave commented Aug 26, 2020

Fixes #1056.

@sdrave sdrave added the pr:new-feature Introduces a new feature label Aug 26, 2020
@sdrave sdrave added this to the 2020.2 milestone Aug 26, 2020
@sdrave sdrave requested a review from pmli August 26, 2020 12:18
@pmli
Copy link
Member

pmli commented Aug 26, 2020

Should also BlockVectorArray and MPIVectorArray be adjusted?

Also, is it possible to test this somehow with hypothesis?

@codecov
Copy link

codecov bot commented Aug 26, 2020

Codecov Report

Merging #1068 into master will decrease coverage by 0.02%.
The diff coverage is 66.66%.

Impacted Files Coverage Δ
src/pymor/vectorarrays/list.py 83.86% <66.66%> (-0.80%) ⬇️
src/pymor/vectorarrays/numpy.py 84.81% <66.66%> (-0.31%) ⬇️

@sdrave
Copy link
Member Author

sdrave commented Aug 27, 2020

Should also BlockVectorArray and MPIVectorArray be adjusted?

Should not be required as IndexError should already be raised when the child arrays are indexed.

Also, is it possible to test this somehow with hypothesis?

I added a simple test.

@sdrave
Copy link
Member Author

sdrave commented Aug 27, 2020

@renefritze something bad is happening here with hypothesis. When I add

@reproduce_failure('5.19.0', b'AAAAAgA=')

I get

hypothesis.errors.DidNotReproduce: The shape of the test data has changed in some way from where this blob was defined. Are you sure you're running the same test?

Do you have the same issue?

Also,

py.test --pdb vectorarray.py

stops at

hypothesis.errors.MultipleFailures: Hypothesis found 2 distinct failures.

which is totally useless.

@renefritze
Copy link
Member

I can replicate that as is. Maybe it's a bug in your (older) hypothesis version.

r_milk01@29783eb890d5:/pymor$ pytest -k test_iter src/pymortests/vectorarray.py 
============================================================================ test session starts ============================================================================
platform linux -- Python 3.7.8, pytest-6.0.1, py-1.9.0, pluggy-0.13.1
rootdir: /pymor, configfile: setup.cfg
plugins: forked-1.3.0, xdist-2.0.0, cov-2.10.1, pycharm-0.7.0, parallel-0.1.0, timeout-1.4.2, hypothesis-5.28.0, memprof-0.2.0
collected 58 items / 57 deselected / 1 selected                                                                                                                             

src/pymortests/vectorarray.py F                                                                                                                                       [100%]

================================================================================= FAILURES ==================================================================================
_________________________________________________________________________________ test_iter _________________________________________________________________________________

    @pyst.given_vector_arrays()
>   @reproduce_failure('5.28.0', b'AAAAAgA=')
    def test_iter(vector_array):

src/pymortests/vectorarray.py:936: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/local/lib/python3.7/site-packages/hypothesis/core.py:610: in execute_once
    result = self.test_runner(data, run)
/usr/local/lib/python3.7/site-packages/hypothesis/executors.py:52: in default_new_style_executor
    return function(data)
/usr/local/lib/python3.7/site-packages/hypothesis/core.py:606: in run
    return test(*args, **kwargs)
src/pymortests/vectorarray.py:936: in test_iter
    @reproduce_failure('5.28.0', b'AAAAAgA=')
/usr/local/lib/python3.7/site-packages/hypothesis/core.py:529: in test
    result = self.test(*args, **kwargs)
src/pymortests/vectorarray.py:942: in test_iter
    assert np.all(almost_equal(w, v))
src/pymor/core/defaults.py:236: in defaults_wrapper
    return decorated_function(**kwargs)
src/pymor/algorithms/basic.py:67: in almost_equal
    X -= U
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = NumpyVectorArray([], NumpyVectorSpace(0)), other = NumpyVectorArray([], NumpyVectorSpace(0))

    def __isub__(self, other):
        assert self.dim == other.dim
        if self._refcount[0] > 1:
            self._deep_copy()
        other_dtype = other.base._array.dtype if other.is_view else other._array.dtype
        common_dtype = np.promote_types(self._array.dtype, other_dtype)
        if self._array.dtype != common_dtype:
            self._array = self._array.astype(common_dtype)
>       self._array[:self._len] -= other.base._array[other.ind] if other.is_view else other._array[:other._len]
E       ValueError: operands could not be broadcast together with shapes (2,0) (4,0) (2,0)

src/pymor/vectorarrays/numpy.py:313: ValueError
-------------------------------------------------------------------------------- Hypothesis ---------------------------------------------------------------------------------
Falsifying example: test_iter(
    vector_array=NumpyVectorArray([], NumpyVectorSpace(0)),
)
============================================================================= warnings summary ==============================================================================
/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:1148
  /usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:1148: PytestConfigWarning: Unknown config ini key: pep8ignore
  
    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

/usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:1148
  /usr/local/lib/python3.7/site-packages/_pytest/config/__init__.py:1148: PytestConfigWarning: Unknown config ini key: pep8maxlinelength
  
    self._warn_or_fail_if_strict("Unknown config ini key: {}\n".format(key))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================= memory consumption estimates ========================================================================
pymortests::vectorarray.py::test_iter  - 248.0 KB
========================================================================== short test summary info ==========================================================================
FAILED src/pymortests/vectorarray.py::test_iter - ValueError: operands could not be broadcast together with shapes (2,0) (4,0) (2,0)
=============================================================== 1 failed, 57 deselected, 2 warnings in 5.78s ================================================================

@sdrave
Copy link
Member Author

sdrave commented Aug 27, 2020

I can replicate that as is. Maybe it's a bug in your (older) hypothesis version.

Possibly. It was the same version CI used. With a newer version, reproduce_failure works. Still, without the decorator, --pdb stops at the wrong location.

@renefritze
Copy link
Member

I can replicate that as is. Maybe it's a bug in your (older) hypothesis version.

Possibly. It was the same version CI used.

I don't think so? This uses 5.28.0, you used 5.19.0.

@sdrave
Copy link
Member Author

sdrave commented Aug 27, 2020

I can replicate that as is. Maybe it's a bug in your (older) hypothesis version.

Possibly. It was the same version CI used.

I don't think so? This uses 5.28.0, you used 5.19.0.

Probably got it from here.

@sdrave
Copy link
Member Author

sdrave commented Aug 28, 2020

@pmli, can this be merged?

@sdrave sdrave merged commit 9416c7e into master Aug 28, 2020
@sdrave sdrave deleted the va_iteration branch August 28, 2020 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:new-feature Introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making VectorArrays iterable
3 participants