i get the error below.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [3], in <cell line: 30>()
27 def observation_spec(self):
28 return self._observation_spec
---> 30 env = connect4_env(4)
TypeError: Can't instantiate abstract class connect4_env with abstract methods _reset, _step
i never actually make the function _reset so it must be coming from py_environment.PyEnvironment
code below
from tf_agents.environments import py_environment
from tf_agents.environments import tf_environment
from tf_agents.environments import tf_py_environment
from tf_agents.environments import utils
from tf_agents.specs import array_spec
from tf_agents.environments import wrappers
from tf_agents.environments import suite_gym
from tf_agents.trajectories import time_step as ts
class connect4_env(py_environment.PyEnvironment):
def __init__(self , num_slots):
self._action_spec = array_spec.BoundedArraySpec(
shape=(), dtype=np.int32, minimum=0, maximum=num_slots-1, name='play')
self._observation_spec = array_spec.BoundedArraySpec(
shape=(1,num_slots), dtype=np.int32, minimum=0, maximum=1, name='board')
self._state = [0 for num in num_slots]
self._episode_ended = False
def action_spec(self):
return self._action_spec
def observation_spec(self):
return self._observation_spec
env = connect4_env(4)
how can i fix this?
why is this happening? if it is from py_environment.PyEnvironment isnt it built in? why would a built in function have a name that breaks everything?
###################
extra info below
im using anaconda
im using tf_agents version 0.13.0
im following this tutorial (but slightly different) https://towardsdatascience.com/creating-a-custom-environment-for-tensorflow-agent-tic-tac-toe-example-b66902f73059
I believe the problem is as stated in the title but i dont know for sure
###############################
update
i have made these changes
from tf_agents.environments import py_environment , _reset, _step
class connect4_env(py_environment.PyEnvironment):
@_reset
@_step
def __init__(self , num_slots):
because i belive i need to import _reset from tf_agents.environments and the use @_reset when creating my class but now get this error.
ImportError: cannot import name '_reset' from 'tf_agents.environments' (C:\Users\tgmjack\anaconda3\lib\site-packages\tf_agents\environments\__init__.py)
ill keep looking
i dont seem to be able to import the abstract functions though
Please read about abstract classes here or look it up on Google.
You need to implement all the abstract methods defined in
py_environment.PyEnvironmentin your subclass that inherits from it.