Skip to content

zyfgi/carsim-guide-skill

carsim-guide

Verified

Operate and automate CarSim simulations from an agent, including safe output and parameter discovery, named Run Control execution contexts, structured overrides, isolated batch sweeps, dataset dependency inspection, control-mode selection, result validation, diagnostics, and version-aware CLI/Simulink/VS API routing. Use for executing, configuring, exploring, or debugging CarSim. Do not use for vehicle-dynamics theory alone, generic dataframe work, or unrelated simulators.

FileKindSize
SKILL.mdskill md6.3 KB
examples/batches/friction_sweep.yamlconfig159 B
examples/batches/mass_friction_grid.yamlconfig198 B
examples/discovery/dataset_tree.pyscript693 B
examples/discovery/find_output.pyscript715 B
examples/discovery/find_parameter.pyscript761 B
examples/scenarios/basic_cruise.yamlconfig380 B
examples/scenarios/friction_change.yamlconfig379 B
examples/scenarios/steering_maneuver.yamlconfig377 B
examples/scenarios/tire_force_output.yamlconfig437 B
examples/scenarios/vehicle_override.yamlconfig376 B
examples/simulink_cosim.pyscript5.5 KB
examples/torque_vectoring.pyscript5.6 KB
references/advanced-controls.mdmarkdown4.0 KB
references/batch-workflows.mdmarkdown1.6 KB
references/compatibility.mdmarkdown1.4 KB
references/control-modes.mdmarkdown1.0 KB
references/database-exploration.mdmarkdown7.4 KB
references/dataset-syntax.mdmarkdown6.6 KB
references/outputs-and-units.mdmarkdown2.1 KB
references/parameter-discovery.mdmarkdown1.4 KB
references/parameters.mdmarkdown3.3 KB
references/python-interface.mdmarkdown7.9 KB
references/run-validation.mdmarkdown2.2 KB
references/scenarios.mdmarkdown3.3 KB
references/simulink-cosim.mdmarkdown4.0 KB
references/troubleshooting.mdmarkdown1.4 KB
references/version-compatibility.mdmarkdown811 B
references/vs-c-api.mdmarkdown3.3 KB
scripts/base_registry.pyscript4.7 KB
scripts/batch_runner.pyscript7.1 KB
scripts/carsim_batch.pyscript23.4 KB
scripts/carsim_errors.pyscript2.2 KB
scripts/control_modes.pyscript1.8 KB
scripts/cosim_model.mother4.7 KB
scripts/database_tools.pyscript16.5 KB
scripts/diagnose_run.pyscript444 B
scripts/diagnostics.pyscript6.9 KB
scripts/discovery_query.pyscript1.0 KB
scripts/dump_dll_exports.pyscript1.9 KB
scripts/output_registry.pyscript8.9 KB
scripts/override_registry.pyscript2.9 KB
scripts/parameter_discovery.pyscript8.6 KB
scripts/parameters.pyscript10.0 KB
scripts/result_contract.pyscript548 B
scripts/scenario_runner.pyscript11.3 KB
scripts/scenario_schema.pyscript4.0 KB
scripts/setup_paths.pyscript11.2 KB
scripts/tv_cosim.mother8.5 KB
scripts/validate_run.pyscript6.1 KB
scripts/version_compatibility.pyscript2.0 KB

scripts/batch_runner.py

View on GitHub
"""Cartesian/zip scenario sweeps built strictly on scenario_runner."""
import argparse
import itertools
import json
from collections.abc import Iterable
from copy import deepcopy
from datetime import datetime, timezone
from pathlib import Path

import yaml
from base_registry import sha256
from scenario_runner import MANIFEST_NAME, run_scenario
from scenario_schema import load_scenario, validate_scenario

BATCH_MANIFEST_NAME = "batch_manifest.json"


def _utc_now() -> str:
    return datetime.now(timezone.utc).isoformat()


def expand_sweep(sweep: dict[str, dict], mode: str = "cartesian") -> list[dict[str, object]]:
    """Expand non-empty ``values`` entries using cartesian or zip semantics."""
    if mode not in {"cartesian", "zip"}:
        raise ValueError("combination must be 'cartesian' or 'zip'")
    if not sweep:
        raise ValueError("sweep must not be empty")
    names = list(sweep)
    values = []
    for name in names:
        spec = sweep[name]
        if set(spec) != {"values"} or not isinstance(spec["values"], list) or not spec["values"]:
            raise ValueError(f"Sweep {name} must contain one non-empty values list")
        values.append(spec["values"])
    if mode == "zip":
        lengths = {len(item) for item in values}
        if len(lengths) != 1:
            raise ValueError("zip sweeps require equal values lengths")
        rows: Iterable[tuple[object, ...]] = zip(*values)
    else:
        rows = itertools.product(*values)
    return [dict(zip(names, row)) for row in rows]


def apply_combination(base: dict, combination: dict[str, object]) -> dict:
    """Apply supported dotted sweep targets to a copied scenario."""
    scenario = deepcopy(base)
    for dotted, value in combination.items():
        parts = dotted.split(".")
        if len(parts) == 2 and parts[0] == "parameters":
            keyword = parts[1]
            parameters = scenario.setdefault("parameters", [])
            matches = [item for item in parameters
                       if item.get("type", "scalar") == "scalar" and
                       item.get("keyword") == keyword]
            if len(matches) > 1:
                raise ValueError(f"Scenario has duplicate scalar parameter {keyword}")
            if matches:
                matches[0]["value"] = value
            else:
                parameters.append({"keyword": keyword, "value": value})
            continue
        target = scenario
        for part in parts[:-1]:
            if part not in target or not isinstance(target[part], dict):
                raise ValueError(f"Unknown sweep target: {dotted}")
            target = target[part]
        if parts[-1] not in target:
            raise ValueError(f"Unknown sweep target: {dotted}")
        target[parts[-1]] = value
    return validate_scenario(scenario)


def load_batch(path: str | Path) -> tuple[dict, dict, Path]:
    """Load a batch YAML and its relative base scenario."""
    batch_path = Path(path).resolve()
    config = yaml.safe_load(batch_path.read_text(encoding="utf-8"))
    allowed = {"batch", "base_scenario", "sweep", "combination"}
    if not isinstance(config, dict) or set(config) - allowed:
        raise ValueError("Batch config has unknown fields")
    if not isinstance(config.get("batch"), dict) or set(config["batch"]) != {"id"}:
        raise ValueError("batch must contain exactly id")
    base_path = (batch_path.parent / config["base_scenario"]).resolve()
    return config, load_scenario(base_path), base_path


def run_batch(batch: str | Path, registry: str | Path,
              output_root: str | Path, prog: str | None = None,
              datadir: str | None = None, execute: bool = False,
              fail_fast: bool = False, timeout: float = 600) -> Path:
    """Compile/run isolated variants and always maintain a batch manifest."""
    batch_path = Path(batch).resolve()
    config, base, base_path = load_batch(batch_path)
    batch_id = config["batch"]["id"]
    if not isinstance(batch_id, str) or not batch_id or any(c not in
            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" for c in batch_id):
        raise ValueError("Invalid batch id")
    combinations = expand_sweep(config["sweep"], config.get("combination", "cartesian"))
    root = Path(output_root).resolve() / batch_id
    if root.exists():
        raise FileExistsError(f"Batch directory already exists: {root}")
    root.mkdir(parents=True)
    manifest_path = root / BATCH_MANIFEST_NAME
    manifest = {
        "manifest_version": 1,
        "batch": {"id": batch_id, "created_utc": _utc_now(),
                  "finished_utc": None, "combination": config.get("combination", "cartesian")},
        "base_scenario": str(base_path),
        "input_sha256": {"batch_config": sha256(batch_path),
                         "base_scenario": sha256(base_path)},
        "sweep": config["sweep"],
        "runs": [],
    }

    def save() -> None:
        manifest_path.write_text(json.dumps(manifest, indent=2, allow_nan=False) + "\n",
                                 encoding="utf-8")

    save()
    try:
        for index, combination in enumerate(combinations, 1):
            run_id = f"run_{index:04d}"
            scenario = apply_combination(base, combination)
            scenario["scenario"]["id"] = run_id
            record = {"run_id": run_id, "parameters": combination,
                      "status": "preparing", "success": False,
                      "manifest_path": str(root / run_id / MANIFEST_NAME)}
            manifest["runs"].append(record)
            save()
            try:
                run_scenario(scenario, registry, root, prog, datadir,
                             execute=execute, timeout=timeout)
                run_manifest = json.loads(Path(record["manifest_path"]).read_text(encoding="utf-8"))
                record["status"] = run_manifest["run"]["status"]
                record["success"] = record["status"] in {"compiled", "passed"}
            except Exception as exc:
                record["status"] = "failed"
                record["error"] = f"{type(exc).__name__}: {exc}"
                save()
                if fail_fast:
                    raise
            save()
    finally:
        manifest["batch"]["finished_utc"] = _utc_now()
        manifest["summary"] = {
            "total": len(manifest["runs"]),
            "successful": sum(bool(item["success"]) for item in manifest["runs"]),
            "failed": sum(item["status"] == "failed" for item in manifest["runs"]),
        }
        save()
    return root


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("batch")
    parser.add_argument("--registry", required=True)
    parser.add_argument("--out", required=True)
    parser.add_argument("--prog")
    parser.add_argument("--datadir")
    parser.add_argument("--run", action="store_true")
    parser.add_argument("--fail-fast", action="store_true")
    parser.add_argument("--timeout", type=float, default=600)
    args = parser.parse_args()
    print(run_batch(args.batch, args.registry, args.out, args.prog, args.datadir,
                    args.run, args.fail_fast, args.timeout))


if __name__ == "__main__":
    main()
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall