Skip to content

enum schemas and binding to C #526

Open
riccardosavorgnan wants to merge 3 commits into
3.0from
ricky/implement_hydra_v3
Open

enum schemas and binding to C #526
riccardosavorgnan wants to merge 3 commits into
3.0from
ricky/implement_hydra_v3

Conversation

@riccardosavorgnan

@riccardosavorgnan riccardosavorgnan commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

This PR introduces the enum schemas and binding to C to make sure of two things:

  • we can validate the values of a config are in the expected range with an explicit mapping between text and integer
  • we can validate the mapping between Enums in python and C behavior align.

The first point in particular let us run a validation of the config directly on the login node rather than waiting for run-time errors (we can add this to this pr if needed).

Note: co-authored with claude.

collision/offroad/traffic_light_behavior take "ignore"/"stop"/"remove"
instead of raw ints; drive.py maps names to binding constants, the C ini
parser rejects anything else, and IGNORE_INFRACTION/STOP_AGENT/REMOVE_AGENT
are exported to Python.
OmegaConf structured schema (config_schema.py) validates types, enum names,
and unknown keys at load_config time; test_config_schema.py asserts the
schema enum ints never drift from the drive.h constants exported by the
binding.
@riccardosavorgnan
riccardosavorgnan marked this pull request as ready for review July 13, 2026 18:42
Comment thread pufferlib/ocean/drive/drive.h Outdated
Comment on lines 401 to 404
int collision_behavior; // IGNORE_INFRACTION, STOP_AGENT, or REMOVE_AGENT
int offroad_behavior; // IGNORE_INFRACTION, STOP_AGENT, or REMOVE_AGENT
int traffic_light_behavior; // IGNORE_INFRACTION, STOP_AGENT, or REMOVE_AGENT
int use_map_cache; // 0 = each env owns its map copy, 1 = share static geometry across envs

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These names don't seem consistent with the other documentation?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems risky to me to have multiple variants of a naming scheme floating around

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yeah. this is the minimal change of keeping the names we already had in the C part of the code. We could totally move everything to have the same names across python and C, and even enforce name matching with a test?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah I just feel like we might as well make that change here if we're going to do this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sounds good! I'll look around and ask claude as well if there's any known/good pattern to follow here, otherwise we can just go with the intuition of naming everything the same.

@riccardosavorgnan
riccardosavorgnan marked this pull request as draft July 16, 2026 13:47
@riccardosavorgnan

Copy link
Copy Markdown
Collaborator Author

converting back to draft while reviewing the proposal

@riccardosavorgnan

Copy link
Copy Markdown
Collaborator Author

Ok,

all relevant config parameters are mapped to an Enum class in the config. Each enum class has a direct name - value matching with the C enum constants. The convention is to have {enum_class_name}_{enum_value} for each class. Example:

DynamicsModel.classic -> DYNAMICS_MODEL_CLASSIC
InitMode.create_all_valid -> INIT_MODE_CREATE_ALL_VALID

The python enum class name has to use the CamelCase convention to ensure we are separate the words, the values have to use PascalCase (underscore separation) (see the 2 examples above). With this convention, we can automatically separate match the python enum to the C enum enforcing the respective integer value match as a test.

@riccardosavorgnan
riccardosavorgnan marked this pull request as ready for review July 16, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants