simview 7.0.0__tar.gz → 7.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simview-7.0.0/simview.egg-info → simview-7.1.0}/PKG-INFO +1 -1
- {simview-7.0.0 → simview-7.1.0}/pyproject.toml +1 -1
- {simview-7.0.0 → simview-7.1.0}/simview/__main__.py +12 -6
- {simview-7.0.0 → simview-7.1.0}/simview/columnar.py +40 -6
- {simview-7.0.0 → simview-7.1.0}/simview/info.py +2 -2
- {simview-7.0.0 → simview-7.1.0}/simview/merge.py +278 -31
- {simview-7.0.0 → simview-7.1.0}/simview/remote.py +43 -30
- {simview-7.0.0 → simview-7.1.0}/simview/sample.py +1 -1
- {simview-7.0.0 → simview-7.1.0}/simview/scene.py +68 -43
- {simview-7.0.0 → simview-7.1.0}/simview/server.py +3 -1
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/WindowedField.js +15 -6
- {simview-7.0.0 → simview-7.1.0}/simview/utils.py +37 -1
- {simview-7.0.0 → simview-7.1.0/simview.egg-info}/PKG-INFO +1 -1
- {simview-7.0.0 → simview-7.1.0}/tests/test_cli.py +20 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_columnar_ondisk.py +141 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_merge.py +56 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_remote.py +60 -1
- {simview-7.0.0 → simview-7.1.0}/tests/test_scene.py +38 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_utils.py +36 -1
- {simview-7.0.0 → simview-7.1.0}/LICENSE +0 -0
- {simview-7.0.0 → simview-7.1.0}/MANIFEST.in +0 -0
- {simview-7.0.0 → simview-7.1.0}/README.md +0 -0
- {simview-7.0.0 → simview-7.1.0}/setup.cfg +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/__init__.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/diff.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/launcher.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/live.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/model.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/preload.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/py.typed +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/render.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/state.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/css/controls.css +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/SimView.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/AnimationController.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/BatchManager.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/InteractionController.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/Scene.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/components/StateStore.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/config.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/main.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/Body.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/Polyline.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/StaticObject.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/Terrain.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/colormap.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/similarity.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/objects/utils.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/AnalysisPanel.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/BatchLegend.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/BodyStateWindow.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/Controls.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/ErrorMetrics.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/Legend.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/PlaybackControls.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/ScalarPlotter.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/TerrainProfile.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/ui/chartControls.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/batchPresets.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/batchVisibility.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/blobCodec.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/blobWindow.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/bodyTransforms.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/cameraRange.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/csv.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/episodes.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/errorMath.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/html.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/interpolate.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/keyboard.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/liveFollow.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/scalarSeries.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/terrainSample.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/uplot.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/viewState.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/viewerDefaults.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/utils/visibleRanges.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/js/vendor/js-colormaps.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/three-0.174.0/addons/controls/OrbitControls.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/three-0.174.0/addons/libs/lil-gui.module.min.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/three-0.174.0/three.core.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/three-0.174.0/three.module.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/uPlot-1.6.32/uPlot.esm.js +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/lib/uPlot-1.6.32/uPlot.min.css +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/textures/contacts/red-cross0.png +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/static/textures/points/ball1.png +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/templates/index.html +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/terrain.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview/view.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview.egg-info/SOURCES.txt +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview.egg-info/dependency_links.txt +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview.egg-info/entry_points.txt +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview.egg-info/requires.txt +0 -0
- {simview-7.0.0 → simview-7.1.0}/simview.egg-info/top_level.txt +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_agent_cli.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_batch_selection.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_columnar_states.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_contacts.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_diff.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_embed_defaults.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_episodes.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_info.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_launcher.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_live.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_pointcloud_features.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_preload.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_roundtrip.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_server.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_show.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_strict_json.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_terrain.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_terrain_query.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_trajectory.py +0 -0
- {simview-7.0.0 → simview-7.1.0}/tests/test_view.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simview
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.1.0
|
|
4
4
|
Summary: THREE.js-based simulation visualization tool
|
|
5
5
|
Author-email: Jan Vlk <vlkjan6@fel.cvut.cz>, Ales Kucera <kuceral4@fel.cvut.cz>, David Korcak <david.korcak@gmail.com>
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -13,6 +13,7 @@ from pathlib import Path
|
|
|
13
13
|
from simview import CACHE_DIR, __version__, remote
|
|
14
14
|
from simview.server import SimViewServer
|
|
15
15
|
from simview.utils import (
|
|
16
|
+
atomic_write_bytes,
|
|
16
17
|
dumps_json,
|
|
17
18
|
human_bytes,
|
|
18
19
|
load_scene,
|
|
@@ -404,7 +405,7 @@ def _render_view_hash(path: Path, args: argparse.Namespace, t: float | None) ->
|
|
|
404
405
|
)
|
|
405
406
|
|
|
406
407
|
|
|
407
|
-
def _shot_path(output: Path, t: float, count: int) -> Path:
|
|
408
|
+
def _shot_path(output: Path, t: float | None, count: int) -> Path:
|
|
408
409
|
if count == 1:
|
|
409
410
|
return output
|
|
410
411
|
return output.with_name(f"{output.stem}_t{t}{output.suffix}")
|
|
@@ -438,6 +439,7 @@ def run_render(path: Path, args: argparse.Namespace) -> None:
|
|
|
438
439
|
sys.exit(1)
|
|
439
440
|
|
|
440
441
|
output = Path(args.output)
|
|
442
|
+
shots: list[tuple[str | None, str | Path]]
|
|
441
443
|
try:
|
|
442
444
|
if args.view is not None:
|
|
443
445
|
shots = [(args.view, output)]
|
|
@@ -481,16 +483,21 @@ def save_merged(
|
|
|
481
483
|
logger.error("Error: --save-merged requires at least 2 input files to merge.")
|
|
482
484
|
sys.exit(1)
|
|
483
485
|
|
|
484
|
-
from simview.columnar import columnarize_states, inline_blob
|
|
486
|
+
from simview.columnar import columnarize_states, inline_blob, is_columnar
|
|
485
487
|
from simview.merge import merge_simulation_files
|
|
486
488
|
|
|
487
|
-
merged = merge_simulation_files(paths, selections)
|
|
489
|
+
merged = merge_simulation_files(paths, selections, columnar_output=True)
|
|
488
490
|
# Pack the merged states the same way SimulationScene.save does: merge
|
|
489
491
|
# decodes every blob to plain lists, so dumping it directly would write
|
|
490
492
|
# the fat legacy per-frame layout. Falls back silently when numpy is
|
|
491
493
|
# unavailable or the states are too irregular (columnarize_states
|
|
492
494
|
# returns None).
|
|
493
|
-
|
|
495
|
+
if not is_columnar(merged["states"]):
|
|
496
|
+
columnar_states = columnarize_states(
|
|
497
|
+
merged["states"], merged["model"], inline_blob
|
|
498
|
+
)
|
|
499
|
+
else:
|
|
500
|
+
columnar_states = None
|
|
494
501
|
if columnar_states is not None:
|
|
495
502
|
merged["states"] = columnar_states
|
|
496
503
|
payload = dumps_json(merged).encode("utf-8")
|
|
@@ -498,8 +505,7 @@ def save_merged(
|
|
|
498
505
|
payload = gzip.compress(payload, compresslevel=1)
|
|
499
506
|
try:
|
|
500
507
|
# Like SimulationScene.save: create missing parent directories.
|
|
501
|
-
out_path
|
|
502
|
-
out_path.write_bytes(payload)
|
|
508
|
+
atomic_write_bytes(out_path, payload)
|
|
503
509
|
except OSError as e:
|
|
504
510
|
logger.error("Error: cannot write merged scene to '%s': %s", out_path, e)
|
|
505
511
|
sys.exit(1)
|
|
@@ -33,6 +33,7 @@ without numpy.
|
|
|
33
33
|
|
|
34
34
|
import base64
|
|
35
35
|
import logging
|
|
36
|
+
import os
|
|
36
37
|
import struct
|
|
37
38
|
from typing import Any
|
|
38
39
|
|
|
@@ -468,15 +469,21 @@ def write_static_bundle(data: dict, directory) -> None:
|
|
|
468
469
|
``<base>/blob/<id>``). Stdlib-only."""
|
|
469
470
|
from pathlib import Path
|
|
470
471
|
|
|
471
|
-
from simview.utils import dumps_json
|
|
472
|
+
from simview.utils import dumps_json, sibling_tempfile
|
|
472
473
|
|
|
473
474
|
out = Path(directory)
|
|
474
|
-
|
|
475
|
-
|
|
475
|
+
blob_dir = out / "blob"
|
|
476
|
+
blob_dir.mkdir(parents=True, exist_ok=True)
|
|
477
|
+
# Number new blobs past every existing one, so republishing never
|
|
478
|
+
# overwrites a blob the live model.json/states.json still reference.
|
|
479
|
+
count = 1 + max(
|
|
480
|
+
(int(p.name) for p in blob_dir.iterdir() if p.name.isdecimal()), default=-1
|
|
481
|
+
)
|
|
482
|
+
blobs: list[tuple[Path, bytes]] = []
|
|
476
483
|
|
|
477
484
|
def write_blob(raw: bytes) -> str:
|
|
478
485
|
nonlocal count
|
|
479
|
-
(
|
|
486
|
+
blobs.append((blob_dir / str(count), raw))
|
|
480
487
|
count += 1
|
|
481
488
|
return f"/blob/{count - 1}"
|
|
482
489
|
|
|
@@ -486,5 +493,32 @@ def write_static_bundle(data: dict, directory) -> None:
|
|
|
486
493
|
# in place, so they must stay inline.
|
|
487
494
|
if is_columnar(data["states"]):
|
|
488
495
|
rewrite_blobs(data["states"], write_blob)
|
|
489
|
-
|
|
490
|
-
(out / f"{name}.json"
|
|
496
|
+
files = blobs + [
|
|
497
|
+
(out / f"{name}.json", dumps_json(data[name]).encode("utf-8"))
|
|
498
|
+
for name in ("model", "states")
|
|
499
|
+
]
|
|
500
|
+
staged: dict[Path, str] = {}
|
|
501
|
+
try:
|
|
502
|
+
for path, raw in files:
|
|
503
|
+
fd, temporary = sibling_tempfile(path)
|
|
504
|
+
staged[path] = temporary
|
|
505
|
+
with os.fdopen(fd, "wb") as f:
|
|
506
|
+
f.write(raw)
|
|
507
|
+
|
|
508
|
+
for path in [path for path, _ in blobs]:
|
|
509
|
+
os.replace(staged.pop(path), path)
|
|
510
|
+
# Each JSON file only references blobs that exist and belong to it.
|
|
511
|
+
# shortcut: an interruption between these two replaces still pairs the
|
|
512
|
+
# new model with the old states; true atomicity needs one manifest file.
|
|
513
|
+
for name in ("model", "states"):
|
|
514
|
+
path = next(path for path in staged if path.name == f"{name}.json")
|
|
515
|
+
os.replace(staged.pop(path), path)
|
|
516
|
+
replaced = {path.name for path, _ in files}
|
|
517
|
+
for path in blob_dir.iterdir():
|
|
518
|
+
if path.name not in replaced and path.name.isdecimal():
|
|
519
|
+
path.unlink(missing_ok=True)
|
|
520
|
+
finally:
|
|
521
|
+
for temporary in staged.values():
|
|
522
|
+
path = Path(temporary)
|
|
523
|
+
if path.exists():
|
|
524
|
+
path.unlink()
|
|
@@ -97,7 +97,7 @@ def _summarize_terrain(terrain: dict) -> dict:
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
|
|
100
|
-
def _summarize_model(model: dict, warnings: list[str], limit: int) -> dict:
|
|
100
|
+
def _summarize_model(model: dict, warnings: list[str], limit: int | None) -> dict:
|
|
101
101
|
terrain = model.get("terrain")
|
|
102
102
|
if terrain is None:
|
|
103
103
|
warnings.append("model has no terrain")
|
|
@@ -154,7 +154,7 @@ def _summarize_model(model: dict, warnings: list[str], limit: int) -> dict:
|
|
|
154
154
|
|
|
155
155
|
|
|
156
156
|
def _summarize_states(
|
|
157
|
-
states, model: dict | None, warnings: list[str], limit: int
|
|
157
|
+
states, model: dict | None, warnings: list[str], limit: int | None
|
|
158
158
|
) -> dict:
|
|
159
159
|
# A columnar file is expanded to the per-frame layout so every check below
|
|
160
160
|
# describes the same thing for both layouts; `layout` records which one the
|
|
@@ -20,15 +20,22 @@ per file.
|
|
|
20
20
|
import bisect
|
|
21
21
|
import logging
|
|
22
22
|
import re
|
|
23
|
+
import sys
|
|
24
|
+
from array import array
|
|
23
25
|
from pathlib import Path
|
|
24
26
|
from typing import Sequence
|
|
25
27
|
|
|
26
28
|
from .columnar import (
|
|
29
|
+
COLUMNAR_VERSION,
|
|
27
30
|
STATE_FIELD_WIDTHS,
|
|
28
31
|
batch_rows,
|
|
32
|
+
blob_bytes,
|
|
29
33
|
blob_floats,
|
|
34
|
+
body_key,
|
|
35
|
+
columnarize_states,
|
|
30
36
|
encode_floats,
|
|
31
37
|
expand_columnar_states,
|
|
38
|
+
inline_blob,
|
|
32
39
|
is_blob,
|
|
33
40
|
is_columnar,
|
|
34
41
|
)
|
|
@@ -227,17 +234,10 @@ def _decode_per_batch(
|
|
|
227
234
|
|
|
228
235
|
|
|
229
236
|
def _load_json(path: Path) -> dict:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
#
|
|
233
|
-
|
|
234
|
-
# than teaching every step below a second shape. expand_columnar_states is
|
|
235
|
-
# stdlib-only, so this keeps merge usable on a base install.
|
|
236
|
-
if isinstance(doc, dict) and is_columnar(doc.get("states")):
|
|
237
|
-
model = doc.get("model")
|
|
238
|
-
batch_size = int((model or {}).get("simBatches", 1))
|
|
239
|
-
doc["states"] = expand_columnar_states(doc["states"], batch_size)
|
|
240
|
-
return doc
|
|
237
|
+
# Columnar states stay packed: merge_simulation_files chooses the output
|
|
238
|
+
# layout before expanding (expand_columnar_states is stdlib-only, so merge
|
|
239
|
+
# stays usable on a base install).
|
|
240
|
+
return loads_json(read_maybe_gzipped_bytes(path))
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
def _require(doc, key: str, expected_type: type | tuple[type, ...], label: str):
|
|
@@ -266,6 +266,76 @@ def _require(doc, key: str, expected_type: type | tuple[type, ...], label: str):
|
|
|
266
266
|
return node
|
|
267
267
|
|
|
268
268
|
|
|
269
|
+
def _validate_columnar_states(states: dict, batch_size: int, label: str) -> None:
|
|
270
|
+
times = states.get("times")
|
|
271
|
+
if not isinstance(times, list) or not times:
|
|
272
|
+
raise ValueError(f"'{label}' has no states")
|
|
273
|
+
previous = None
|
|
274
|
+
for idx, time in enumerate(times):
|
|
275
|
+
if previous is not None and time < previous:
|
|
276
|
+
raise ValueError(
|
|
277
|
+
f"'{label}': state times are not non-decreasing (times[{idx}] "
|
|
278
|
+
f"has time {time} after {previous})."
|
|
279
|
+
)
|
|
280
|
+
previous = time
|
|
281
|
+
|
|
282
|
+
bodies = states.get("bodies")
|
|
283
|
+
if not isinstance(bodies, list):
|
|
284
|
+
raise ValueError(f"File '{label}' has a non-list columnar 'states.bodies'.")
|
|
285
|
+
seen = set()
|
|
286
|
+
for idx, body in enumerate(bodies):
|
|
287
|
+
if not isinstance(body, dict) or "name" not in body:
|
|
288
|
+
raise ValueError(
|
|
289
|
+
f"File '{label}' has 'states.bodies[{idx}]' missing 'name'."
|
|
290
|
+
)
|
|
291
|
+
key = body_key(body["name"])
|
|
292
|
+
if key in seen:
|
|
293
|
+
raise ValueError(
|
|
294
|
+
f"File '{label}' lists body '{body['name']}' more than once."
|
|
295
|
+
)
|
|
296
|
+
seen.add(key)
|
|
297
|
+
fields = body.get("fields")
|
|
298
|
+
if not isinstance(fields, dict):
|
|
299
|
+
raise ValueError(
|
|
300
|
+
f"File '{label}' has 'states.bodies[{idx}].fields' of type "
|
|
301
|
+
f"{type(fields).__name__}; expected dict."
|
|
302
|
+
)
|
|
303
|
+
for field, value in fields.items():
|
|
304
|
+
width = STATE_FIELD_WIDTHS.get(field)
|
|
305
|
+
if width is None or not is_blob(value):
|
|
306
|
+
raise ValueError(
|
|
307
|
+
f"File '{label}' has an invalid columnar field "
|
|
308
|
+
f"'states.bodies[{idx}].fields.{field}'."
|
|
309
|
+
)
|
|
310
|
+
raw = blob_bytes(value)
|
|
311
|
+
expected = len(times) * batch_size * width
|
|
312
|
+
if len(raw) % 4 or len(raw) // 4 != expected:
|
|
313
|
+
raise ValueError(
|
|
314
|
+
f"File '{label}': body '{body['name']}' field '{field}' "
|
|
315
|
+
f"has {len(raw) // 4} floats; expected {expected}."
|
|
316
|
+
)
|
|
317
|
+
contacts = body.get("contacts")
|
|
318
|
+
if contacts is not None and not isinstance(contacts, list):
|
|
319
|
+
raise ValueError(
|
|
320
|
+
f"File '{label}' has a non-list contacts array for body "
|
|
321
|
+
f"'{body['name']}'."
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
scalars = states.get("scalars")
|
|
325
|
+
if scalars is not None and not isinstance(scalars, dict):
|
|
326
|
+
raise ValueError(f"File '{label}' has a non-dict columnar 'states.scalars'.")
|
|
327
|
+
for name, value in (scalars or {}).items():
|
|
328
|
+
if not is_blob(value):
|
|
329
|
+
raise ValueError(f"File '{label}' has an invalid columnar scalar '{name}'.")
|
|
330
|
+
raw = blob_bytes(value)
|
|
331
|
+
expected = len(times) * batch_size
|
|
332
|
+
if len(raw) % 4 or len(raw) // 4 != expected:
|
|
333
|
+
raise ValueError(
|
|
334
|
+
f"File '{label}': scalar '{name}' has {len(raw) // 4} floats; "
|
|
335
|
+
f"expected {expected}."
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
|
|
269
339
|
def _validate_doc(doc: dict, label: str) -> None:
|
|
270
340
|
"""Lightweight upfront structural check for a loaded SimView JSON document,
|
|
271
341
|
so malformed input fails fast with a clear message instead of a deep
|
|
@@ -289,23 +359,27 @@ def _validate_doc(doc: dict, label: str) -> None:
|
|
|
289
359
|
_require(doc, "model.terrain.heightData", (list, str), label)
|
|
290
360
|
if doc["model"]["terrain"].get("normals") is not None:
|
|
291
361
|
_require(doc, "model.terrain.normals", (list, str), label)
|
|
292
|
-
|
|
293
|
-
if
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
if not
|
|
298
|
-
raise ValueError(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
362
|
+
states = doc.get("states")
|
|
363
|
+
if isinstance(states, dict) and is_columnar(states):
|
|
364
|
+
_validate_columnar_states(states, int(doc["model"].get("simBatches", 1)), label)
|
|
365
|
+
else:
|
|
366
|
+
_require(doc, "states", list, label)
|
|
367
|
+
if not states:
|
|
368
|
+
raise ValueError(f"'{label}' has no states")
|
|
369
|
+
previous = None
|
|
370
|
+
for idx, state in enumerate(states):
|
|
371
|
+
if not isinstance(state, dict) or "time" not in state:
|
|
372
|
+
raise ValueError(
|
|
373
|
+
f"File '{label}' has 'states[{idx}]' missing 'time' -- is it "
|
|
374
|
+
"a valid SimView scene?"
|
|
375
|
+
)
|
|
376
|
+
# Resampling bisects each file's times, so they must be sorted.
|
|
377
|
+
if previous is not None and state["time"] < previous:
|
|
378
|
+
raise ValueError(
|
|
379
|
+
f"'{label}': state times are not non-decreasing "
|
|
380
|
+
f"(states[{idx}] has time {state['time']} after {previous})."
|
|
381
|
+
)
|
|
382
|
+
previous = state["time"]
|
|
309
383
|
|
|
310
384
|
|
|
311
385
|
def _expand_batched(
|
|
@@ -796,9 +870,156 @@ def _merge_states(
|
|
|
796
870
|
return merged_states
|
|
797
871
|
|
|
798
872
|
|
|
873
|
+
def _columnar_array(value: str) -> array:
|
|
874
|
+
"""Decode an inline float32 blob as an array without expanding per frame."""
|
|
875
|
+
values = array("f")
|
|
876
|
+
values.frombytes(blob_bytes(value))
|
|
877
|
+
if sys.byteorder == "big":
|
|
878
|
+
values.byteswap()
|
|
879
|
+
return values
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
def _merge_columnar_states(
|
|
883
|
+
states_list: list[dict],
|
|
884
|
+
batch_sizes: list[int],
|
|
885
|
+
bodies: list[dict],
|
|
886
|
+
scalar_names: list[str],
|
|
887
|
+
labels: list[str],
|
|
888
|
+
selections: list[list[int] | None],
|
|
889
|
+
) -> dict:
|
|
890
|
+
"""Merge columnar trajectories as flat arrays, never per-frame objects."""
|
|
891
|
+
ref_times = states_list[0]["times"]
|
|
892
|
+
times_by_file = [states["times"] for states in states_list]
|
|
893
|
+
frame_indices = [
|
|
894
|
+
[
|
|
895
|
+
out_idx if file_idx == 0 else _nearest_index(times_by_file[file_idx], t)
|
|
896
|
+
for out_idx, t in enumerate(ref_times)
|
|
897
|
+
]
|
|
898
|
+
for file_idx in range(len(states_list))
|
|
899
|
+
]
|
|
900
|
+
decoded_bodies = []
|
|
901
|
+
decoded_scalars = []
|
|
902
|
+
for states, batch_size in zip(states_list, batch_sizes):
|
|
903
|
+
body_map = {}
|
|
904
|
+
for body in states.get("bodies") or []:
|
|
905
|
+
key = body_key(body["name"])
|
|
906
|
+
body_map[key] = (
|
|
907
|
+
body,
|
|
908
|
+
{
|
|
909
|
+
field: _columnar_array(value)
|
|
910
|
+
for field, value in (body.get("fields") or {}).items()
|
|
911
|
+
},
|
|
912
|
+
)
|
|
913
|
+
decoded_bodies.append(body_map)
|
|
914
|
+
decoded_scalars.append(
|
|
915
|
+
{
|
|
916
|
+
name: _columnar_array(value)
|
|
917
|
+
for name, value in (states.get("scalars") or {}).items()
|
|
918
|
+
}
|
|
919
|
+
)
|
|
920
|
+
|
|
921
|
+
# Columnar blobs are time-major: every file's selected batches for one
|
|
922
|
+
# output frame come before the next output frame.
|
|
923
|
+
merged_bodies = []
|
|
924
|
+
for body in bodies:
|
|
925
|
+
if body.get("localTransform") is not None:
|
|
926
|
+
continue
|
|
927
|
+
key = body_key(body["name"])
|
|
928
|
+
available = set(body.get("availableAttributes") or [])
|
|
929
|
+
field_names = [
|
|
930
|
+
field
|
|
931
|
+
for field in STATE_FIELD_WIDTHS
|
|
932
|
+
if field == "bodyTransform" or field in available
|
|
933
|
+
]
|
|
934
|
+
merged_fields = {}
|
|
935
|
+
contacts = [] if "contacts" in available else None
|
|
936
|
+
|
|
937
|
+
for field in field_names:
|
|
938
|
+
merged = array("f")
|
|
939
|
+
width = STATE_FIELD_WIDTHS[field]
|
|
940
|
+
for out_idx, _ in enumerate(ref_times):
|
|
941
|
+
for file_idx, (body_map, batch_size, selection) in enumerate(
|
|
942
|
+
zip(decoded_bodies, batch_sizes, selections)
|
|
943
|
+
):
|
|
944
|
+
if key not in body_map or field not in body_map[key][1]:
|
|
945
|
+
raise ValueError(
|
|
946
|
+
f"'{labels[file_idx]}' body '{body['name']}' is missing "
|
|
947
|
+
f"'{field}'."
|
|
948
|
+
)
|
|
949
|
+
source = body_map[key][1][field]
|
|
950
|
+
frame_idx = frame_indices[file_idx][out_idx]
|
|
951
|
+
start = frame_idx * batch_size * width
|
|
952
|
+
selected = range(batch_size) if selection is None else selection
|
|
953
|
+
for batch_idx in selected:
|
|
954
|
+
merged.extend(
|
|
955
|
+
source[
|
|
956
|
+
start + batch_idx * width : start
|
|
957
|
+
+ (batch_idx + 1) * width
|
|
958
|
+
]
|
|
959
|
+
)
|
|
960
|
+
merged_fields[field] = encode_floats(merged)
|
|
961
|
+
|
|
962
|
+
if contacts is not None:
|
|
963
|
+
for out_idx, _ in enumerate(ref_times):
|
|
964
|
+
frame_contacts = []
|
|
965
|
+
for file_idx, (body_map, batch_size, selection) in enumerate(
|
|
966
|
+
zip(decoded_bodies, batch_sizes, selections)
|
|
967
|
+
):
|
|
968
|
+
if key not in body_map:
|
|
969
|
+
raise ValueError(
|
|
970
|
+
f"'{labels[file_idx]}' is missing body '{body['name']}'."
|
|
971
|
+
)
|
|
972
|
+
source_body = body_map[key][0]
|
|
973
|
+
frame_idx = frame_indices[file_idx][out_idx]
|
|
974
|
+
source_contacts = source_body.get("contacts")
|
|
975
|
+
value = (
|
|
976
|
+
source_contacts[frame_idx]
|
|
977
|
+
if source_contacts is not None
|
|
978
|
+
and frame_idx < len(source_contacts)
|
|
979
|
+
else None
|
|
980
|
+
)
|
|
981
|
+
if value is None:
|
|
982
|
+
value = [[] for _ in range(batch_size)]
|
|
983
|
+
frame_contacts.extend(_select(value, selection))
|
|
984
|
+
contacts.append(frame_contacts)
|
|
985
|
+
|
|
986
|
+
merged_body = {"name": body["name"], "fields": merged_fields}
|
|
987
|
+
if contacts is not None:
|
|
988
|
+
merged_body["contacts"] = contacts
|
|
989
|
+
merged_bodies.append(merged_body)
|
|
990
|
+
|
|
991
|
+
merged_scalars = {}
|
|
992
|
+
for scalar_name in scalar_names:
|
|
993
|
+
merged = array("f")
|
|
994
|
+
for out_idx, _ in enumerate(ref_times):
|
|
995
|
+
for file_idx, (scalars, batch_size, selection) in enumerate(
|
|
996
|
+
zip(decoded_scalars, batch_sizes, selections)
|
|
997
|
+
):
|
|
998
|
+
if scalar_name not in scalars:
|
|
999
|
+
raise ValueError(
|
|
1000
|
+
f"'{labels[file_idx]}' is missing scalar '{scalar_name}'."
|
|
1001
|
+
)
|
|
1002
|
+
source = scalars[scalar_name]
|
|
1003
|
+
frame_idx = frame_indices[file_idx][out_idx]
|
|
1004
|
+
start = frame_idx * batch_size
|
|
1005
|
+
selected = range(batch_size) if selection is None else selection
|
|
1006
|
+
for batch_idx in selected:
|
|
1007
|
+
merged.append(source[start + batch_idx])
|
|
1008
|
+
merged_scalars[scalar_name] = encode_floats(merged)
|
|
1009
|
+
|
|
1010
|
+
return {
|
|
1011
|
+
"version": COLUMNAR_VERSION,
|
|
1012
|
+
"times": ref_times,
|
|
1013
|
+
"bodies": merged_bodies,
|
|
1014
|
+
"scalars": merged_scalars,
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
|
|
799
1018
|
def merge_simulation_files(
|
|
800
1019
|
paths: Sequence[str | Path],
|
|
801
1020
|
selections: Sequence[str | Sequence[int] | None] | None = None,
|
|
1021
|
+
*,
|
|
1022
|
+
columnar_output: bool = False,
|
|
802
1023
|
) -> dict:
|
|
803
1024
|
"""Load and merge `paths` into a single `{"model": ..., "states": ...}` dict
|
|
804
1025
|
where each file's batches are concatenated into the output's batch dimension.
|
|
@@ -810,6 +1031,11 @@ def merge_simulation_files(
|
|
|
810
1031
|
what lets several files that each carry the same ground-truth batch be
|
|
811
1032
|
merged without duplicating it, and it is the one case where a single file
|
|
812
1033
|
is a valid merge input.
|
|
1034
|
+
|
|
1035
|
+
`columnar_output=True` returns a columnar states document when every input
|
|
1036
|
+
is columnar or columnarizable. That is the fast path used by the CLI and
|
|
1037
|
+
server; the default keeps the historical per-frame list for direct Python
|
|
1038
|
+
callers.
|
|
813
1039
|
"""
|
|
814
1040
|
resolved_paths = [Path(p) for p in paths]
|
|
815
1041
|
if selections is None:
|
|
@@ -862,9 +1088,30 @@ def merge_simulation_files(
|
|
|
862
1088
|
f"'{label}' has polylines, which cannot be merged across "
|
|
863
1089
|
"files or batch selections; drop them before merging."
|
|
864
1090
|
)
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1091
|
+
all_columnar = False
|
|
1092
|
+
if columnar_output:
|
|
1093
|
+
all_columnar = all(is_columnar(states) for states in states_list)
|
|
1094
|
+
for doc in docs:
|
|
1095
|
+
if not is_columnar(doc["states"]):
|
|
1096
|
+
converted = columnarize_states(doc["states"], doc["model"], inline_blob)
|
|
1097
|
+
if converted is not None:
|
|
1098
|
+
doc["states"] = converted
|
|
1099
|
+
states_list = [doc["states"] for doc in docs]
|
|
1100
|
+
all_columnar = all(is_columnar(states) for states in states_list)
|
|
1101
|
+
if columnar_output and all_columnar:
|
|
1102
|
+
merged_states = _merge_columnar_states(
|
|
1103
|
+
states_list, batch_sizes, bodies, scalar_names, labels, batch_selections
|
|
1104
|
+
)
|
|
1105
|
+
else:
|
|
1106
|
+
for doc in docs:
|
|
1107
|
+
if is_columnar(doc["states"]):
|
|
1108
|
+
doc["states"] = expand_columnar_states(
|
|
1109
|
+
doc["states"], int(doc["model"].get("simBatches", 1))
|
|
1110
|
+
)
|
|
1111
|
+
states_list = [doc["states"] for doc in docs]
|
|
1112
|
+
merged_states = _merge_states(
|
|
1113
|
+
states_list, batch_sizes, bodies, scalar_names, labels, batch_selections
|
|
1114
|
+
)
|
|
868
1115
|
|
|
869
1116
|
out_sizes = _output_sizes(batch_sizes, batch_selections)
|
|
870
1117
|
total_batches = sum(out_sizes)
|
|
@@ -221,14 +221,18 @@ def _fetch_argv(host: str, remote_path: str, has_gzip: bool) -> tuple[list[str],
|
|
|
221
221
|
def _fetch(host: str, remote_path: str, dest: Path, has_gzip: bool, size: int) -> int:
|
|
222
222
|
"""Stream the remote file to `dest`, returning the bytes actually transferred.
|
|
223
223
|
|
|
224
|
-
Decompression is incremental and the write goes to a '.partial'
|
|
225
|
-
only renamed into place once complete, so a 300MB scene is
|
|
226
|
-
memory whole and an interrupted fetch never leaves a
|
|
227
|
-
entry behind.
|
|
224
|
+
Decompression is incremental and the write goes to a unique '.partial'
|
|
225
|
+
file that is only renamed into place once complete, so a 300MB scene is
|
|
226
|
+
never held in memory whole and an interrupted fetch never leaves a
|
|
227
|
+
usable-looking cache entry behind.
|
|
228
228
|
"""
|
|
229
229
|
argv, gunzip = _fetch_argv(host, remote_path, has_gzip)
|
|
230
230
|
decomp = zlib.decompressobj(16 + zlib.MAX_WBITS) if gunzip else None
|
|
231
|
-
|
|
231
|
+
fd, partial_name = tempfile.mkstemp(
|
|
232
|
+
prefix=f".{dest.name}.", suffix=".partial", dir=dest.parent
|
|
233
|
+
)
|
|
234
|
+
partial = Path(partial_name)
|
|
235
|
+
os.close(fd)
|
|
232
236
|
wire = written = next_report = 0
|
|
233
237
|
|
|
234
238
|
try:
|
|
@@ -236,33 +240,42 @@ def _fetch(host: str, remote_path: str, dest: Path, has_gzip: bool, size: int) -
|
|
|
236
240
|
# can't fill the buffer and deadlock against our stdout read loop. stdin
|
|
237
241
|
# stays inherited so ssh can still prompt for a passphrase.
|
|
238
242
|
with tempfile.TemporaryFile() as errf:
|
|
243
|
+
proc = None
|
|
239
244
|
try:
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
try:
|
|
246
|
+
proc = subprocess.Popen(argv, stdout=subprocess.PIPE, stderr=errf)
|
|
247
|
+
except OSError as e: # pragma: no cover - broken ssh install
|
|
248
|
+
raise RemoteError(f"Could not run ssh: {e}") from e
|
|
249
|
+
assert proc.stdout is not None
|
|
250
|
+
with open(partial, "wb") as out:
|
|
251
|
+
while True:
|
|
252
|
+
chunk = proc.stdout.read(_CHUNK)
|
|
253
|
+
if not chunk:
|
|
254
|
+
break
|
|
255
|
+
wire += len(chunk)
|
|
256
|
+
if decomp is not None:
|
|
257
|
+
chunk = decomp.decompress(chunk)
|
|
258
|
+
out.write(chunk)
|
|
259
|
+
written += len(chunk)
|
|
260
|
+
if size and written >= next_report:
|
|
261
|
+
logger.info(
|
|
262
|
+
" %s / %s (%.0f%%)",
|
|
263
|
+
human_bytes(written),
|
|
264
|
+
human_bytes(size),
|
|
265
|
+
100.0 * written / size,
|
|
266
|
+
)
|
|
267
|
+
next_report = written + _PROGRESS_STEP
|
|
250
268
|
if decomp is not None:
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
next_report = written + _PROGRESS_STEP
|
|
262
|
-
if decomp is not None:
|
|
263
|
-
out.write(decomp.flush())
|
|
264
|
-
proc.stdout.close()
|
|
265
|
-
returncode = proc.wait()
|
|
269
|
+
out.write(decomp.flush())
|
|
270
|
+
proc.stdout.close()
|
|
271
|
+
returncode = proc.wait()
|
|
272
|
+
finally:
|
|
273
|
+
if proc is not None:
|
|
274
|
+
if proc.stdout is not None:
|
|
275
|
+
proc.stdout.close()
|
|
276
|
+
if proc.poll() is None:
|
|
277
|
+
proc.kill()
|
|
278
|
+
proc.wait()
|
|
266
279
|
errf.seek(0)
|
|
267
280
|
stderr = errf.read().decode("utf-8", "replace").strip()
|
|
268
281
|
|
|
@@ -146,7 +146,7 @@ def sample_states(
|
|
|
146
146
|
row = poses[b].get(lookup)
|
|
147
147
|
if row is None:
|
|
148
148
|
continue
|
|
149
|
-
out = {"position": row[:3], "orientation_wxyz": row[3:]}
|
|
149
|
+
out: dict = {"position": row[:3], "orientation_wxyz": row[3:]}
|
|
150
150
|
for f, rows in fields.items():
|
|
151
151
|
if rows is not None:
|
|
152
152
|
out[f] = rows[b]
|