-
Notifications
You must be signed in to change notification settings - Fork 21
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 pickle tests #53
Add pickle tests #53
Conversation
# Conflicts: # .github/workflows/optional-install-test.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Elliot for doing this, looks impressive as far
# Without EzPickle:_register_bsuite_envs.<locals>._make_bsuite_env cannot be pickled | ||
# With EzPickle: maximum recursion limit reached | ||
FAILING_PICKLE_ENVS = [ | ||
"bsuite/bandit_noise-v0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have found this before. It is generally because one of the classes implemented __getattr__
.
Is there a particular parameter that is missing?
I suspect the issue is that the environment only defines a variable on reset
or another function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll go check that individual env and see. But what would we be able to do to fix it, besides submitting a PR to their repo? I guess we could in the compatibility wrapper specifically check if it’s that env or if an env has that specific variable not defined in init, and then do whatever modifications are required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In short, we can't fix it. The environments failing use a wrapper that contains
def __getattr__(self, attr):
return getattr(self._env, attr)
The problem exists when _env
doesn't exist in the wrapper, i.e., when a staticmethod is existed (__setstate__
) then this causes an infinite loop to occur of __getattr__("static_method")
-> __getattr__("_env")
-> __getattr__("_env")
-> ad infinitum
The second issue is that dm don't seem to be maintaining the project anymore.
The solution is simple
def __getattr__(self, attr):
if "_env" in self.__dict__:
return getattr(self._env, attr)
else:
return super().__getattribute__(attr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put a PR up by any chance? Even if they don't' end up merging it I feel like we might as well try, you seem to understand this stuff better than me though, I'm not sure I'd be able to explain it well or respond to any questions about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/test_dm_control.py
Outdated
@@ -103,6 +104,36 @@ def test_seeding(env_id): | |||
env_2.close() | |||
|
|||
|
|||
@pytest.mark.skip( | |||
reason="Fatal Python error: Segmentation fault (with or without EzPickle" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know the source of this? Mujoco is the probable cause which we can probably get solved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's to do with pluggy?
/Users/elliottower/anaconda3/envs/shimmy/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py --target test_dm_control.py::test_pickle
Testing started at 1:17 PM ...
Launching pytest with arguments test_dm_control.py::test_pickle --no-header --no-summary -q in /Users/elliottower/Documents/GitHub/Shimmy/tests
============================= test session starts ==============================
collecting ... collected 85 items
test_dm_control.py::test_pickle[dm_control/acrobot-swingup-v0] Fatal Python error: Segmentation fault
Current thread 0x000000011149c600 (most recent call first):
File "/Users/elliottower/Documents/GitHub/Shimmy/tests/test_dm_control.py", line 114 in test_pickle
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/python.py", line 192 in pytest_pyfunc_call
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/python.py", line 1761 in runtest
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 166 in pytest_runtest_call
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 259 in <lambda>
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 338 in from_call
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 258 in call_runtest_hook
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 219 in call_and_report
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 130 in runtestprotocol
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/runner.py", line 111 in pytest_runtest_protocol
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/main.py", line 347 in pytest_runtestloop
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/main.py", line 322 in _main
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/main.py", line 268 in wrap_session
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/main.py", line 315 in pytest_cmdline_main
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_callers.py", line 39 in _multicall
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_manager.py", line 80 in _hookexec
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/pluggy/_hooks.py", line 265 in __call__
File "/Users/elliottower/anaconda3/envs/shimmy/lib/python3.9/site-packages/_pytest/config/__init__.py", line 164 in main
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm/_jb_pytest_runner.py", line 51 in <module>
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
@pseudo-rnd-thoughts any idea about these? It looks like DM lab seeding doesn't work, and there was some issue with pickling: https://github.com/Farama-Foundation/Shimmy/actions/runs/4567097924/jobs/8060464686 Also I've run the pre-commit hooks locally and it passed previously but now for some reason the CI pre-commit hooks are failing with the meltingpot compatibility file and tests? If you look up a few runs it was passing but I don't think I changed the file. I uninstalled pre-commit and re-installed it and it didn't change anything. Tried reverting to the original changes but it now won't let me commit without it re-formatting things. Not sure if this issue has happened before? Edit: got it working by commenting out isort on the file, not ideal but the problem persisted even after removing and reinstalling pre-commit hooks. |
About the seeding for DM lab, it seems it is possible (link), but our tests here are returning different observations and failing the seed test. I commented out the observations and it still failed with other errors. I think the problem then must be that we are not properly seeding it in the wrapper. |
Checked over my own code to ensure there weren't any obvious typos or mistakes, tests are passing now so it should be in a good state to merge at least from what I can see. |
@@ -48,6 +48,10 @@ def reset( | |||
self._env.reset(seed=seed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we had solved the seeding issue in dm-lab @jjshoots
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure but I think this should be a separate PR with the other dm-lab fixes, this is just for adding pickle tests and turns out the pickle tests for dm lab don't seem to work and are blocked so can just update the seed/pickle stuff for dm-lab later
# Without EzPickle:_register_bsuite_envs.<locals>._make_bsuite_env cannot be pickled | ||
# With EzPickle: maximum recursion limit reached | ||
FAILING_PICKLE_ENVS = [ | ||
"bsuite/bandit_noise-v0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks elliot, I agree, just a couple of points about |
Description
This PR adds tests to ensure that each environment type can be saved and loaded via pickling. It adds EzPickle support to those environments which cannot be pickled, such as OpenSpiel.
Note: I made this as a fork of the previous PR adding dockerfile/CI support, could revert the commit and make a new branch but figured this was fine as that was merged.
Fixes # (issue), Depends on # (pull request)
Type of change
Screenshots
Checklist:
pre-commit
checks withpre-commit run --all-files
(seeCONTRIBUTING.md
instructions to set it up)pytest -v
and no errors are present.pytest -v
has generated that are related to my code to the best of my knowledge.