Skip to content

Commit e2ae827

Browse files
committed
refactor(testing): encode synthetic joint states with hebbian-mcap 0.1.2
The synthetic episode generator hand-rolled its JointState CDR encoder. The shared encoder now takes velocities and efforts and produces the same bytes, so the generator uses it. The one test that builds deliberately malformed joint messages uses the schema-driven ROS 2 encoder instead. TRANSFORM_BEHAVIOR_VERSION stays at 13, which has not shipped in a release; its note now names the 0.1.2 library identifier.
1 parent fc2411b commit e2ae827

6 files changed

Lines changed: 36 additions & 50 deletions

File tree

‎docs/FORMAT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The single overriding rule: **a canonical episode is spec-conforming MCAP.** Eve
1919

2020
- MCAP magic, `Header`, data section, `DataEnd`, summary section, `Footer`, closing magic, per the [MCAP spec](https://mcap.dev/spec).
2121
- `Header.profile` is the empty string `""` (the file mixes protobuf video channels with pass-through channels of arbitrary encoding, so no single profile applies).
22-
- `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)).
22+
- `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)).
2323
- Chunks are compressed with **zstd** by default (`"none"` is permitted). Each `Chunk` record carries `uncompressed_crc`; the `Footer` carries a summary CRC.
2424
- 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.
2525
- 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.

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"httpx2>=2.12.0",
2727
"huggingface-hub>=1.31.0,<2",
2828
"mcap>=1.4.0",
29-
"hebbian-mcap==0.1.1",
29+
"hebbian-mcap==0.1.2",
3030
"mcap-protobuf-support>=0.5.4",
3131
"mcap-ros2-support>=0.5.7",
3232
"numpy>=2.3.5",
@@ -56,7 +56,7 @@ mediapipe = ["mediapipe>=1.0.1"]
5656
# dependency is real, and confined to the one check that needs it. Headless
5757
# because a data pipeline runs where there is no display.
5858
motion = ["opencv-python-headless>=5.0.0.93"]
59-
video = ["av>=18.1.0", "hebbian-mcap[video]==0.1.1"]
59+
video = ["av>=18.1.0", "hebbian-mcap[video]==0.1.2"]
6060
native-build = ["Cython>=3.3.0", "setuptools>=84.0.0"]
6161
openai = ["openai>=3.3.1"]
6262

‎src/hflow/behavior.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
# library identifier, schema/channel placement, and compressed bytes can change.
110110
# Regenerate derived outputs rather than mixing both writers under one identity.
111111
#
112-
# "13": video messages are encoded and rewritten by hebbian-mcap 0.1.1. The
112+
# "13": video messages are encoded and rewritten by hebbian-mcap (0.1.2). The
113113
# CompressedVideo schema record now carries protobuf ``json_name`` entries, the
114114
# library identifier names the new release, and a pass-through protobuf message
115115
# that gains an access unit delimiter keeps its original field order. Decoded

‎src/hflow/testing.py‎

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from dataclasses import dataclass
4545
from pathlib import Path
4646

47+
from hebbian_mcap import encode_joint_state
4748
from mcap.writer import Writer
4849

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

183-
def write_f64(self, value: float) -> None:
184-
self.align(8)
185-
self._body += struct.pack("<d", value)
186-
187184
def write_string(self, value: str) -> None:
188185
encoded_value = value.encode("utf-8")
189186
# The uint32 length prefix includes the trailing NUL terminator.
@@ -203,26 +200,6 @@ def _write_header(encoder: _CdrEncoder, stamp_ns: int, frame_id: str) -> None:
203200
encoder.write_string(frame_id)
204201

205202

206-
def _encode_joint_state(
207-
stamp_ns: int,
208-
frame_id: str,
209-
joint_names: list[str],
210-
positions: list[float],
211-
velocities: list[float],
212-
efforts: list[float],
213-
) -> bytes:
214-
encoder = _CdrEncoder()
215-
_write_header(encoder, stamp_ns, frame_id)
216-
encoder.write_u32(len(joint_names))
217-
for joint_name in joint_names:
218-
encoder.write_string(joint_name)
219-
for float_sequence in (positions, velocities, efforts):
220-
encoder.write_u32(len(float_sequence))
221-
for element in float_sequence:
222-
encoder.write_f64(element)
223-
return encoder.payload()
224-
225-
226203
def _encode_compressed_image(stamp_ns: int, frame_id: str, jpeg_bytes: bytes) -> bytes:
227204
encoder = _CdrEncoder()
228205
_write_header(encoder, stamp_ns, frame_id)
@@ -690,11 +667,11 @@ def _build_joint_messages(spec: SyntheticEpisodeSpec) -> list[tuple[int, bytes]]
690667
JOINT_SINE_AMPLITUDE_RAD * 2.0 * math.pi * frequency_hz * math.cos(angle_rad)
691668
)
692669
log_time_ns = _message_log_time_ns(spec, message_index, spec.joint_hz)
693-
payload = _encode_joint_state(
694-
stamp_ns=log_time_ns,
695-
frame_id="base",
696-
joint_names=joint_names,
697-
positions=positions,
670+
payload = encode_joint_state(
671+
log_time_ns,
672+
"base",
673+
joint_names,
674+
positions,
698675
velocities=velocities,
699676
efforts=[0.0] * spec.joint_count,
700677
)

‎tests/test_checks_nan_failopen.py‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import pytest
2222
from mcap.writer import Writer
23+
from mcap_ros2.writer import serialize_dynamic
2324

2425
from hflow import Episode
2526
from hflow.checks import (
@@ -34,7 +35,6 @@
3435
from hflow.testing import (
3536
_JOINT_STATE_SCHEMA_TEXT,
3637
JOINT_STATE_SCHEMA_NAME,
37-
_encode_joint_state,
3838
)
3939

4040
TOPIC = "/joint_states"
@@ -48,6 +48,9 @@ def _joint_states_episode(
4848
*,
4949
omit_positions: bool = False,
5050
) -> Episode:
51+
encode_joint_state = serialize_dynamic(JOINT_STATE_SCHEMA_NAME, _JOINT_STATE_SCHEMA_TEXT)[
52+
JOINT_STATE_SCHEMA_NAME
53+
]
5154
with path.open("wb") as stream:
5255
writer = Writer(stream)
5356
writer.start(profile="ros2", library="test-546")
@@ -63,13 +66,19 @@ def _joint_states_episode(
6366
METADATA_RECORD_EPISODE, {"task": "nan-failopen", "embodiment": "probe"}
6467
)
6568
for sequence, (stamp_ns, position) in enumerate(zip(stamps_ns, positions, strict=True)):
66-
payload = _encode_joint_state(
67-
stamp_ns,
68-
"probe",
69-
["j0"],
70-
[] if omit_positions else [position],
71-
[],
72-
[],
69+
# A message naming a joint without a position is malformed on purpose,
70+
# so it is built with the schema-driven encoder, which does not check it.
71+
payload = encode_joint_state(
72+
{
73+
"header": {
74+
"stamp": {"sec": stamp_ns // NS_PER_S, "nanosec": stamp_ns % NS_PER_S},
75+
"frame_id": "probe",
76+
},
77+
"name": ["j0"],
78+
"position": [] if omit_positions else [position],
79+
"velocity": [],
80+
"effort": [],
81+
}
7382
)
7483
writer.add_message(
7584
channel_id=channel_id,

‎uv.lock‎

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)