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

Unable to load multiprocessing context for my validated custom gym environment. #845

Open
Yash271100 opened this issue Jun 12, 2023 · 1 comment

Comments

@Yash271100
Copy link

This is the code I am implementing: -
Along with other dependencies;
from tf_agents.environments import ParallelPyEnvironment

num_cpu = 4;
def GetmyENV():
      return PyENV
parallel_py_env = ParallelPyEnvironment([GetmyENV]*int(num_cpu))

The RuntimeError I get is

RuntimeError: Unable to load multiprocessing context.

Please ensure that you properly initialize your program by wrapping your main()
call:

def main(argv):
  ...

if __name__ == '__main__':
  tf_agents.system.multiprocessing.handle_main(main, extra_state_savers=...)

or, if using absl.app:

if __name__ == '__main__':
  tf_agents.system.multiprocessing.handle_main(
      functools.partial(absl.app.run, main), extra_state_savers=...)


For unit tests, this also means wrapping your test.main using handle_test_main:

if __name__ == '__main__':
  tf_agents.system.multiprocessing.handle_test_main(
      tf.test.main, extra_state_savers=...)

or

if __name__ == '__main__':
  tf_agents.system.multiprocessing.handle_test_main(
      tf_agents.utils.test_utils.main, extra_state_savers=...)

If you are in interactive mode (e.g. python console, ipython, jupyter notebook)
use:

tf_agents.system.multiprocessing.enable_interactive_mode(
    extra_state_savers=...)

For more details on state savers, see the docstrings for
`tf_agents.multiprocessing.handle_*` and:

https://pythonspeed.com/articles/python-multiprocessing/

  In call to configurable 'ParallelPyEnvironment' (<class 'tf_agents.environments.parallel_py_environment.ParallelPyEnvironment'>)

I do think my PyEnvironment does not have any issues as the validation was successful. However, my initialization might be incorrect. Kindly help me with this.

@Yash271100
Copy link
Author

I get the same error using the standard CardGameEnv() explained in the tutorial provided by Tensorflow.

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

1 participant