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

#3540 causes RecursionError in particular draw pattern #3560

Closed
rsokl opened this issue Jan 25, 2023 · 1 comment · Fixed by #3569
Closed

#3540 causes RecursionError in particular draw pattern #3560

rsokl opened this issue Jan 25, 2023 · 1 comment · Fixed by #3569
Assignees
Labels
bug something is clearly wrong here

Comments

@rsokl
Copy link
Contributor

rsokl commented Jan 25, 2023

#3540 introduces a change that causes a RecursionError in MyGrad's test suite.

This is a weird bug. It seems to be specific to drawing from an array-based strategy that spans multiple lines and that includes an identity mapping (I said it was weird!).

The following tests pass (note the xfail)

import pytest

import hypothesis.extra.numpy as hnp
import hypothesis.strategies as st
from hypothesis import given

@given(st.data())
def test_one_line_identity_passes(data):
    x = data.draw(hnp.arrays(shape=(2,), dtype=float).map(lambda x: x))


@pytest.mark.xfail(raises=RecursionError, strict=True)
@given(st.data())
def test_multiline_identity_fails(data):
    x = data.draw(
        hnp.arrays(
            shape=(2,),
            dtype=float,
        ).map(lambda x: x)
    )


@given(st.data())
def test_multiline_non_identity_passes(data):
    x = data.draw(
        hnp.arrays(
            shape=(2,),
            dtype=float,
        ).map(lambda x: 1 * x)
    )
    
    
@given(st.data())
def test_multiline_non_array_passes(data):
    x = data.draw(
        st.lists(
            st.integers(
                1,
                5,
            )
        ).map(lambda x: x)
    )
@rsokl rsokl added the bug something is clearly wrong here label Jan 25, 2023
@rsokl rsokl changed the title #3540 causes RecursionError in MyGrad's test suite #3540 causes RecursionError in particular draw pattern Jan 25, 2023
@Zac-HD Zac-HD self-assigned this Jan 25, 2023
copybara-service bot pushed a commit to tensorflow/probability that referenced this issue Jan 31, 2023
…ense thing

1. Avoid infinite recursion in hypothesis-based tests by pinning to 6.64.0
Possibly related to HypothesisWorks/hypothesis#3560

2. Pin to an earlier Jax release until a jax/tf co-install issue is resolved (related to tensorflow/tensorflow#59425, tensorflow/tensorflow#59478).

3. Patch in Jacob's cl/505883596, addressing some recent 3p license requirements in build files and dodging a resulting copybara/oss breakage by importing brain's py_comment copybara function.

PiperOrigin-RevId: 506050497
@Zac-HD
Copy link
Member

Zac-HD commented Feb 4, 2023

Wow, finally sniped this and feel kinda stupid: the following call can recurse, but doesn't copy the stack used for cycle-detection.

p = RepresentationPrinter()
p.known_object_printers = self.known_object_printers
p.repr_call("_" * self.output_width, args, kwargs, force_split=False)

Bleeding obvious once you see it, and it's a single-line fix🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something is clearly wrong here
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants