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

[Bug] Generation Strategy equality check error without call to repr #2226

Closed
madeline-scyphers opened this issue Feb 28, 2024 · 1 comment
Closed
Assignees

Comments

@madeline-scyphers
Copy link
Contributor

madeline-scyphers commented Feb 28, 2024

I came across a case where if I check if two GenerationStetegys are the same without some call to their repr (print since no str method, logging, debug break implicitly calling it for you, etc.) then it errors during the eq check with a RuntimeError: dictionary changed size during iteration

Ax 0.3.6
os - linux, mac, and windows (found in my CI job)
python - 3.10

Traceback
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:29: in _type_safe_equals
    return eq_func(self, other)
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/base.py:32: in __eq__
    return object_attribute_dicts_equal(
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:113: in object_attribute_dicts_equal
    unequal_type, unequal_value = object_attribute_dicts_find_unequal_fields(
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:200: in object_attribute_dicts_find_unequal_fields
    equal = isinstance(other_val, list) and same_elements(one_val, other_val)
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:60: in same_elements
    elif item1 == item2:
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/modelbridge/generation_node.py:778: in __eq__
    return SortableBase.__eq__(self, other=other)
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:29: in _type_safe_equals
    return eq_func(self, other)
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/base.py:32: in __eq__
    return object_attribute_dicts_equal(
../../../../mambaforge/envs/boa-dev/lib/python3.11/site-packages/ax/utils/common/equality.py:113: in object_attribute_dicts_equal
    unequal_type, unequal_value = object_attribute_dicts_find_unequal_fields(

Here are some example functions that produce the error and avoid the error.

def test_gen_strat1():
    """Errors similar to above traceback"""
    gs1 = GenerationStrategy(
        steps=[
            GenerationStep(model=Models.SOBOL, num_trials=5),
            GenerationStep(model=Models.GPEI, num_trials=-1),
        ])
    gs2 = GenerationStrategy(
        steps=[
            GenerationStep(model=Models.SOBOL, num_trials=5),
            GenerationStep(model=Models.GPEI, num_trials=-1),
        ])
    assert gs1 == gs2


def test_gen_strat2():
    """No error"""
    gs1 = GenerationStrategy(
        steps=[
            GenerationStep(model=Models.SOBOL, num_trials=5),
            GenerationStep(model=Models.GPEI, num_trials=-1),
        ])
    gs2 = GenerationStrategy(
        steps=[
            GenerationStep(model=Models.SOBOL, num_trials=5),
            GenerationStep(model=Models.GPEI, num_trials=-1),
        ])
    print(gs1)
    print(gs2)
    assert gs1 == gs2

I believe it has to do with the repr in GenerationStrategy, specifically the part that calls the name property. If I make a subclass and remove that, then the printing no longer stops the error.

@madeline-scyphers madeline-scyphers changed the title Generation Strategy equality check error without call to repr [Bug] Generation Strategy equality check error without call to repr Feb 28, 2024
@mgrange1998
Copy link
Contributor

Thanks for the heads up! I root caused the issue and have a pull request up to fix it (#2229 , and will land it shortly.

@mgrange1998 mgrange1998 self-assigned this Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants