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

[Proposal] add utils.check_environments_match #575

Closed
1 task done
Kallinteris-Andreas opened this issue Jun 28, 2023 · 1 comment
Closed
1 task done

[Proposal] add utils.check_environments_match #575

Kallinteris-Andreas opened this issue Jun 28, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@Kallinteris-Andreas
Copy link
Collaborator

Proposal

Add:

def check_environments_match(
    env_a: gym.Env,
    env_b: gym.Env,
    num_steps: int,
    seed: int = None,
    skip_obs: bool = False,
    skip_rew: bool = False,
    skip_terminal: bool = False,
    skip_truncated: bool = False,
    skip_info: bool = False,
):
    """Checks if the environments `env_a` & `env_b` are identical.

    Args:
        num_steps: number of timesteps to test for, setting to 0 tests only resetting.
        skip_obs: If `True` it does not check for equivalence of the observation.
        skip_rew: If `True` it does not check for equivalence of the observation.
        skip_terminal: If `True` it does not check for equivalence of the observation.
        skip_truncated: If `True` it does not check for equivalence of the observation.
        skip_info: If `True` it does not check for equivalence of the observation.
    """
    assert env_a.action_space == env_b.action_space
    assert skip_obs or env_b.observation_space == env_b.observation_space

    obs_a, info_a = env_a.reset(seed)
    obs_b, info_b = env_b.reset(seed)
    assert skip_obs or data_equivalence(obs_a, obs_b)
    assert skip_info or data_equivalence(info_a, info_b)
    env_a.action_space.seed(seed)
    for _ in range(num_steps):
        action = env_a.action_space.sample()
        obs_a, rew_a, terminal_a, truncated_a, info_a = env_a.step(action)
        obs_b, rew_b, terminal_b, truncated_b, info_b = env_b.step(action)
        assert skip_obs or data_equivalence(obs_a, obs_b)
        assert skip_rew or data_equivalence(rew_a, rew_b)
        assert skip_terminal or terminal_a == terminal_b
        assert skip_truncated or truncated_a == truncated_b
        assert skip_info or data_equivalence(info_a, info_b)

        if terminal_a or truncated_a:
            obs_a, info_a = env_a.reset(seed)
            obs_b, info_b = env_b.reset(seed)
            assert skip_obs or data_equivalence(obs_a, obs_b)
            assert skip_info or data_equivalence(info_a, info_b)

Note: pettingzoo has

https://github.com/Farama-Foundation/PettingZoo/blob/969c079164e6fd84b4878f26debfeff644aa2786/pettingzoo/test/seed_test.py#L16

Motivation

It could enable:

env_v4 = gym.make('HalfCheetah-v4')
env_v5 = gym.make("HalfCheetah-v5")
check_environments_match(env_v4, env_v5, 1000,

Or for any new environment revision.

Pitch

No response

Alternatives

I could simply keep it in test_mujoco_v5.py

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@Kallinteris-Andreas Kallinteris-Andreas added the enhancement New feature or request label Jun 28, 2023
@pseudo-rnd-thoughts
Copy link
Member

I think this is a good idea, thanks for the proposal.
At least internally, this would be helpful to assess if a version change is required

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants