Skip to content
Merged
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
2 changes: 1 addition & 1 deletion docs/FORMAT.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The single overriding rule: **a canonical episode is spec-conforming MCAP.** Eve

- MCAP magic, `Header`, data section, `DataEnd`, summary section, `Footer`, closing magic, per the [MCAP spec](https://mcap.dev/spec).
- `Header.profile` is the empty string `""` (the file mixes protobuf video channels with pass-through channels of arbitrary encoding, so no single profile applies).
- `Header.library` is informational only (currently `hebbian-mcap/0.1.1`). Its exact value is not part of the format contract, and no reader may key behavior off it (see [Identifier rules](#identifier-rules)).
- `Header.library` is informational only (currently `hebbian-mcap/0.1.2`). Its exact value is not part of the format contract, and no reader may key behavior off it (see [Identifier rules](#identifier-rules)).
- Chunks are compressed with **zstd** by default (`"none"` is permitted). Each `Chunk` record carries `uncompressed_crc`; the `Footer` carries a summary CRC.
- The summary section repeats all `Schema` and `Channel` records and contains `Statistics`, all `ChunkIndex` records, `AttachmentIndex`/`MetadataIndex` records, and `SummaryOffset` records. A canonical episode always has a complete summary; unindexed files are not canonical.
- Each topic names exactly one channel. MCAP allows several channels to share a topic; a canonical episode does not, because topic-keyed reads would be ambiguous.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"httpx2>=2.12.0",
"huggingface-hub>=1.31.0,<2",
"mcap>=1.4.0",
"hebbian-mcap==0.1.1",
"hebbian-mcap==0.1.2",
"mcap-protobuf-support>=0.5.4",
"mcap-ros2-support>=0.5.7",
"numpy>=2.3.5",
Expand Down Expand Up @@ -56,7 +56,7 @@ mediapipe = ["mediapipe>=1.0.1"]
# dependency is real, and confined to the one check that needs it. Headless
# because a data pipeline runs where there is no display.
motion = ["opencv-python-headless>=5.0.0.93"]
video = ["av>=18.1.0", "hebbian-mcap[video]==0.1.1"]
video = ["av>=18.1.0", "hebbian-mcap[video]==0.1.2"]
native-build = ["Cython>=3.3.0", "setuptools>=84.0.0"]
openai = ["openai>=3.3.1"]

Expand Down
2 changes: 1 addition & 1 deletion src/hflow/behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
# library identifier, schema/channel placement, and compressed bytes can change.
# Regenerate derived outputs rather than mixing both writers under one identity.
#
# "13": video messages are encoded and rewritten by hebbian-mcap 0.1.1. The
# "13": video messages are encoded and rewritten by hebbian-mcap (0.1.2). The
# CompressedVideo schema record now carries protobuf ``json_name`` entries, the
# library identifier names the new release, and a pass-through protobuf message
# that gains an access unit delimiter keeps its original field order. Decoded
Expand Down
35 changes: 6 additions & 29 deletions src/hflow/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from dataclasses import dataclass
from pathlib import Path

from hebbian_mcap import encode_joint_state
from mcap.writer import Writer

from hflow._field_guards import require_float, require_int
Expand Down Expand Up @@ -180,10 +181,6 @@ def write_i32(self, value: int) -> None:
self.align(4)
self._body += struct.pack("<i", value)

def write_f64(self, value: float) -> None:
self.align(8)
self._body += struct.pack("<d", value)

def write_string(self, value: str) -> None:
encoded_value = value.encode("utf-8")
# The uint32 length prefix includes the trailing NUL terminator.
Expand All @@ -203,26 +200,6 @@ def _write_header(encoder: _CdrEncoder, stamp_ns: int, frame_id: str) -> None:
encoder.write_string(frame_id)


def _encode_joint_state(
stamp_ns: int,
frame_id: str,
joint_names: list[str],
positions: list[float],
velocities: list[float],
efforts: list[float],
) -> bytes:
encoder = _CdrEncoder()
_write_header(encoder, stamp_ns, frame_id)
encoder.write_u32(len(joint_names))
for joint_name in joint_names:
encoder.write_string(joint_name)
for float_sequence in (positions, velocities, efforts):
encoder.write_u32(len(float_sequence))
for element in float_sequence:
encoder.write_f64(element)
return encoder.payload()


def _encode_compressed_image(stamp_ns: int, frame_id: str, jpeg_bytes: bytes) -> bytes:
encoder = _CdrEncoder()
_write_header(encoder, stamp_ns, frame_id)
Expand Down Expand Up @@ -690,11 +667,11 @@ def _build_joint_messages(spec: SyntheticEpisodeSpec) -> list[tuple[int, bytes]]
JOINT_SINE_AMPLITUDE_RAD * 2.0 * math.pi * frequency_hz * math.cos(angle_rad)
)
log_time_ns = _message_log_time_ns(spec, message_index, spec.joint_hz)
payload = _encode_joint_state(
stamp_ns=log_time_ns,
frame_id="base",
joint_names=joint_names,
positions=positions,
payload = encode_joint_state(
log_time_ns,
"base",
joint_names,
positions,
velocities=velocities,
efforts=[0.0] * spec.joint_count,
Comment on lines +670 to 676

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Joint arrays lack test coverage

The new encode_joint_state call relies on the dependency to preserve velocities and efforts, but test_joint_states_round_trip only checks names, timestamps, and positions. Add assertions for the expected sine-wave velocities and zero efforts. Otherwise, dropping or swapping either array would leave the tests green despite changing the generated episodes.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

)
Expand Down
25 changes: 17 additions & 8 deletions tests/test_checks_nan_failopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import pytest
from mcap.writer import Writer
from mcap_ros2.writer import serialize_dynamic

from hflow import Episode
from hflow.checks import (
Expand All @@ -34,7 +35,6 @@
from hflow.testing import (
_JOINT_STATE_SCHEMA_TEXT,
JOINT_STATE_SCHEMA_NAME,
_encode_joint_state,
)

TOPIC = "/joint_states"
Expand All @@ -48,6 +48,9 @@ def _joint_states_episode(
*,
omit_positions: bool = False,
) -> Episode:
encode_joint_state = serialize_dynamic(JOINT_STATE_SCHEMA_NAME, _JOINT_STATE_SCHEMA_TEXT)[
JOINT_STATE_SCHEMA_NAME
]
with path.open("wb") as stream:
writer = Writer(stream)
writer.start(profile="ros2", library="test-546")
Expand All @@ -63,13 +66,19 @@ def _joint_states_episode(
METADATA_RECORD_EPISODE, {"task": "nan-failopen", "embodiment": "probe"}
)
for sequence, (stamp_ns, position) in enumerate(zip(stamps_ns, positions, strict=True)):
payload = _encode_joint_state(
stamp_ns,
"probe",
["j0"],
[] if omit_positions else [position],
[],
[],
# A message naming a joint without a position is malformed on purpose,
# so it is built with the schema-driven encoder, which does not check it.
payload = encode_joint_state(
{
"header": {
"stamp": {"sec": stamp_ns // NS_PER_S, "nanosec": stamp_ns % NS_PER_S},
"frame_id": "probe",
},
"name": ["j0"],
"position": [] if omit_positions else [position],
"velocity": [],
"effort": [],
}
)
writer.add_message(
channel_id=channel_id,
Expand Down
18 changes: 9 additions & 9 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading