7f39abb613
Add declarative single-leg import, fixed-anchor benchmark, masked shared-policy PPO prototype, regression tests, and consolidated documentation.
133 lines
5.9 KiB
Python
133 lines
5.9 KiB
Python
"""Shared finite benchmark launcher; preserve failures through Kit fast shutdown."""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
import traceback
|
|
from pathlib import Path
|
|
|
|
from runtime_common import finish_run, write_json
|
|
|
|
TASK = "SkillFactory-SingleLegAnchor-Go2-v0"
|
|
|
|
|
|
def launch(description, configure_parser, run):
|
|
if not __debug__:
|
|
raise RuntimeError("Benchmark assertions require Python without -O/PYTHONOPTIMIZE")
|
|
if sys.version_info[:2] != (3, 12):
|
|
raise RuntimeError("Use /home/cen/IsaacLab/isaaclab.sh -p with Python 3.12, not the old conda environment")
|
|
for key in ("CONDA_PREFIX", "VIRTUAL_ENV"):
|
|
if os.environ.get(key):
|
|
print(f"[WARNING] Active {key}={os.environ[key]}; actual interpreter: {sys.executable}")
|
|
from isaaclab_tasks.utils import add_launcher_args, launch_simulation, resolve_task_config, setup_preset_cli
|
|
|
|
parser = argparse.ArgumentParser(description=description)
|
|
parser.add_argument("--task", default=TASK)
|
|
parser.add_argument("--num_envs", type=int, default=64)
|
|
parser.add_argument("--seed", type=int, default=42)
|
|
parser.add_argument("--anchor_height", type=float, default=None)
|
|
parser.add_argument("--output", type=Path, default=Path("logs/week1_anchor/smoke"))
|
|
configure_parser(parser)
|
|
add_launcher_args(parser)
|
|
args, hydra_args = setup_preset_cli(parser)
|
|
sys.argv = [sys.argv[0]] + hydra_args
|
|
# Our selected backend is known to require Kit. Start it before resolving
|
|
# configs: action classes can import pxr and preload an incompatible USD.
|
|
from isaaclab.app import AppLauncher
|
|
|
|
app = AppLauncher(args).app
|
|
code = 0
|
|
env = None
|
|
args.output.mkdir(parents=True, exist_ok=True)
|
|
result = {"passed": False, "status": "running"}
|
|
write_json(args.output / "result.json", result)
|
|
try:
|
|
import SkillFactory.tasks # noqa: F401
|
|
|
|
cfg, _ = resolve_task_config(args.task, "")
|
|
cfg.scene.num_envs = args.num_envs
|
|
cfg.seed = args.seed
|
|
cfg.terminations.time_out = None # no automatic reset hiding verification failures
|
|
if getattr(args, "suite", None) == "stability" and args.anchor_height is None:
|
|
args.anchor_height = 0.6
|
|
if args.anchor_height is not None:
|
|
cfg.scene.robot.init_state.pos = (0.0, 0.0, args.anchor_height)
|
|
if getattr(args, "suite", None) == "calibration":
|
|
import isaaclab.sim as sim_utils
|
|
from isaaclab.assets import RigidObjectCfg
|
|
from isaaclab.sensors import ContactSensorCfg
|
|
|
|
cfg.scene.calibration_probe = RigidObjectCfg(
|
|
prim_path="{ENV_REGEX_NS}/Probe",
|
|
spawn=sim_utils.SphereCfg(
|
|
radius=0.05,
|
|
mass_props=sim_utils.MassPropertiesCfg(mass=1.0),
|
|
rigid_props=sim_utils.RigidBodyPropertiesCfg(),
|
|
collision_props=sim_utils.CollisionPropertiesCfg(),
|
|
activate_contact_sensors=True,
|
|
),
|
|
init_state=RigidObjectCfg.InitialStateCfg(pos=(0.7, 0.0, 0.3)),
|
|
)
|
|
cfg.scene.probe_contact = ContactSensorCfg(
|
|
prim_path="{ENV_REGEX_NS}/Probe",
|
|
update_period=0.0,
|
|
history_length=5,
|
|
filter_prim_paths_expr=cfg.scene.foot_contact.filter_prim_paths_expr,
|
|
)
|
|
# Kit is already launched, so this context performs backend setup but
|
|
# does not own app.close(). We retain the failure exit code ourselves.
|
|
with launch_simulation(cfg, args):
|
|
import gymnasium as gym
|
|
import torch
|
|
|
|
torch.manual_seed(args.seed)
|
|
env = gym.make(args.task, cfg=cfg)
|
|
u = env.unwrapped
|
|
from pxr import UsdPhysics
|
|
|
|
from isaaclab.sim import get_current_stage
|
|
|
|
stage = get_current_stage()
|
|
grounds = [
|
|
str(p.GetPath())
|
|
for p in stage.Traverse()
|
|
if str(p.GetPath()).startswith("/World/ground/") and p.HasAPI(UsdPhysics.CollisionAPI)
|
|
]
|
|
expected = cfg.scene.foot_contact.filter_prim_paths_expr
|
|
if grounds != expected:
|
|
raise RuntimeError(f"Ground collision mapping mismatch: actual={grounds}, expected={expected}")
|
|
assert u.scene["foot_contact"].num_sensors == 1
|
|
assert u.scene["foot_contact"].data.force_matrix_w.torch.shape == (args.num_envs, 1, 1, 3)
|
|
import importlib.metadata
|
|
|
|
from SkillFactory.assets.go2_leg import CONVERSION, MANIFEST
|
|
|
|
body_masses = u.scene["robot"].data.body_mass.torch[0].tolist()
|
|
asset_report = {
|
|
"source": MANIFEST["source"],
|
|
"derived_urdf_sha256": MANIFEST["derived_urdf_sha256"],
|
|
"conversion": CONVERSION,
|
|
"backend": "Kit PhysxCfg",
|
|
"python": sys.version,
|
|
"packages": {n: importlib.metadata.version(n) for n in ("isaaclab", "isaaclab-physx", "torch")},
|
|
"effective_body_mass_kg": dict(zip(u.scene["robot"].body_names, body_masses)),
|
|
"missing_inertial_fixed_links": MANIFEST["missing_inertial_fixed_links"],
|
|
"inertial_handling": (
|
|
"Fixed auxiliary colliders preserved; PhysX mass inferred from geometry/default density"
|
|
),
|
|
"pd": MANIFEST["control"],
|
|
"ground_colliders": grounds,
|
|
}
|
|
write_json(args.output / "physical_asset.json", asset_report)
|
|
result = run(env, args)
|
|
print(json.dumps(result, indent=2), flush=True)
|
|
except BaseException:
|
|
traceback.print_exc()
|
|
code = 1
|
|
error = traceback.format_exc()
|
|
(args.output / "failure.txt").write_text(error)
|
|
result = {"passed": False, "error": error}
|
|
finally:
|
|
finish_run(app, env, args.output / "result.json", result, code)
|