Skip to content
Open
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 @@ -187,8 +187,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 @@ -83,7 +85,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)

self.init_steps = init_steps
self.init_mode_str = init_mode
Expand Down Expand Up @@ -209,7 +211,7 @@ def __init__(
max_controlled_agents=self.max_controlled_agents,
map_path=self.map_files[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 @@ -281,7 +283,7 @@ def step(self, actions):
max_controlled_agents=self.max_controlled_agents,
map_path=self.map_files[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.2.2",
"pettingzoo==1.24.1",
]

Expand Down