Repository: openai/gym

Issue:
[Bug Report] AttributeError: 'Discrete' object has no attribute 'start'
**Describe the bug**
Change in https://github.com/openai/gym/pull/2470 introduced a bug when loading pre-trained agents with previous version of gym.

Fix is probably similar to https://github.com/DLR-RM/stable-baselines3/issues/573 ...


**Code example**
from RL Zoo CI

See https://github.com/DLR-RM/rl-baselines3-zoo/pull/210 (note: the CI now passes because I downgraded to gym 0.21)
and
https://github.com/DLR-RM/rl-baselines3-zoo/runs/5305883843?check_suite_focus=true

```
python enjoy --algo qrdqn --env Acrobot-v1
```

traceback:
```
 Loading rl-trained-agents/qrdqn/Acrobot-v1_1/Acrobot-v1.zip
----------------------------- Captured stderr call -----------------------------
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/stable_baselines3/common/save_util.py:166: UserWarning: Could not deserialize object exploration_schedule. Consider using `custom_objects` argument to replace this object.
  warnings.warn(
Traceback (most recent call last):
  File "/home/runner/work/rl-baselines3-zoo/rl-baselines3-zoo/enjoy.py", line 248, in <module>
    main()
  File "/home/runner/work/rl-baselines3-zoo/rl-baselines3-zoo/enjoy.py", line 178, in main
    model = ALGOS[algo].load(model_path, env=env, custom_objects=custom_objects, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/stable_baselines3/common/base_class.py", line 709, in load
    check_for_correct_spaces(env, data["observation_space"], data["action_space"])
  File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/stable_baselines3/common/utils.py", line 224, in check_for_correct_spaces
    if action_space != env.action_space:
  File "/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/gym/spaces/discrete.py", line 50, in __eq__
    and self.start == other.start
AttributeError: 'Discrete' object has no attribute 'start'
```

**System Info**
Gym 0.22

**Additional context**
Add any other context about the problem here.

### Checklist

- [x] I have checked that there is no similar [issue](https://github.com/openai/gym/issues) in the repo (**required**)



Discussion:

Resolving patch:
diff --git a/gym/spaces/discrete.py b/gym/spaces/discrete.py
--- a/gym/spaces/discrete.py
+++ b/gym/spaces/discrete.py
@@ -12,7 +12,7 @@ class Discrete(Space[int]):
 
     Example::
 
-        >>> Discrete(2)
+        >>> Discrete(2)            # {0, 1}
         >>> Discrete(3, start=-1)  # {-1, 0, 1}
 
     """
@@ -49,3 +49,17 @@ def __eq__(self, other) -> bool:
             and self.n == other.n
             and self.start == other.start
         )
+
+    def __setstate__(self, state):
+        super().__setstate__(state)
+
+        # Don't mutate the original state
+        state = dict(state)
+
+        # Allow for loading of legacy states.
+        # See https://github.com/openai/gym/pull/2470
+        if "start" not in state:
+            state["start"] = 0
+
+        # Update our state
+        self.__dict__.update(state)


Test patch:
diff --git a/tests/spaces/test_spaces.py b/tests/spaces/test_spaces.py
--- a/tests/spaces/test_spaces.py
+++ b/tests/spaces/test_spaces.py
@@ -537,6 +537,22 @@ def test_infinite_space(space):
     ), "Low's dtype {space.high.dtype} doesn't match `space.dtype`'"
 
 
+def test_discrete_legacy_state_pickling():
+    legacy_state = {
+        "n": 3,
+    }
+
+    d = Discrete(1)
+    assert "start" in d.__dict__
+    del d.__dict__["start"]  # legacy did not include start param
+    assert "start" not in d.__dict__
+
+    d.__setstate__(legacy_state)
+
+    assert d.start == 0
+    assert d.n == 3
+
+
 @pytest.mark.parametrize(
     "space",
     [