LeRobot documentation
环境
环境
模拟环境通过 EnvConfig 进行配置,并由 make_env 构建,或者针对单个任务使用 make_task_env。配置仅包含选项;其 sim_settings() 将这些选项映射到其模拟器集成的关键字参数。
请参阅 Simulation 了解环境的使用方式,EnvHub 了解如何在 Hub 上使用和发布环境,以及 Adding a Benchmark 了解如何贡献基准测试。
HubEnvConfig
类 lerobot.envs.HubEnvConfig
< source >( task: str | None = Nonefps: int = 30features: dict[str, PolicyFeature] = <factory>features_map: dict[str, str] = <factory>max_parallel_tasks: int = 1disable_env_checker: bool = Trueserver: EnvClientConfig | None = Nonehub_path: str | None = Nonetrust_remote_code: bool = Falsemake_env_kwargs: dict[str, Any] = <factory>use_native_batch: bool = False )
来自 EnvHub 仓库的 env.py 中的 env;运行它需要 trust_remote_code。
EnvConfig
类 lerobot.envs.EnvConfig
< source >( task: str | None = Nonefps: int = 30features: dict[str, PolicyFeature] = <factory>features_map: dict[str, str] = <factory>max_parallel_tasks: int = 1disable_env_checker: bool = Trueserver: EnvClientConfig | None = None )
环境的选项。make_env 根据其 sim_settings() 构建环境。
已移除:使用 lerobot.envs.make_task_env(config, task_group, task_id, ...) 构建单个任务的 env。
已移除:使用 lerobot.envs.make_env(config, n_envs, use_async_envs) 构建环境。
返回此环境的 (preprocessor, postprocessor)。默认值:identity。
返回 sim_settings(),其中包含模拟的默认值,与本地环境和环境服务器运行时的设置一致。
返回模拟设置,类似于服务器 YAML 中的 sim 部分;缺失的设置将使用模拟默认值。
默认使用带有 gym_kwargs 和增量动作的 Gymnasium 环境 gym_id;否则请覆盖此设置。
make_env
lerobot.envs.make_env
< source >( cfg: EnvConfign_envs: int = 1use_async_envs: bool = False ) → dict[str, dict[int, gym.vector.VectorEnv]]
参数
- cfg (
EnvConfig) — 环境配置。EnvHub 仓库为HubEnvConfig(hub_path="user/repo", trust_remote_code=True)。 - n_envs (
int,可选,默认为1) — 每个向量环境中的环境数量。 - use_async_envs (
bool,可选,默认为False) — 在各自独立的工作进程中运行每个环境。
返回值
dict[str, dict[int, gym.vector.VectorEnv]]
向量环境,格式为 {suite: {task_id: env}}。单任务环境只有一个 suite,其任务 ID 为 0。
引发
ValueError 或 RuntimeError 或 ModuleNotFoundError
ValueError— 如果n_envs小于 1。RuntimeError— 如果 EnvHub 仓库的代码可以在不使用其配置中的trust_remote_code的情况下运行。ModuleNotFoundError— 如果模拟器未安装,或者仓库的env.py所需的某个包未安装。
构建配置的向量环境。
make_task_env
lerobot.envs.make_task_env
< source >( cfg: EnvConfigtask_group: str | None = Nonetask_id: int | None = Nonen_envs: int = 1use_async_envs: bool = False )
构建某个任务的本地或托管向量环境;未指定 task_id 时,默认为该套件中的第一个任务。