danijar / crafter

Benchmarking the Spectrum of Agent Capabilities

Home Page:https://danijar.com/crafter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any plan to make Crafter compatible with the latest Gym API?

sparisi opened this issue · comments

The latest Gym API expects terminated, truncated rather than just done after a env.step(), and seeds the environment with env.reset(seed=seed) rather than env.seed(seed=seed). It is possible to apply a compatibility wrapper by making the env with env = gym.make('CrafterReward-v1', apply_api_compatibility=True) but to work properly the base env must have the env.seed(seed=seed) function, which your Env class does not have (instead, it has the self._seed attribute).

Is there any plan to add the env.seed() function, to make it fully compatible with the latest API? That would also make it compatible with Gymnasium.

Hi, I plan to switch to the new API once that's become more widely used than the old one (not sure if that will ever happen though?).

I might also switch the env to implement my own API that I use for all projects and then provide wrappers for Gym, Gymnasium, DMEnv, etc.

In the meantime, can you patch the seed function? Something along the lines of:

def seed(self, seed):
  self._seed = seed
Env.seed = seed
env = GymToGymnasium(Env())

Otherwise it's also pretty easy to subclass to implement the seed method or the new API directly. Would be great to see the solution you end up using for others to benefit! :)

Hi!
I feel that the new API is already quite popular, especially among new students.
Just having the seed function would make the code compatibile with every version of gym / gymnasium thanks to the apply_api_compatibility argument.

The problem with the current setup is that seeding depends on the episode as well, and the episode counter is internally increased at every reset call. So doing

env.seed(1)
env.reset()
env.seed(1)
env.reset()

produces 2 different observations. This is not the usual behavior with other gym / gymnasium env.
A solution would be to have

def seed(seed):
  self._seed = seed
  self._episode = episode

But then one could not do env.reset(seed=seed) (as in the new API) without resetting the episode.

Is having the episode as the environment attribute necessary? I see that it is used only for seeding.

If self._episode could be taken out of the environment, one could do something like:

ep = 0
for _ in training_steps:
  ep_seed = hash(seed, ep)
  env.seed(ep_seed)
  env.reset()
  done = False
  while not done:
    act = ...
    obs, rwd, done, info = env.step(act)
    training_steps += 1
  ep +=1

or, with the new API

ep = 0
for _ in training_steps:
  ep_seed = hash(seed, ep)
  env.reset(seed=ep_seed)
  done = False
  while not done:
    act = ...
    obs, rwd, done, info = env.step(act)
    training_steps += 1
  ep +=1

Hi Catid, first of all thanks so much for your work on an update. I'm having trouble using your updated version. It seems like when I try "pip install git+https://github.com/catid/crafter.git", I still get the "AttributeError: 'Env' object has no attribute 'seed'" issue, leading me to believe my installation process is wrong. Is there another way you recommend installing your updated package?