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

Add __setattr__ to wrappers. Fixes #1176 #1180

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Feb 10, 2024

  1. Add __setattr__ to wrappers. Fixes Farama-Foundation#1176

    Adding this ensures that variables get set to the appropriate
    location. By default, any public value set by the wrapper is sent
    to the env to be set there instead of on the wrapper. If a variable
    is meant to be set by the wrapper, it should be listed in the
    _local_vars class variable of the wrapper. This is not ideal, but
    seems to be the most reasonable design.
    
    An example of needing to specify which vars to keep locally is here:
    https://python-patterns.guide/gang-of-four/decorator-pattern/#implementing-dynamic-wrapper
    The solution is to list which vars should be in the wrapper and
    check them when setting a value. That is the approach used in this
    commit, but more generalized.
    
    In line with __getattr__, private values cannot be set on underlying
    envs. There are two exceptions:
    _cumulative_rewards was previously exempted in __getattr__ because it
    is used by many envs.
    _skip_agent_selection is added because is used byt the dead step
    handling. If a wrapper can't set this, that functionality will break.
    dm-ackerman committed Feb 10, 2024
    Configuration menu
    Copy the full SHA
    c082b23 View commit details
    Browse the repository at this point in the history
  2. Add tests to validate fix of 1176

    These check that the wrapper functions of __getattr__ and
    __setattr__ work as intended
    dm-ackerman committed Feb 10, 2024
    Configuration menu
    Copy the full SHA
    b6fe82f View commit details
    Browse the repository at this point in the history