You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import tensorflow as tf
from tf_agents.environments import suite_gym
from tf_agents.environments import tf_py_environment
from tf_agents.environments import parallel_py_environment
import tensorflow as tf
from tf_agents.environments import suite_gym
from tf_agents.environments import tf_py_environment
from tf_agents.environments import parallel_py_environment
创建单个CartPole环境
def get_CartPole_Env():
return suite_gym.load("CartPole-v0")
创建并行环境
tf_env = tf_py_environment.TFPyEnvironment(
parallel_py_environment.ParallelPyEnvironment([get_CartPole_Env] * 4)
)
RuntimeError Traceback (most recent call last)
in <cell line: 11>()
10 # 创建并行环境
11 tf_env = tf_py_environment.TFPyEnvironment(
---> 12 parallel_py_environment.ParallelPyEnvironment([get_CartPole_Env] * 4)
13 )
6 frames
/usr/local/lib/python3.10/dist-packages/tf_agents/system/system_multiprocessing.py in get_context(method)
85 """
86 if not multiprocessing_core.initialized():
---> 87 raise RuntimeError(_NOT_INITIALIZED_ERROR)
88 return _rewrite_target_with_state(multiprocessing_core.get_context(method))
89
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'>)
The text was updated successfully, but these errors were encountered: