feat: release v0.3 with RP1 trained skills and scaled arenas
This commit is contained in:
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Stage a completed RP1 BeyondMimic STUDENT actor + reference. Never starts training.
|
||||
|
||||
Use roboparty_train/.venv/bin/python. Stages skills disabled; enable only after
|
||||
real physics playback/transition validation. Trusted local checkpoints only.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
import numpy as np
|
||||
import onnx
|
||||
from onnx.reference import ReferenceEvaluator
|
||||
import torch
|
||||
import yaml
|
||||
|
||||
|
||||
def sha(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def dump(path, value):
|
||||
temp = path.with_suffix(path.suffix + ".tmp")
|
||||
temp.write_text(json.dumps(value, indent=2, ensure_ascii=False, allow_nan=False) + "\n")
|
||||
temp.replace(path)
|
||||
|
||||
|
||||
def parameter(value, name):
|
||||
if not isinstance(value, dict):
|
||||
return float(value)
|
||||
matches = [float(v) for p, v in value.items() if re.fullmatch(p, name)]
|
||||
if len(matches) != 1:
|
||||
raise ValueError(f"Actuator parameter is ambiguous/missing: {name}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__)
|
||||
p.add_argument("--checkpoint", type=Path, required=True)
|
||||
p.add_argument("--skill", choices=["dance", "wave"], required=True)
|
||||
p.add_argument("--duration", type=float, help="Episode seconds; dance defaults to the trained 10s horizon, wave to its full clip")
|
||||
p.add_argument("--package", type=Path, default=Path(__file__).resolve().parents[1] / "public/robots/rp1")
|
||||
args = p.parse_args()
|
||||
cp, target, skill_id = args.checkpoint.resolve(), args.package.resolve(), args.skill
|
||||
params = cp.parent / "params"
|
||||
env = yaml.load((params / "env.yaml").read_text(), Loader=yaml.BaseLoader)
|
||||
agent = yaml.load((params / "agent.yaml").read_text(), Loader=yaml.BaseLoader)
|
||||
config = json.loads((target / "robot.json").read_text())
|
||||
robot, group = env["scene"]["robot"], env["observations"]["student"]
|
||||
names = config["joints"]["groups"]["policy"]
|
||||
action = env["actions"]["joint_pos"]
|
||||
expected_terms = ["command", "base_ang_vel", "projected_gravity", "joint_pos", "joint_vel", "actions"]
|
||||
expected_funcs = ["generated_commands", "base_ang_vel", "projected_gravity", "joint_pos_rel", "joint_vel_rel", "last_action"]
|
||||
terms = [(k, v) for k, v in group.items() if isinstance(v, dict) and "func" in v]
|
||||
if not (
|
||||
agent["obs_groups"]["actor"] == ["student"]
|
||||
and group["history_length"] == "1"
|
||||
and group["concatenate_terms"] == "true"
|
||||
and [k for k, _ in terms] == expected_terms
|
||||
and [v["func"].split(":")[-1] for _, v in terms] == expected_funcs
|
||||
and all(v.get("scale") == "null" and v.get("clip") == "null"
|
||||
and v.get("modifiers") == "null" and v.get("delay_max_lag") == "0" for _, v in terms)
|
||||
and agent["actor"]["activation"] == "elu"
|
||||
and agent["actor"]["obs_normalization"] == "true"
|
||||
and agent["clip_actions"] == "null"
|
||||
and robot["joint_ordering"] == action["joint_names"] == names
|
||||
and action["preserve_order"] == action["use_default_offset"] == "true"
|
||||
and action["clip"] == "null" and float(action["offset"]) == 0
|
||||
and len(names) == 24
|
||||
and all(float(v) == 0 for v in robot["init_state"]["joint_vel"].values())
|
||||
and config["sim"] == {"timestep": float(env["sim"]["dt"]), "decimation": int(env["decimation"])}
|
||||
):
|
||||
raise ValueError("Unsupported logged actor/observation/action contract; update explicitly")
|
||||
actuator = robot["actuators"]["all_joints"]
|
||||
for n in names:
|
||||
for out, key in {"kp": "stiffness", "kd": "damping", "torque_limit": "actuator_effort_limit",
|
||||
"velocity_limit": "actuator_velocity_limit", "keep_velocity": "keep_velocity"}.items():
|
||||
if abs(config["actuation"]["joints"][n][out] - parameter(actuator[key], n)) > 1e-8:
|
||||
raise ValueError(f"Per-skill actuator contract differs: {n}/{out}")
|
||||
before = sha(cp)
|
||||
saved = torch.load(cp, map_location="cpu", weights_only=True)
|
||||
if int(saved["iter"]) < int(agent["max_iterations"]) - 1 or cp.stem != f"model_{saved['iter']}":
|
||||
raise ValueError("Only the final configured checkpoint may be imported")
|
||||
state = saved["actor_state_dict"]
|
||||
shapes = [(512, 126), (256, 512), (128, 256), (24, 128)]
|
||||
if any(tuple(state[f"mlp.{2*i}.weight"].shape) != shape for i, shape in enumerate(shapes)):
|
||||
raise ValueError("Unsupported actor architecture")
|
||||
if any(not torch.isfinite(v).all() for v in state.values()) or (state["obs_normalizer._std"] < 0).any():
|
||||
raise ValueError("Invalid checkpoint tensors")
|
||||
|
||||
class Actor(torch.nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.register_buffer("mean", state["obs_normalizer._mean"])
|
||||
self.register_buffer("std", state["obs_normalizer._std"])
|
||||
layers = []
|
||||
for i, (out_size, in_size) in enumerate(shapes):
|
||||
layer = torch.nn.Linear(in_size, out_size)
|
||||
layer.load_state_dict({"weight": state[f"mlp.{2*i}.weight"], "bias": state[f"mlp.{2*i}.bias"]})
|
||||
layers.append(layer)
|
||||
if i < len(shapes) - 1:
|
||||
layers.append(torch.nn.ELU())
|
||||
self.mlp = torch.nn.Sequential(*layers)
|
||||
|
||||
def forward(self, obs):
|
||||
return self.mlp((obs - self.mean) / (self.std + 1e-2))
|
||||
|
||||
motion_file = Path(env["commands"]["motion"]["motion_file"])
|
||||
with np.load(motion_file, allow_pickle=False) as motion:
|
||||
source_names = list(motion["joint_names"].astype(str))
|
||||
order = [source_names.index(n) for n in names]
|
||||
pos, vel = motion["joint_pos"][:, order], motion["joint_vel"][:, order]
|
||||
fps = float(motion["fps"].item())
|
||||
dt = config["sim"]["timestep"] * config["sim"]["decimation"]
|
||||
if abs(fps * dt - 1) > 1e-9 or pos.shape != vel.shape or pos.shape[1] != 24 or len(pos) < 2:
|
||||
raise ValueError("Motion/control clock or shape mismatch (no silent resampling)")
|
||||
if not (np.isfinite(pos).all() and np.isfinite(vel).all()):
|
||||
raise ValueError("Non-finite motion")
|
||||
duration = args.duration if args.duration is not None else min(10.0, len(pos) * dt)
|
||||
if not np.isfinite(duration) or not 0 < duration <= len(pos) * dt:
|
||||
raise ValueError("Duration must be within the reference clip")
|
||||
defaults = {n: float(robot["init_state"]["joint_pos"][n]) for n in names}
|
||||
for folder in ["policies", "motions"]:
|
||||
(target / folder).mkdir(exist_ok=True)
|
||||
policy = target / f"policies/{skill_id}.export.onnx"
|
||||
actor = Actor().eval()
|
||||
torch.onnx.export(actor, torch.zeros(1, 126), str(policy), input_names=["obs"],
|
||||
output_names=["actions"], opset_version=17, dynamo=False)
|
||||
model = onnx.load(policy)
|
||||
onnx.helper.set_model_props(model, {"checkpoint": cp.name, "checkpoint_sha256": before,
|
||||
"iteration": str(saved["iter"]), "actor_observation_group": "student",
|
||||
"joint_names": ",".join(names), "default_joint_pos": ",".join(map(str, defaults.values())),
|
||||
"motion_sha256": sha(motion_file), "status": "completed-training"})
|
||||
onnx.checker.check_model(model)
|
||||
onnx.save(model, policy)
|
||||
evaluator = ReferenceEvaluator(model)
|
||||
rng = np.random.default_rng(42)
|
||||
samples = [np.zeros((1, 126), np.float32), *[rng.normal(size=(1, 126)).astype(np.float32) for _ in range(16)]]
|
||||
standing = np.r_[pos[0], vel[0], [0, 0, 0], [0, 0, -1], np.zeros(72)].astype(np.float32)[None]
|
||||
samples.append(standing)
|
||||
error = 0.0
|
||||
for obs in samples:
|
||||
with torch.no_grad():
|
||||
expected = actor(torch.from_numpy(obs)).numpy()
|
||||
actual = evaluator.run(None, {"obs": obs})[0]
|
||||
np.testing.assert_allclose(actual, expected, rtol=2e-4, atol=2e-5)
|
||||
error = max(error, float(np.max(np.abs(actual - expected))))
|
||||
if before != sha(cp):
|
||||
raise ValueError("Checkpoint changed during export")
|
||||
policy.replace(target / f"policies/{skill_id}.onnx")
|
||||
binary = target / f"motions/{skill_id}.f32"
|
||||
temp = binary.with_suffix(".tmp")
|
||||
temp.write_bytes(np.concatenate([pos.ravel(), vel.ravel()]).astype("<f4").tobytes())
|
||||
temp.replace(binary)
|
||||
dump(target / f"motions/{skill_id}.json", {"schema": 1, "layout": "positions_then_velocities",
|
||||
"dtype": "float32-le", "step_dt": dt, "frames": len(pos), "joint_names": names,
|
||||
"data": f"motions/{skill_id}.f32"})
|
||||
skill = next(s for s in config["skills"] if s["id"] == skill_id)
|
||||
skill.update({"available": False, "duration": duration, "blend": 0.5,
|
||||
"defaults": defaults, "reference": f"motions/{skill_id}.json",
|
||||
"observations": {"obs": {"terms": [{"type": "motion_command", "group": "policy"},
|
||||
{"type": "gyro", "sensor": config["observations"]["obs"]["terms"][0]["sensor"]},
|
||||
{"type": "projected_gravity", "body": "base_link"},
|
||||
{"type": "joint_pos_rel", "group": "policy"}, {"type": "joint_vel", "group": "policy"},
|
||||
{"type": "last_action", "group": "policy"}]}},
|
||||
"actions": [{"type": "joint_position", "group": "policy", "scale": float(action["scale"]), "offset": "default"}],
|
||||
"controller": {"type": "onnx", "policy": f"policies/{skill_id}.onnx"}})
|
||||
next(b for b in config["input"]["bindings"] if b["action"] == f"skill:{skill_id}")["disabled"] = True
|
||||
provenance_path = target / "source-manifest.json"
|
||||
provenance = json.loads(provenance_path.read_text())
|
||||
provenance.setdefault("skills", {})[skill_id] = {"checkpoint": str(cp), "checkpoint_sha256": before,
|
||||
"iteration": int(saved["iter"]), "configured_iterations": int(agent["max_iterations"]),
|
||||
"motion": str(motion_file), "motion_sha256": sha(motion_file), "frames": len(pos), "fps": fps,
|
||||
"actor_observation_group": "student", "export_max_abs_error": error,
|
||||
"training_params_sha256": {n: sha(params / n) for n in ["env.yaml", "agent.yaml"]},
|
||||
"deployed_duration": duration, "validation": "staged-disabled"}
|
||||
for f in [f"policies/{skill_id}.onnx", f"motions/{skill_id}.json", f"motions/{skill_id}.f32"]:
|
||||
provenance["files"] = [r for r in provenance["files"] if r["file"] != f]
|
||||
provenance["files"].append({"file": f, "sha256": sha(target / f)})
|
||||
dump(provenance_path, provenance)
|
||||
dump(target / "robot.json", config)
|
||||
print(f"Staged {skill_id}: final {saved['iter']}, 126→24, {len(pos)} frames / {len(pos)*dt:.2f}s, max error {error:.3g}. DISABLED pending playback validation.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Import a trusted RP1-Flat checkpoint without starting/stopping Isaac Lab.
|
||||
|
||||
Run with roboparty_train/.venv/bin/python. Never run on an untrusted .pt file.
|
||||
Only the logged 24-DOF Direct/term-major/ELU MLP contract is supported.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import numpy as np
|
||||
import onnx
|
||||
from onnx.reference import ReferenceEvaluator
|
||||
import torch
|
||||
import yaml
|
||||
|
||||
|
||||
def dump(path, value):
|
||||
path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n")
|
||||
|
||||
|
||||
def sha(path):
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def resolve_parameter(value, name):
|
||||
if not isinstance(value, dict):
|
||||
return float(value)
|
||||
matches = [float(v) for pattern, v in value.items() if re.fullmatch(pattern, name)]
|
||||
if len(matches) != 1:
|
||||
raise ValueError(f"Ambiguous/missing actuator parameter: {name}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--source", type=Path, required=True)
|
||||
parser.add_argument("--checkpoint", type=Path, required=True)
|
||||
parser.add_argument("--policy-only", action="store_true", help="Preserve assets/other skills; replace walk ONNX and provenance only")
|
||||
parser.add_argument("--completed", action="store_true", help="Require final configured iteration and mark walking training complete")
|
||||
args = parser.parse_args()
|
||||
source, checkpoint = args.source.resolve(), args.checkpoint.resolve()
|
||||
public = Path(__file__).resolve().parents[1] / "public" / "robots"
|
||||
target = public / "rp1"
|
||||
params = checkpoint.parent / "params"
|
||||
# BaseLoader reads YAML data only, ignoring Python object construction tags.
|
||||
env = yaml.load((params / "env.yaml").read_text(), Loader=yaml.BaseLoader)
|
||||
agent = yaml.load((params / "agent.yaml").read_text(), Loader=yaml.BaseLoader)
|
||||
robot = env["scene_context"]["robot"]
|
||||
names = robot["joint_ordering"]
|
||||
if not (len(names) == 24 and env["robot"]["observation_history_layout"] == "term_major"
|
||||
and env["robot"]["actor_obs_history_length"] == "3"
|
||||
and agent["actor"]["activation"] == "elu"
|
||||
and agent["actor"]["obs_normalization"] == "true"
|
||||
and all(float(v) == 1 for v in env["normalization"]["obs_scales"].values())):
|
||||
raise ValueError("Unsupported training contract; update importer explicitly")
|
||||
defaults = {n: float(robot["init_state"]["joint_pos"][n]) for n in names}
|
||||
if args.policy_only:
|
||||
current = json.loads((target / "robot.json").read_text())
|
||||
if not (current["joints"]["groups"]["policy"] == names
|
||||
and current["joints"]["defaults"] == defaults
|
||||
and current["actions"][0]["scale"] == float(env["robot"]["action_scale"])
|
||||
and current["sim"] == {"timestep": float(env["sim"]["dt"]), "decimation": int(env["decimation"])}):
|
||||
raise ValueError("Training contract changed; full re-import/revalidation required")
|
||||
saved = torch.load(checkpoint, map_location="cpu", weights_only=True)
|
||||
if args.completed and int(saved["iter"]) < int(agent["max_iterations"]) - 1:
|
||||
raise ValueError("--completed requires the final configured training iteration")
|
||||
state = saved["actor_state_dict"]
|
||||
expected = [(512, 243), (256, 512), (128, 256), (24, 128)]
|
||||
if any(tuple(state[f"mlp.{2*i}.weight"].shape) != shape for i, shape in enumerate(expected)):
|
||||
raise ValueError("Unsupported actor architecture")
|
||||
if any(not torch.isfinite(v).all() for v in state.values()):
|
||||
raise ValueError("Non-finite checkpoint")
|
||||
|
||||
class Actor(torch.nn.Module):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.register_buffer("mean", state["obs_normalizer._mean"])
|
||||
self.register_buffer("std", state["obs_normalizer._std"])
|
||||
layers = []
|
||||
for i, (out_size, in_size) in enumerate(expected):
|
||||
layer = torch.nn.Linear(in_size, out_size)
|
||||
layer.load_state_dict({"weight": state[f"mlp.{2*i}.weight"], "bias": state[f"mlp.{2*i}.bias"]})
|
||||
layers.append(layer)
|
||||
if i < len(expected) - 1:
|
||||
layers.append(torch.nn.ELU())
|
||||
self.mlp = torch.nn.Sequential(*layers)
|
||||
|
||||
def forward(self, obs):
|
||||
# RSL-RL EmpiricalNormalization epsilon is 1e-2, not sqrt(var+eps).
|
||||
action = self.mlp((obs - self.mean) / (self.std + 1e-2))
|
||||
return action.clamp(-float(agent["clip_actions"]), float(agent["clip_actions"]))
|
||||
|
||||
for folder in ["policies", "meshes", "LICENSES"]:
|
||||
(target / folder).mkdir(parents=True, exist_ok=True)
|
||||
actor = Actor().eval()
|
||||
policy = target / "policies" / "walk.export.onnx"
|
||||
torch.onnx.export(actor, torch.zeros(1, 243), str(policy), input_names=["obs"],
|
||||
output_names=["actions"], opset_version=17, dynamo=False)
|
||||
model = onnx.load(policy)
|
||||
onnx.helper.set_model_props(model, {
|
||||
"checkpoint": checkpoint.name, "checkpoint_sha256": sha(checkpoint),
|
||||
"iteration": str(saved["iter"]), "joint_names": ",".join(names),
|
||||
"default_joint_pos": ",".join(str(robot["init_state"]["joint_pos"][n]) for n in names),
|
||||
"history_layout": "term_major", "history_length": "3", "status": "completed-training" if args.completed else "training-preview",
|
||||
})
|
||||
onnx.checker.check_model(model)
|
||||
onnx.save(model, policy)
|
||||
evaluator = ReferenceEvaluator(model)
|
||||
rng = np.random.default_rng(42)
|
||||
max_error = 0.0
|
||||
for obs in [np.zeros((1, 243), dtype=np.float32), *[rng.normal(size=(1, 243)).astype(np.float32) for _ in range(8)]]:
|
||||
with torch.no_grad():
|
||||
expected_action = actor(torch.from_numpy(obs)).numpy()
|
||||
actual = evaluator.run(None, {"obs": obs})[0]
|
||||
np.testing.assert_allclose(actual, expected_action, rtol=2e-4, atol=2e-5)
|
||||
max_error = max(max_error, float(np.abs(actual - expected_action).max()))
|
||||
|
||||
policy.replace(target / "policies" / "walk.onnx")
|
||||
if args.policy_only:
|
||||
provenance_file = target / "source-manifest.json"
|
||||
provenance = json.loads(provenance_file.read_text())
|
||||
provenance.update({"training_completed": args.completed, "checkpoint": str(checkpoint), "checkpoint_sha256": sha(checkpoint),
|
||||
"iteration": int(saved["iter"]), "export_max_abs_error": max_error,
|
||||
"training_params_sha256": {name: sha(params / name) for name in ["env.yaml", "agent.yaml"]}})
|
||||
for record in provenance["files"]:
|
||||
if record["file"] == "policies/walk.onnx":
|
||||
record["sha256"] = sha(target / record["file"])
|
||||
dump(provenance_file, provenance)
|
||||
if args.completed:
|
||||
current["name"] = "RP1"
|
||||
dump(target / "robot.json", current)
|
||||
print(f"Updated walk policy only: iteration {saved['iter']}, max error {max_error:.3g}")
|
||||
return
|
||||
|
||||
asset_root = source / "robolab" / "data" / "robots" / "roboparty" / "rp1"
|
||||
tree = ET.parse(asset_root / "mjcf" / "robot_24dof.xml")
|
||||
root = tree.getroot()
|
||||
root.find("compiler").set("meshdir", ".")
|
||||
assets = []
|
||||
for mesh in root.findall("./asset/mesh"):
|
||||
rel = mesh.attrib["file"]
|
||||
shutil.copyfile(asset_root / rel, target / rel)
|
||||
assets.append({"path": rel, "vfs": rel})
|
||||
tree.write(target / "model.xml", encoding="utf-8", xml_declaration=True)
|
||||
actuator = robot["actuators"]["all_joints"]
|
||||
parameters = {}
|
||||
for name in names:
|
||||
parameters[name] = {out: resolve_parameter(actuator[key], name) for out, key in {
|
||||
"kp": "stiffness", "kd": "damping", "torque_limit": "actuator_effort_limit",
|
||||
"velocity_limit": "actuator_velocity_limit", "keep_velocity": "keep_velocity",
|
||||
}.items()}
|
||||
config = json.loads((public / "microban" / "robot.json").read_text())
|
||||
config.update({
|
||||
"id": "rp1", "family": "rp1", "name": "RP1" if args.completed else "RP1 (training preview)",
|
||||
"dimensions": {"height": 1.32},
|
||||
"assets": assets,
|
||||
"base": {"type": "floating", "root_body": "base_link", "freejoint": "base_link_freejoint",
|
||||
"spawn": {"pos": [float(v) for v in robot["init_state"]["pos"]], "yaw": 0}, "initial": defaults},
|
||||
"sim": {"timestep": float(env["sim"]["dt"]), "decimation": int(env["decimation"])},
|
||||
"joints": {"groups": {"policy": names}, "defaults": defaults},
|
||||
"observations": {"obs": {"history": 3, "layout": "term_major", "terms": [
|
||||
{"type": "gyro", "sensor": "base_ang_vel"},
|
||||
{"type": "projected_gravity", "body": "base_link"},
|
||||
{"type": "command", "size": 3},
|
||||
{"type": "joint_pos_rel", "group": "policy"},
|
||||
{"type": "joint_vel", "group": "policy"},
|
||||
{"type": "last_action", "group": "policy"},
|
||||
]}},
|
||||
"actions": [{"type": "joint_position", "group": "policy", "scale": float(env["robot"]["action_scale"]), "offset": "default"}],
|
||||
"actuation": {"type": "joint_pd", "kp": 120, "kd": 7.5, "torque_limit": 140, "joints": parameters},
|
||||
"commands": {"size": 3, "limits": [0.4, -0.3, 0.6]},
|
||||
"skills": [{"id": "walk", "kind": "primary", "owns": "policy", "controller": {"type": "onnx", "policy": "policies/walk.onnx"}},
|
||||
*[{"id": s, "kind": "episodic", "owns": "policy", "available": False,
|
||||
"duration": d, "blend": 0.5, "controller": {"type": "onnx"}} for s, d in [("dance", 10), ("wave", 4)]]],
|
||||
"render": {"source": "mjcf_visual", "groups": [2], "camera": {"distance": 2.4}},
|
||||
"termination": {"tilt_z": -0.5, "min_height": 0.4, "on_fall": "hold"},
|
||||
"license": "Training preview; RP1 mesh license not supplied upstream. Local evaluation only; see SOURCE.md. Actuation omits randomized delay/domain randomization.",
|
||||
})
|
||||
config["input"]["bindings"] = [b for b in config["input"]["bindings"] if not b["action"].startswith("toggle:")]
|
||||
config["input"]["bindings"].extend([
|
||||
{"action": "skill:dance", "codes": ["KeyJ"], "label": "Dance", "disabled": True},
|
||||
{"action": "skill:wave", "codes": ["KeyH"], "label": "Wave", "disabled": True},
|
||||
])
|
||||
# Sensor name is read from the actual source model, not guessed from other robots.
|
||||
gyros = root.findall("./sensor/gyro")
|
||||
if len(gyros) != 1 or gyros[0].get("site") != "imu":
|
||||
raise ValueError("Expected root-frame IMU gyro")
|
||||
config["observations"]["obs"]["terms"][0]["sensor"] = gyros[0].get("name")
|
||||
dump(target / "robot.json", config)
|
||||
shutil.copyfile(source / "robolab" / "LICENSE", target / "LICENSES" / "RoboLab-BSD-3-Clause.txt")
|
||||
commit = subprocess.check_output(["git", "-C", str(asset_root), "rev-parse", "HEAD"], text=True).strip()
|
||||
files = ["model.xml", "policies/walk.onnx", "LICENSES/RoboLab-BSD-3-Clause.txt", *[a["path"] for a in assets]]
|
||||
dump(target / "source-manifest.json", {
|
||||
"source": "https://github.com/Roboparty/rp1_description", "commit": commit,
|
||||
"training_completed": args.completed, "checkpoint": str(checkpoint), "checkpoint_sha256": sha(checkpoint), "iteration": int(saved["iter"]),
|
||||
"training_params_sha256": {name: sha(params / name) for name in ["env.yaml", "agent.yaml"]},
|
||||
"source_model_sha256": sha(asset_root / "mjcf" / "robot_24dof.xml"),
|
||||
"export_max_abs_error": max_error,
|
||||
"files": [{"file": f, "sha256": sha(target / f)} for f in files],
|
||||
})
|
||||
print(f"Imported {target}: iteration {saved['iter']}, ONNX/PyTorch max error {max_error:.3g}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
validateWorld,
|
||||
} from "../src/platform/loader/SchemaValidator.js";
|
||||
import { resolveWorldId } from "../src/platform/worlds/arena.js";
|
||||
import { JointMotionReference } from "../src/platform/policy/JointMotionReference.js";
|
||||
const root = fileURLToPath(new URL("../public/robots/", import.meta.url));
|
||||
const entries = JSON.parse(await readFile(resolve(root, "index.json"), "utf8"));
|
||||
for (const entry of entries) {
|
||||
@@ -18,9 +19,25 @@ for (const entry of entries) {
|
||||
config.model,
|
||||
...config.assets.map((a) => a.path),
|
||||
...config.skills
|
||||
.filter((s) => s.controller.type === "onnx")
|
||||
.filter((s) => s.controller.type === "onnx" && s.available !== false)
|
||||
.map((s) => s.controller.policy),
|
||||
];
|
||||
for (const skill of config.skills.filter((s) => s.reference)) {
|
||||
const spec = JSON.parse(
|
||||
await readFile(resolve(dirname(file), skill.reference), "utf8"),
|
||||
);
|
||||
const buffer = await readFile(resolve(dirname(file), spec.data));
|
||||
new JointMotionReference(
|
||||
spec,
|
||||
buffer.buffer.slice(
|
||||
buffer.byteOffset,
|
||||
buffer.byteOffset + buffer.byteLength,
|
||||
),
|
||||
config.joints.groups[skill.owns],
|
||||
config.sim.timestep * config.sim.decimation,
|
||||
);
|
||||
paths.push(skill.reference, spec.data);
|
||||
}
|
||||
for (const path of paths) await access(resolve(dirname(file), path));
|
||||
validateWorld(
|
||||
JSON.parse(
|
||||
|
||||
Reference in New Issue
Block a user