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

TypeError: can't pickle _thread.lock objects on running highway-env/scripts/highway_planning.ipynb #192

Closed
shivambhandari99 opened this issue May 7, 2021 · 2 comments

Comments

@shivambhandari99
Copy link


TypeError Traceback (most recent call last)
in ()
16 # Run episode
17 for step in trange(env.unwrapped.config["duration"], desc="Running..."):
---> 18 action = agent.act(obs)
19 obs, reward, done, info = env.step(action)
20

20 frames
/usr/local/lib/python3.7/dist-packages/rl_agents/agents/tree_search/abstract.py in act(self, state)
95
96 def act(self, state):
---> 97 return self.plan(state)[0]
98
99 def save(self, filename):

/usr/local/lib/python3.7/dist-packages/rl_agents/agents/tree_search/abstract.py in plan(self, observation)
60 replanning_required = self.step(self.previous_actions)
61 if replanning_required:
---> 62 env = preprocess_env(self.env, self.config["env_preprocessors"])
63 actions = self.planner.plan(state=env, observation=observation)
64 else:

/usr/local/lib/python3.7/dist-packages/rl_agents/agents/common/factory.py in preprocess_env(env, preprocessor_configs)
109 env = preprocessor(preprocessor_config["args"])
110 else:
--> 111 env = preprocessor()
112 except AttributeError:
113 logger.warning("The environment does not have a {} method".format(preprocessor_config["method"]))

/usr/local/lib/python3.7/dist-packages/highway_env/envs/common/abstract.py in simplify(self)
335 :return: a simplified environment state
336 """
--> 337 state_copy = copy.deepcopy(self)
338 state_copy.road.vehicles = [state_copy.vehicle] + state_copy.road.close_vehicles_to(
339 state_copy.vehicle, self.PERCEPTION_DISTANCE)

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
159 copier = getattr(x, "deepcopy", None)
160 if copier:
--> 161 y = copier(memo)
162 else:
163 reductor = dispatch_table.get(cls)

/usr/local/lib/python3.7/dist-packages/highway_env/envs/common/abstract.py in deepcopy(self, memo)
408 for k, v in self.dict.items():
409 if k not in ['viewer', '_automatic_rendering_callback']:
--> 410 setattr(result, k, copy.deepcopy(v, memo))
411 else:
412 setattr(result, k, None)

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
148 copier = _deepcopy_dispatch.get(cls)
149 if copier:
--> 150 y = copier(x, memo)
151 else:
152 try:

/usr/lib/python3.7/copy.py in _deepcopy_method(x, memo)
246
247 def _deepcopy_method(x, memo): # Copy instance methods
--> 248 return type(x)(x.func, deepcopy(x.self, memo))
249 d[types.MethodType] = _deepcopy_method
250

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
178 y = x
179 else:
--> 180 y = _reconstruct(x, memo, *rv)
181
182 # If is its own copy, don't memoize.

/usr/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
279 if state is not None:
280 if deep:
--> 281 state = deepcopy(state, memo)
282 if hasattr(y, 'setstate'):
283 y.setstate(state)

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
148 copier = _deepcopy_dispatch.get(cls)
149 if copier:
--> 150 y = copier(x, memo)
151 else:
152 try:

/usr/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
239 memo[id(x)] = y
240 for key, value in x.items():
--> 241 y[deepcopy(key, memo)] = deepcopy(value, memo)
242 return y
243 d[dict] = _deepcopy_dict

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
178 y = x
179 else:
--> 180 y = _reconstruct(x, memo, *rv)
181
182 # If is its own copy, don't memoize.

/usr/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
279 if state is not None:
280 if deep:
--> 281 state = deepcopy(state, memo)
282 if hasattr(y, 'setstate'):
283 y.setstate(state)

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
148 copier = _deepcopy_dispatch.get(cls)
149 if copier:
--> 150 y = copier(x, memo)
151 else:
152 try:

/usr/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
239 memo[id(x)] = y
240 for key, value in x.items():
--> 241 y[deepcopy(key, memo)] = deepcopy(value, memo)
242 return y
243 d[dict] = _deepcopy_dict

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
178 y = x
179 else:
--> 180 y = _reconstruct(x, memo, *rv)
181
182 # If is its own copy, don't memoize.

/usr/lib/python3.7/copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy)
279 if state is not None:
280 if deep:
--> 281 state = deepcopy(state, memo)
282 if hasattr(y, 'setstate'):
283 y.setstate(state)

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
148 copier = _deepcopy_dispatch.get(cls)
149 if copier:
--> 150 y = copier(x, memo)
151 else:
152 try:

/usr/lib/python3.7/copy.py in _deepcopy_dict(x, memo, deepcopy)
239 memo[id(x)] = y
240 for key, value in x.items():
--> 241 y[deepcopy(key, memo)] = deepcopy(value, memo)
242 return y
243 d[dict] = _deepcopy_dict

/usr/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
167 reductor = getattr(x, "reduce_ex", None)
168 if reductor:
--> 169 rv = reductor(4)
170 else:
171 reductor = getattr(x, "reduce", None)

TypeError: can't pickle _thread.lock objects

@eleurent
Copy link
Collaborator

eleurent commented May 7, 2021

Hi, thank you for the feedback!
I could reproduce the issue, I'll investigate.
It might be due to a difference in python 3.7´s deepcopy.

@eleurent
Copy link
Collaborator

Update: it is not due to a difference in python 3.7's deepcopy as I thought.
And what's more: I can only reproduce the issue on colab, but if I run the notebook on a local python 3.7 interpreter everything it works. The plot thickens!

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

2 participants