|
44 | 44 | SomeGeneratorAbovePmax, |
45 | 45 | SomeGeneratorBelowPmin, |
46 | 46 | SomeGeneratorAboveRampmax, |
47 | | - SomeGeneratorBelowRampmin) |
| 47 | + SomeGeneratorBelowRampmin, |
| 48 | + BackendError) |
48 | 49 | from grid2op.Parameters import Parameters |
49 | 50 | from grid2op.Reward import BaseReward, RewardHelper |
50 | 51 | from grid2op.Opponent import OpponentSpace, NeverAttackBudget, BaseOpponent |
@@ -671,6 +672,9 @@ def __init__( |
671 | 672 | self._previous_conn_state = None |
672 | 673 | self._cst_prev_state_at_init = None |
673 | 674 |
|
| 675 | + # 1.11: do not check rules if first observation |
| 676 | + self._called_from_reset = True |
| 677 | + |
674 | 678 | @property |
675 | 679 | def highres_sim_counter(self): |
676 | 680 | return self._highres_sim_counter |
@@ -994,6 +998,9 @@ def _custom_deepcopy_for_copy(self, new_obj, dict_=None): |
994 | 998 | new_obj._previous_conn_state = copy.deepcopy(self._previous_conn_state) |
995 | 999 | new_obj._cst_prev_state_at_init = self._cst_prev_state_at_init # no need to deep copy this |
996 | 1000 |
|
| 1001 | + |
| 1002 | + new_obj._called_from_reset = self._called_from_reset |
| 1003 | + |
997 | 1004 | def get_path_env(self): |
998 | 1005 | """ |
999 | 1006 | Get the path that allows to create this environment. |
@@ -1550,6 +1557,7 @@ def reset(self, |
1550 | 1557 | f"can be used.") |
1551 | 1558 |
|
1552 | 1559 | self.__is_init = True |
| 1560 | + self._called_from_reset = True |
1553 | 1561 | # current = None is an indicator that this is the first step of the environment |
1554 | 1562 | # so don't change the setting of current_obs = None unless you are willing to change that |
1555 | 1563 | self.current_obs = None |
@@ -3550,7 +3558,8 @@ def step(self, action: BaseAction) -> Tuple[BaseObservation, |
3550 | 3558 | # and this regardless of the |
3551 | 3559 | _ = action.get_topological_impact(powerline_status, _store_in_cache=True, _read_from_cache=False) |
3552 | 3560 |
|
3553 | | - if self._last_obs is not None: |
| 3561 | + if not self._called_from_reset: |
| 3562 | + # avoid checking this at first environment "step" which is a "reset" |
3554 | 3563 | is_legal, reason = self._game_rules(action=action, env=self) |
3555 | 3564 | else: |
3556 | 3565 | is_legal = True |
@@ -3634,6 +3643,10 @@ def step(self, action: BaseAction) -> Tuple[BaseObservation, |
3634 | 3643 | is_done = True |
3635 | 3644 | # TODO in this case: cancel the topological action of the agent |
3636 | 3645 | # and continue instead of "game over" |
| 3646 | + except BackendError as exc_: |
| 3647 | + has_error = True |
| 3648 | + except_.append(exc_) |
| 3649 | + is_done = True |
3637 | 3650 | self._time_apply_act += time.perf_counter() - beg_ |
3638 | 3651 |
|
3639 | 3652 | # now it's time to run the powerflow properly |
|
0 commit comments