Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion pufferlib/ocean/drive/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,26 @@ static int my_init(Env *env, PyObject *args, PyObject *kwargs) {
env->human_agent_idx = unpack(kwargs, "human_agent_idx");
env->ini_file = unpack_str(kwargs, "ini_file");
env_init_config conf = {0};

// Check if INI file exists before parsing
FILE *ini_check = fopen(env->ini_file, "r");
if (ini_check == NULL) {
char error_msg[1024];
snprintf(error_msg, sizeof(error_msg),
"INI config file not found: '%s'. "
"Please ensure the file exists at this path.",
env->ini_file);
PyErr_SetString(PyExc_FileNotFoundError, error_msg);
return -1;
}
fclose(ini_check);

if (ini_parse(env->ini_file, handler, &conf) < 0) {
printf("Error while loading %s", env->ini_file);
char error_msg[1024];
snprintf(error_msg, sizeof(error_msg),
"Failed to parse INI config file: '%s'", env->ini_file);
PyErr_SetString(PyExc_ValueError, error_msg);
return -1;
}
if (kwargs && PyDict_GetItemString(kwargs, "episode_length")) {
conf.episode_length = (int)unpack(kwargs, "episode_length");
Expand Down
8 changes: 5 additions & 3 deletions pufferlib/ocean/drive/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from multiprocessing import Pool, cpu_count
from tqdm import tqdm

_PACKAGE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
_INI_FILE = os.path.join(_PACKAGE_DIR, "config", "ocean", "drive.ini")

class Drive(pufferlib.PufferEnv):
def __init__(
Expand Down Expand Up @@ -82,7 +84,7 @@ def __init__(
+ self.max_partner_objects * self.partner_features
+ self.max_road_objects * self.road_features
)
self.single_observation_space = gymnasium.spaces.Box(low=-1, high=1, shape=(self.num_obs,), dtype=np.float32)
self.single_observation_space = gymnasium.spaces.Box(low=-1, high=2, shape=(self.num_obs,), dtype=np.float32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: observation space upper bound increased from 1 to 2 without explanation

Suggested change
self.single_observation_space = gymnasium.spaces.Box(low=-1, high=2, shape=(self.num_obs,), dtype=np.float32)
self.single_observation_space = gymnasium.spaces.Box(low=-1, high=1, shape=(self.num_obs,), dtype=np.float32)

Does this change reflect actual observation values that can exceed 1, or is this related to RLlib compatibility requirements?

Prompt To Fix With AI
This is a comment left during a code review.
Path: pufferlib/ocean/drive/drive.py
Line: 87:87

Comment:
**logic:** observation space upper bound increased from 1 to 2 without explanation

```suggestion
        self.single_observation_space = gymnasium.spaces.Box(low=-1, high=1, shape=(self.num_obs,), dtype=np.float32)
```

 Does this change reflect actual observation values that can exceed 1, or is this related to RLlib compatibility requirements?

How can I resolve this? If you propose a fix, please make it concise.


self.init_steps = init_steps
self.init_mode_str = init_mode
Expand Down Expand Up @@ -192,7 +194,7 @@ def __init__(
max_controlled_agents=self.max_controlled_agents,
map_id=map_ids[i],
max_agents=nxt - cur,
ini_file="pufferlib/config/ocean/drive.ini",
ini_file=_INI_FILE,
init_steps=init_steps,
init_mode=self.init_mode,
control_mode=self.control_mode,
Expand Down Expand Up @@ -266,7 +268,7 @@ def step(self, actions):
max_controlled_agents=self.max_controlled_agents,
map_id=map_ids[i],
max_agents=nxt - cur,
ini_file="pufferlib/config/ocean/drive.ini",
ini_file=_INI_FILE,
init_steps=self.init_steps,
init_mode=self.init_mode,
control_mode=self.control_mode,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ def run(self):

install_requires = [
"setuptools",
"numpy<2.0",
"numpy",
"shimmy[gym-v21]",
"gym==0.23",
"gymnasium==0.29.1",
"gymnasium==1.1.1",
"pettingzoo==1.24.1",
]

Expand Down