Skip to content

Commit

Permalink
Merge pull request #365 from PettingZoo-Team/seed_test_argument
Browse files Browse the repository at this point in the history
added seed test argument
  • Loading branch information
jkterry1 committed Apr 9, 2021
2 parents 827716f + 94df085 commit b6a386e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 9 additions & 2 deletions docs/dev_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,17 @@ The seed test takes in a function that creates a pettingzoo environment. For exa
from pettingzoo.test import seed_test
from pettingzoo.butterfly import pistonball_v4
env_fn = pistonball_v4.env
seed_test(env_fn, num_cycles=10)
seed_test(env_fn, num_cycles=10, test_kept_state=True)
```

The optional argument, `num_cycles`, indicates how long the environment will be run to check for determinism. Some environments only fail the test long after initialization.
Internally, there are two separate tests.

1. Do two separate environments give the same result after the environment is seeded?
2. Does a single environment give the same result after seed() then reset() is called?

The first optional argument, `num_cycles`, indicates how long the environment will be run to check for determinism. Some environments only fail the test long after initialization.

The second optional argument, `test_kept_state` allows the user to disable the second test. Some physics based environments fail this test due to barely detectable differences due to caches, etc, which are not important enough to matter.

### Max Cycles Test

Expand Down
4 changes: 2 additions & 2 deletions pettingzoo/test/pytest_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_module(name, env_module):
if "classic/" not in name:
parallel_api_test(env_module.parallel_env())

if "prospector" not in name:
seed_test(env_module.env, 50)
test_kept_state = "prospector" not in name
seed_test(env_module.env, 50, test_kept_state)

if "classic/" not in name:
max_cycles_test(env_module)
Expand Down
5 changes: 3 additions & 2 deletions pettingzoo/test/seed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ def test_environment_reset_deterministic(env1, num_cycles):
assert hash1 == hash2, "environments kept state after seed(42) and reset()"


def seed_test(env_constructor, num_cycles=10):
def seed_test(env_constructor, num_cycles=10, test_kept_state=True):
env1 = env_constructor()
test_environment_reset_deterministic(env1, num_cycles)
if test_kept_state:
test_environment_reset_deterministic(env1, num_cycles)
env2 = env_constructor()
base_seed = 42
env1.seed(base_seed)
Expand Down

0 comments on commit b6a386e

Please sign in to comment.