AminHP / gym-anytrading

The most simple, flexible, and comprehensive OpenAI Gym trading environment (Approved by OpenAI Gym)
MIT License
2.09k stars 459 forks source link

Tensor conversion error when trying to use TF-Agents with Anytrading #95

Closed jimdog99 closed 9 months ago

jimdog99 commented 9 months ago

I have been working on a tf_agent test program using latest anytrading environment.

Once I got past the py_environment compatibility issues and got it to load correctly, I ran into the following problem...

I have a line of code in the replaybuffer that does the following: time_step = environment.current_time_step()

But I get back the following error when this is run against the anytrading environment...

File "/home/michael/test9.py", line 196, in timestamp_data time_step = environment.current_time_step() File "/usr/local/lib/python3.10/dist-packages/tf_agents/environments/tf_environment.py", line 196, in current_time_step return self._current_time_step() File "/usr/local/lib/python3.10/dist-packages/tf_agents/environments/tf_py_environment.py", line 240, in _current_time_step outputs = tf.numpy_function( File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler raise e.with_traceback(filtered_tb) from None File "/usr/local/lib/python3.10/dist-packages/tensorflow/python/framework/constant_op.py", line 102, in convert_to_eager_tensor return ops.EagerTensor(value, ctx.device_name, dtype) ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type Positions).

This seems to be related to the Positions class which holds the current and past Positions. Any ideas?

Using latest tensorflow 2.14 with tf-agents 0.18 on python 3.10 with gymnasium 0.29.1

AminHP commented 9 months ago

Could you provide a minimal code to reproduce the problem?

jimdog99 commented 9 months ago

Sorry I resolved the issue.... I had a mistake in my TFPyEnvironment which I was using to wrap your Gym.

Please close this issue.