Skip to content
Open
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
5 changes: 2 additions & 3 deletions pufferlib/ocean/drive/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,8 @@ def save_map_binary(map_data, output_file, unique_map_id):
sdc_track_index = metadata.get("sdc_track_index", -1) # -1 as default if not found
tracks_to_predict = metadata.get("tracks_to_predict", [])

# Write original scenario_id with fallback to placeholder
scenario_id = map_data.get("scenario_id", f"map_{unique_map_id:03d}")
f.write(struct.pack("16s", scenario_id.encode("utf-8")))
# Note: C load_map_binary does NOT read a scenario_id prefix.
# Do not write one here or the binary will be misaligned.
Comment on lines +802 to +803
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

The note here is easy to misread as “scenario_id isn’t part of the binary at all”, but load_map_binary does read an int scenario_id per-entity. Consider rewording to explicitly say “the file must start with sdc_track_index (no 16-byte string prefix)” and/or reference pufferlib/ocean/drive/drive.h:1060 to prevent confusion.

Suggested change
# Note: C load_map_binary does NOT read a scenario_id prefix.
# Do not write one here or the binary will be misaligned.
# Binary layout note:
# The file must start with sdc_track_index (an int32), with NO 16-byte
# scenario_id string prefix. The corresponding C reader
# (load_map_binary in pufferlib/ocean/drive/drive.h:1060) reads
# scenario_id as an int per-entity, not as a file-level prefix. Writing
# any extra prefix here will misalign all subsequent reads.

Copilot uses AI. Check for mistakes.

# Write sdc_track_index
f.write(struct.pack("i", sdc_track_index))
Comment on lines +802 to 806
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

This change alters the on-disk binary format (removing the 16-byte prefix). Please add a small regression test that writes a minimal map via save_map_binary and asserts the first bytes are sdc_track_index (i.e., no 16-byte offset) so this misalignment doesn’t get reintroduced later.

Copilot uses AI. Check for mistakes.
Expand Down
Loading