simulation-environments
Create and operate SMARTS HiWayEnvV1 and parallel Gymnasium environments, configure agent interfaces and policies, and diagnose action, observation, lifecycle, and deterministic-seeding issues.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- simulation-environments
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Create and operate SMARTS HiWayEnvV1 and parallel Gymnasium environments, configure agent interfaces and policies, and diagnose action, observation, lifecycle, and deterministic-seeding issues.
- disable-model-invocation
- true
02 资源文件 7
- 参考文档references/action-observation-reward.md8.3 KB
- 参考文档references/api-reference.md6.7 KB
- 参考文档references/configuration.md6.4 KB
- 参考文档references/troubleshooting.md8.1 KB
- 参考文档references/workflows.md7.3 KB
- 脚本scripts/inspect_interfaces.py4.3 KB
- 脚本scripts/smoke_env.py9.8 KB
03 SKILL.md 正文
SMARTS simulation environments
Use this route for the core CPU simulation loop: a pre-built SMARTS scenario,
AgentInterface/AgentType, an Agent policy, Gymnasium return values,
controller actions, deterministic scenario iteration, and bounded parallel
execution. The bundled scripts intentionally do not build scenarios, install
packages, launch visualization, or start external traffic services.
Operating contract
- Run the commands from any directory in the Python environment that has
SMARTS installed. Verify the install first with
inspect_interfaces.py. - Supply an already generated scenario directory to
smoke_env.py;--scenariois mandatory for a smoke run, the default configured agent id isego, and the helper uses a Laner interface with a run bounded to eight steps.--self-testexercises parser and active-agent lifecycle logic without importing SMARTS or needing a scenario. - A scenario must contain the generated map/traffic artifacts expected by the
installed SMARTS version. Ask the
scenario-studioroute to define or build one; do not invent a source-checkout-relative path here. - Use
headless=Truefor core checks. Camera/image setup belongs to thesensors-visualizationroute. Ray/RLlib, registry packaging, and long training belong torl-agent-zoo; publicsclcommands belong tocli-integrations.
Fast start
from smarts.core.agent_interface import AgentInterface, AgentType
from smarts.env.gymnasium.hiway_env_v1 import HiWayEnvV1
AGENT = "ego"
interface = AgentInterface.from_type(
AgentType.LanerWithSpeed, max_episode_steps=200
)
env = HiWayEnvV1(
scenarios=["built-scenario"],
agent_interfaces={AGENT: interface},
headless=True,
seed=42,
)
try:
observations, infos = env.reset(seed=42)
while observations:
actions = {
agent_id: env.action_space[agent_id].sample()
for agent_id in observations
}
observations, rewards, terminateds, truncateds, infos = env.step(actions)
if terminateds.get("__all__", False) or truncateds.get("__all__", False):
break
finally:
env.close()
The default HiWayEnvV1 formatting is multi-agent: only currently active
agent ids appear in the observation, reward, and policy-action dictionaries.
An empty observation dictionary is a valid intermediate window; keep stepping
with {} until __all__ is true or the caller's own bound is reached. Never
send actions for an id that is not active in the current observation window.
Choose an interface deliberately
- Start with
AgentInterface.from_type(AgentType.Laner)for a four-valued lane policy,LanerWithSpeedfor(target_speed, lane_delta),Standardfor waypoint/neighborhood observations with actuator-dynamic control, orStandardWithAbsoluteSteeringfor continuous throttle/brake/steering. - Construct
AgentInterface(...)when exact sensor parameters or done criteria matter.Truesensor flags resolve to their default dataclass; useWaypoints,NeighborhoodVehicles,RGB,OGM, and related dataclasses for non-default dimensions or ranges. AgentInterface.actionchooses both the expected action shape and the controller/chassis path. Match the policy output toenv.action_space[id], not to a guessed Python type. Seeaction-observation-reward.md.- A policy can subclass
Agentand implementact(self, obs, **configs), or useAgent.from_function(callable). Keep model loading outsideactwhen possible and make policy output deterministic when reproducibility matters.
Lifecycle and checks
- Import
smarts.env.gymnasium(orsmarts.env) before using the registered Gymnasium idhiway-v1; directHiWayEnvV1(...)avoids registration. - Inspect
env.observation_spaceandenv.action_spaceimmediately after construction. In formatted modes they are GymnasiumDictspaces keyed by configured agent id.space.contains(candidate)is the quickest mismatch test. - Call
reset(seed=integer)once at the start of a reproducible run. A subsequentreset(seed=None)does not re-seed an existing RNG. SMARTS scenario iteration advances on each reset; useScenarioOrder.sequentialwhen order, rather than shuffled order, is part of the experiment. - Call
step(actions)only before episode completion, then callreset()for the next episode. Always callclose(), including when a policy raises.with HiWayEnvV1(...) as env:is supported.
Return-shape essentials
reset() returns exactly (observations, infos). In default per-agent mode,
step() returns exactly
(observations, rewards, terminateds, truncateds, infos), where all five
values are dictionaries and terminateds["__all__"] marks completion of all
configured agents. SMARTS currently mirrors the done dictionary into both
terminateds and truncateds; treat the two positions separately in caller
code for Gymnasium compatibility. environment_return_mode="environment"
changes the middle status to (float_reward, bool_terminated, bool_truncated, info) while observations remain a dictionary. See the full contract in the
bundled references before adapting a third-party vectorizer.
Parallel route in this skill
ParallelEnv takes picklable env_constructors, requires all child
observation and action spaces to compare equal, and returns batches as
sequences: reset() yields (observations_batch, infos_batch) and step()
yields five batched sequences. It uses worker processes, seeds worker i as
seed + i, and can auto-reset completed workers. Close it explicitly; use
small num_env values that do not exceed available CPUs.
References and safe helpers
api-reference.md— verified signatures, enums, classes, and import surface.workflows.md— single/multi-agent, deterministic, and parallel recipes.action-observation-reward.md— action mappings, formatted spaces, observation fields, rewards, and done semantics.configuration.md— environment/interface, scenario-order, vehicle, controller, and optional-image settings.troubleshooting.md— installation, optional dependencies, data/configuration, API misuse, and workflow failures.scripts/inspect_interfaces.py— import and signature/enum/space inspection without a scenario.scripts/smoke_env.py— explicit-scenario, headless, bounded reset/step/close smoke check.
The installed-package verification target for this route is SMARTS 2.0.1 on Python 3.11 with CPU core dependencies. Rendering, RLlib/Ray, SUMO, ROS, Waymo, Argoverse, and Visdom are optional integrations and are not implied by the core smoke check.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).