perf(simulation): push current previews and streamline native sensor startup
This commit is contained in:
@@ -172,7 +172,7 @@ class InferencePreview:
|
||||
|
||||
def publish(self, rgb, values, observation, frame_id):
|
||||
now = time.monotonic()
|
||||
if now - self.last < 0.5:
|
||||
if now - self.last < 0.125:
|
||||
return
|
||||
self.last = now
|
||||
original = Image.fromarray(rgb)
|
||||
|
||||
@@ -188,7 +188,9 @@ class MountedSensors:
|
||||
class MountedRange:
|
||||
def __init__(self, rig, contact_height):
|
||||
from terrain import RangeSensor
|
||||
from carb import Float3
|
||||
|
||||
self.query_vector = lambda xyz: Float3(*xyz)
|
||||
legacy = RangeSensor()
|
||||
self.query = legacy.query
|
||||
self.mounts, self.contact_height = rig["mounts"], contact_height
|
||||
@@ -244,7 +246,7 @@ class MountedRange:
|
||||
origins.append(origin)
|
||||
observed, clear, depth, paths = mounted_range_returns(
|
||||
self.query, origin, rays @ rotation, key, self.mounts[key], self.rs_rays[:, 0],
|
||||
organized_ranges=view_ranges,
|
||||
organized_ranges=view_ranges, query_vector=self.query_vector,
|
||||
)
|
||||
points.extend(observed)
|
||||
ends.extend(clear)
|
||||
@@ -268,7 +270,8 @@ class MountedRange:
|
||||
return np.asarray(points, np.float32).reshape(-1, 3)
|
||||
|
||||
|
||||
def mounted_range_returns(query, origin, directions, key, spec, forward, *, organized_ranges=None):
|
||||
def mounted_range_returns(query, origin, directions, key, spec, forward, *,
|
||||
organized_ranges=None, query_vector=tuple):
|
||||
"""Same first-hit rays, with range filtering outside the Python query loop.
|
||||
|
||||
Keep per-beam ownership and order. A self hit never becomes a no-return
|
||||
@@ -277,14 +280,16 @@ def mounted_range_returns(query, origin, directions, key, spec, forward, *, orga
|
||||
"""
|
||||
count = len(directions)
|
||||
maximum = np.full(count, 8.0) if key == "k1" else np.minimum(8.0, 6.0 / forward)
|
||||
mount = tuple(origin)
|
||||
# PhysX consumes Float3 internally. Native callers avoid repeated pybind
|
||||
# sequence conversion; portable checks can use the identical tuple contract.
|
||||
mount = query_vector(origin)
|
||||
positions = np.full((count, 3), np.nan)
|
||||
no_hit = np.zeros(count, dtype=bool)
|
||||
paths = [None] * count
|
||||
for row, (direction, limit) in enumerate(
|
||||
zip(directions.tolist(), maximum.tolist(), strict=True)
|
||||
):
|
||||
hit = query.raycast_closest(mount, tuple(direction), limit, bothSides=True)
|
||||
hit = query.raycast_closest(mount, query_vector(direction), limit, bothSides=True)
|
||||
if not hit["hit"]:
|
||||
no_hit[row] = True
|
||||
elif not (
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Run-owned Isaac configuration without unrelated robot demonstration downloads.
|
||||
|
||||
Derive both SDK profiles, retaining every renderer/physics setting and every
|
||||
other dependency. Never edit the installed SDK or inherit persistent UI state.
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
DEMO = '"isaacsim.robot.policy.examples" = {}'
|
||||
BASE = '"isaacsim.exp.base" = {}'
|
||||
|
||||
|
||||
def prepare_experience(apps, directory):
|
||||
apps, directory = Path(apps).resolve(), Path(directory).resolve()
|
||||
base_path = apps / "isaacsim.exp.base.kit"
|
||||
python_path = apps / "isaacsim.exp.base.python.kit"
|
||||
base, python = base_path.read_text(), python_path.read_text()
|
||||
parsed_base, parsed_python = tomllib.loads(base), tomllib.loads(python)
|
||||
if not all(p["package"]["version"] == "6.1.0" for p in (parsed_base, parsed_python)):
|
||||
raise RuntimeError("Unsupported Isaac experience profile; expected 6.1.0")
|
||||
if base.count(DEMO) != 1 or python.count(BASE) != 1:
|
||||
raise RuntimeError("Isaac experience dependencies changed; review required")
|
||||
if parsed_python["settings"]["app"]["settings"]["persistent"] is not False:
|
||||
raise RuntimeError("Native simulation must not inherit persistent UI settings")
|
||||
# JSON strings are also valid TOML strings, including Windows path escaping.
|
||||
sdk = json.dumps(apps.as_posix())[1:-1]
|
||||
base = base.replace(DEMO, "").replace("${app}", sdk)
|
||||
python = python.replace(BASE, '"missioncore.native.base" = {}').replace("${app}", sdk)
|
||||
# Keep the SDK search paths and add only this run's derived base profile.
|
||||
folders = "'++' = ["
|
||||
if python.count(folders) != 1:
|
||||
raise RuntimeError("Isaac extension search paths changed; review required")
|
||||
python = python.replace(folders, folders + "\n " + json.dumps(directory.as_posix()) + ",", 1)
|
||||
tomllib.loads(base); tomllib.loads(python)
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
derived_base = directory / "missioncore.native.base.kit"
|
||||
derived_python = directory / "missioncore.native.python.kit"
|
||||
derived_base.write_text(base)
|
||||
derived_python.write_text(python)
|
||||
receipt = {
|
||||
"schema_version": "missioncore.native-experience/v1",
|
||||
"excluded_dependency": "isaacsim.robot.policy.examples",
|
||||
"sources": {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in (base_path, python_path)},
|
||||
"derived": {p.name: hashlib.sha256(p.read_bytes()).hexdigest() for p in (derived_base, derived_python)},
|
||||
}
|
||||
(directory / "receipt.json").write_text(json.dumps(receipt, indent=2))
|
||||
return str(derived_python)
|
||||
@@ -74,15 +74,23 @@ def acquire_service_lock(path):
|
||||
|
||||
def publish_previews(client, episode, run_id, stopped):
|
||||
"""Best-effort view telemetry has its own connection and never delays control."""
|
||||
last_frame = -1
|
||||
while not stopped.wait(0.5):
|
||||
last_frame, last_modified = -1, None
|
||||
path = episode / "inference-preview.json"
|
||||
while not stopped.wait(0.05):
|
||||
try:
|
||||
preview = read_json(episode / "inference-preview.json")
|
||||
if not path.exists():
|
||||
continue
|
||||
modified = path.stat().st_mtime_ns
|
||||
if modified == last_modified:
|
||||
continue
|
||||
preview = read_json(path)
|
||||
if preview and preview["frame_id"] > last_frame:
|
||||
client.request("/worker/runs/" + run_id + "/inference-preview", preview)
|
||||
last_frame = preview["frame_id"]
|
||||
last_modified = modified
|
||||
except Exception as exc:
|
||||
logging.warning("Inference preview unavailable: %s", type(exc).__name__)
|
||||
stopped.wait(1)
|
||||
|
||||
|
||||
def preparation_heartbeat(client, hello, run_id):
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import argparse
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
@@ -62,6 +63,7 @@ def main():
|
||||
CONTROL_PROFILE = robot["control"]
|
||||
startup_phase("native-runtime")
|
||||
from isaacsim import SimulationApp
|
||||
from native_experience import prepare_experience
|
||||
|
||||
app = SimulationApp(
|
||||
{
|
||||
@@ -85,7 +87,8 @@ def main():
|
||||
"--/app/runLoops/main/manualModeEnabled=false",
|
||||
"--/exts/isaacsim.core.throttling/enable_manualmode=false",
|
||||
],
|
||||
}
|
||||
},
|
||||
experience=prepare_experience(os.environ["EXP_PATH"], directory / "native-experience"),
|
||||
)
|
||||
import carb.settings
|
||||
import numpy as np
|
||||
|
||||
Reference in New Issue
Block a user