ray-project / tutorial

778 stars 212 forks source link

Unbound Local Error when running rllib_exercise02 #131

Closed stephen-mcaleer closed 5 years ago

stephen-mcaleer commented 5 years ago

I get this error when trying to create a PPO agent


UnboundLocalError Traceback (most recent call last)

in 6 config['num_cpus_per_worker'] = 0 # This avoids running out of resources in the notebook environment when this cell is re-executed 7 ----> 8 agent = PPOTrainer(config, 'CartPole-v0') ~/anaconda3/lib/python3.7/site-packages/ray/rllib/agents/trainer.py in __init__(self, config, env, logger_creator) 309 logger_creator = default_logger_creator 310 --> 311 Trainable.__init__(self, config, logger_creator) 312 313 @classmethod ~/anaconda3/lib/python3.7/site-packages/ray/tune/trainable.py in __init__(self, config, logger_creator) 86 self._iterations_since_restore = 0 87 self._restored = False ---> 88 self._setup(copy.deepcopy(self.config)) 89 self._local_ip = ray.services.get_node_ip_address() 90 ~/anaconda3/lib/python3.7/site-packages/ray/rllib/agents/trainer.py in _setup(self, config) 422 423 with get_scope(): --> 424 self._init(self.config, self.env_creator) 425 426 # Evaluation related ~/anaconda3/lib/python3.7/site-packages/ray/rllib/agents/trainer_template.py in _init(self, config, env_creator) 61 policy = get_policy_class(config) 62 self.local_evaluator = self.make_local_evaluator( ---> 63 env_creator, policy) 64 self.remote_evaluators = self.make_remote_evaluators( 65 env_creator, policy, config["num_workers"]) ~/anaconda3/lib/python3.7/site-packages/ray/rllib/agents/trainer.py in make_local_evaluator(self, env_creator, policy, extra_config) 620 config["local_evaluator_tf_session_args"] 621 }), --> 622 extra_config or {})) 623 624 @DeveloperAPI ~/anaconda3/lib/python3.7/site-packages/ray/rllib/agents/trainer.py in _make_evaluator(self, cls, env_creator, policy, worker_index, config) 845 remote_env_batch_wait_ms=config["remote_env_batch_wait_ms"], 846 soft_horizon=config["soft_horizon"], --> 847 _fake_sampler=config.get("_fake_sampler", False)) 848 849 @override(Trainable) ~/anaconda3/lib/python3.7/site-packages/ray/rllib/evaluation/policy_evaluator.py in __init__(self, env_creator, policy, policy_mapping_fn, policies_to_train, tf_session_creator, batch_steps, batch_mode, episode_horizon, preprocessor_pref, sample_async, compress_observations, num_envs, observation_filter, clip_rewards, clip_actions, env_config, model_config, policy_config, worker_index, monitor_path, log_dir, log_level, callbacks, input_creator, input_evaluation, output_creator, remote_worker_envs, remote_env_batch_wait_ms, soft_horizon, _fake_sampler) 319 with self.tf_sess.as_default(): 320 self.policy_map, self.preprocessors = \ --> 321 self._build_policy_map(policy_dict, policy_config) 322 else: 323 self.policy_map, self.preprocessors = self._build_policy_map( ~/anaconda3/lib/python3.7/site-packages/ray/rllib/evaluation/policy_evaluator.py in _build_policy_map(self, policy_dict, policy_config) 725 if tf: 726 with tf.variable_scope(name): --> 727 policy_map[name] = cls(obs_space, act_space, merged_conf) 728 else: 729 policy_map[name] = cls(obs_space, act_space, merged_conf) ~/anaconda3/lib/python3.7/site-packages/ray/rllib/policy/tf_policy_template.py in __init__(self, obs_space, action_space, config, existing_inputs) 107 grad_stats_fn=grad_stats_fn, 108 before_loss_init=before_loss_init_wrapper, --> 109 existing_inputs=existing_inputs) 110 111 if after_init: ~/anaconda3/lib/python3.7/site-packages/ray/rllib/policy/dynamic_tf_policy.py in __init__(self, obs_space, action_space, config, loss_fn, stats_fn, grad_stats_fn, before_loss_init, make_action_sampler, existing_inputs, get_batch_divisibility_req) 90 "prev_actions": prev_actions, 91 "prev_rewards": prev_rewards, ---> 92 "is_training": self._get_is_training_placeholder(), 93 } 94 ~/anaconda3/lib/python3.7/site-packages/ray/rllib/policy/tf_policy.py in _get_is_training_placeholder(self) 310 """ 311 if not hasattr(self, "_is_training"): --> 312 self._is_training = tf.placeholder_with_default(False, ()) 313 return self._is_training 314 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/array_ops.py in placeholder_with_default(input, shape, name) 2091 A `Tensor`. Has the same type as `input`. 2092 """ -> 2093 return gen_array_ops.placeholder_with_default(input, shape, name) 2094 2095 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/gen_array_ops.py in placeholder_with_default(input, shape, name) 5923 shape = _execute.make_shape(shape, "shape") 5924 _, _, _op = _op_def_lib._apply_op_helper( -> 5925 "PlaceholderWithDefault", input=input, shape=shape, name=name) 5926 _result = _op.outputs[:] 5927 _inputs_flat = _op.inputs ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py in _apply_op_helper(self, op_type_name, name, **keywords) 509 dtype=dtype, 510 as_ref=input_arg.is_ref, --> 511 preferred_dtype=default_dtype) 512 except TypeError as err: 513 if dtype is None: ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in internal_convert_to_tensor(value, dtype, name, as_ref, preferred_dtype, ctx, accept_symbolic_tensors) 1173 1174 if ret is None: -> 1175 ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) 1176 1177 if ret is NotImplemented: ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_tensor_conversion_function(v, dtype, name, as_ref) 302 as_ref=False): 303 _ = as_ref --> 304 return constant(v, dtype=dtype, name=name) 305 306 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in constant(value, dtype, shape, name) 243 """ 244 return _constant_impl(value, dtype, shape, name, verify_shape=False, --> 245 allow_broadcast=True) 246 247 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/constant_op.py in _constant_impl(value, dtype, shape, name, verify_shape, allow_broadcast) 281 tensor_util.make_tensor_proto( 282 value, dtype=dtype, shape=shape, verify_shape=verify_shape, --> 283 allow_broadcast=allow_broadcast)) 284 dtype_value = attr_value_pb2.AttrValue(type=tensor_value.tensor.dtype) 285 const_tensor = g.create_op( ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast) 571 raise TypeError( 572 "Element type not supported in TensorProto: %s" % numpy_dtype.name) --> 573 append_fn(tensor_proto, proto_values) 574 575 return tensor_proto tensorflow/python/framework/fast_tensor_util.pyx in tensorflow.python.framework.fast_tensor_util.AppendBoolArrayToTensorProto() ~/anaconda3/lib/python3.7/site-packages/numpy/lib/type_check.py in asscalar(***failed resolving arguments***) 545 warnings.warn('np.asscalar(a) is deprecated since NumPy v1.16, use ' 546 'a.item() instead', DeprecationWarning, stacklevel=1) --> 547 return a.item() 548 549 #----------------------------------------------------------------------------- UnboundLocalError: local variable 'a' referenced before assignment
stephen-mcaleer commented 5 years ago

Fixed by using python 3.6 instead of 3.7