Skip to content

Commit cd40208

Browse files
author
Jeff Law
committed
Skip warning message from rllib precheck
1 parent 6baed40 commit cd40208

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

graphenv/graph_env.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import warnings
33
from typing import Any, Dict, List, Optional, Tuple
4+
import inspect
45

56
import gymnasium as gym
67
import numpy as np
@@ -108,13 +109,20 @@ def step(self, action: int) -> Tuple[Dict[str, np.ndarray], float, bool, bool, d
108109
self.state = self.state.children[action]
109110

110111
except IndexError:
111-
warnings.warn(
112-
"Attempting to choose a masked child state. This is either due to "
113-
"rllib's env pre_check module, or due to a failure of the policy model "
114-
"to mask invalid actions. Returning the current state to satisfy the "
115-
"pre_check module.",
116-
RuntimeWarning,
117-
)
112+
# Skip this warning message if the call
113+
# came from rllib's precheck function
114+
# https://github.com/ray-project/ray/blob/e6dad0b961b5e962f6dc4986947ccac2d2e032cd/rllib/utils/pre_checks/env.py#L220
115+
caller_name = inspect.stack()[2][3]
116+
if caller_name == "check_gym_environments":
117+
pass
118+
else:
119+
warnings.warn(
120+
"Attempting to choose a masked child state. This is either due to "
121+
"rllib's env pre_check module, or due to a failure of the policy model "
122+
"to mask invalid actions. Returning the current state to satisfy the "
123+
"pre_check module.",
124+
RuntimeWarning,
125+
)
118126

119127
# In RLlib 2.3, the config options "no_done_at_end", "horizon", and "soft_horizon" are no longer supported
120128
# according to the migration guide https://docs.google.com/document/d/1lxYK1dI5s0Wo_jmB6V6XiP-_aEBsXDykXkD1AXRase4/edit#

0 commit comments

Comments
 (0)