Gymnasium: [Question] Reset function leads to an Assertion error because of the seed
Question
Hi all,
I have the following reset function
def reset (self, **kwargs):
seed = 1
super().reset(seed=seed)
self.state_difference_costs_to_conventional_solution = 0
self.state_difference_peak_to_conventional_solution = 0
self.state_thermal_discomfort = 0
info = {}
self.observation_space = np.array([0,0, 0])
return self.observation_space, info
This leads to the Assertion error of the gynasium environment checker
AssertionError: Mostly likely the environment reset function does not call
super().reset(seed=seed)as the random number generators are not different when different seeds are passed to
env.reset.
I tried multiple things but they all were not successfull.
It says that super().reset(seed=seed)
is not called but it is in fact called as you can see. I also tried super().reset(seed=None)
but this leads to the same error. I also tried:
def reset (self):
self.state_difference_costs_to_conventional_solution = 0
self.state_difference_peak_to_conventional_solution = 0
self.state_thermal_discomfort = 0
info = {}
self.observation_space = np.array([0,0, 0])
return self.observation_space, info
which leads to the error
raise gym.error.Error(
gymnasium.error.Error: The `reset` method does not provide a `seed` or `**kwargs` keyword argument.
Actually I don’t need a seed argument at all as I don’t use it. Can anyone tell me why this problem occurs and how to solve it?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 29 (12 by maintainers)
@PBerit In your version you pass an instance of your DSM_Env to gym.register and not the DSM_Env class.
Try:
gym.register("dsm-env-v0", lambda: DSM_Env(<params>))
I can confirm that @pseudo-rnd-thoughts code doesn’t give that warning about render spec with your render function from your original source code:
with:
@mvhensbergen : Thanks for your answer and effort. It now runs without any warnings. Also thanks to @pseudo-rnd-thoughts . I really appreciate your help.
@PBerit
I have cut down your code sample to the essentials below:
One remark, your original step function did not return the amount of variables that was required by the new library (got a Warning from the library when running) so you might also not run the latest version of gymnasium?
The output of this script is:
<class 'gymnasium.spaces.box.Box'> <class 'numpy.ndarray'>
The above script shows that after your
step
function, you have overwritten the ‘observation_space’ variable in Env and to a ndarray instead of a Box. This corrupts your Env.If you remove the ‘self.’ in the step function (thus making a local variable) you will return an observation without corrupting the
observation_space
variable.I would advise to carefully look into the example code and tutorial to get a bit more feeling about the classes and try to rewrite your code.
In addition, I don’t think this GitHub issue tracker is meant to discuss these things as it appears your issue is not a problem with the library itself ( and also has been closed by the maintainer). If you like you can contact me further outside this platform or perhaps find help elsewhere?
I will need to look into this a bit more (as I am responding while at work). I can try your code tomorrow - that will probably make me better see what the problem is.
As the documentation states what you should return is an observation which is -an element of- the observation space. What you do is overwrite the definition of the observation_space itself and return it.
So self.observation_space is the collection of all possible observations, step should return only one observation out of that space.
I hope this helps.