safe_gymnasium | Overriding environment {new_spec.id} already in registry.

safe_gymnasium中__init__.py如下

# Copyright 2022-2023 OmniSafe Team. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Safety-Gymnasium Environments."""

import copy

from gymnasium import make as gymnasium_make
from gymnasium import register as gymnasium_register

from vlmsrl.sgym import vector, wrappers
from vlmsrl.sgym.tasks.safe_multi_agent.tasks.velocity.safe_mujoco_multi import make_ma
from vlmsrl.sgym.utils.registration import make, register
from vlmsrl.sgym.version import __version__

import warnings

warnings.filterwarnings("ignore", category=UserWarning, message=".*already in registry.*")


__all__ = [
    'register',
    'make',
    'gymnasium_make',
    'gymnasium_register',
]

VERSION = 'v0'
ROBOT_NAMES = ('Point', 'Car', 'Doggo', 'Racecar', 'Ant', 'Aloha')
MAKE_VISION_ENVIRONMENTS = True
MAKE_DEBUG_ENVIRONMENTS = True

# ========================================
# Helper Methods for Easy Registration
# ========================================

PREFIX = 'Safety'

robots = ROBOT_NAMES


def __register_helper(env_id, entry_point, spec_kwargs=None, **kwargs):
    """Register a environment to both Safety-Gymnasium and Gymnasium registry."""
    env_name, dash, version = env_id.partition('-')
    if spec_kwargs is None:
        spec_kwargs = {}

    register(
        id=env_id,
        entry_point=entry_point,
        kwargs=spec_kwargs,
        **kwargs,
    )
    gymnasium_register(
        id=f'{env_name}Gymnasium{dash}{version}',
        entry_point='sgym.wrappers.gymnasium_conversion:make_gymnasium_environment',
        kwargs={'env_id': f'{env_name}Gymnasium{dash}{version}', **copy.deepcopy(spec_kwargs)},
        **kwargs,
    )


def __combine(tasks, agents, max_episode_steps):
    """Combine tasks and agents together to register environment tasks."""
    for task_name, task_config in tasks.items():
        # Vector inputs
        for robot_name in agents:
            env_id = f'{PREFIX}{robot_name}{task_name}-{VERSION}'
            combined_config = copy.deepcopy(task_config)
            combined_config.update({'agent_name': robot_name})

            __register_helper(
                env_id=env_id,
                entry_point='sgym.builder:Builder',
                spec_kwargs={'config': combined_config, 'task_id': env
做mario游戏的时候为什么报错?NameNotFound Traceback (most recent call last) Cell In[2], line 19 9 # ------------------------------------------------- 10 # 2️⃣ 选择具体的环境 ID 11 # 语法:SuperMarioBros-<world>-<stage>-v<version> (...) 16 # v3 – 84×84 灰度 + 叠帧 + 只保留玩家位置(简化状态) 17 # ------------------------------------------------- 18 env_id = "SuperMarioBros-1-1-v0" # 第 1 世界第 1 关,使用原始像素 ---> 19 env = gym.make(env_id) # 通过 Gymnasium 创建环境 21 # ------------------------------------------------- 22 # 3️⃣ 包装动作空间(只保留常用 7 种动作) 23 # ------------------------------------------------- 24 env = JoypadSpace(env, SIMPLE_MOVEMENT) File D:\10_The_Programs\4_The_Codes\00_virtual_environment\V25_11_13_RL_gymnasium_pytorch\Lib\site-packages\gymnasium\envs\registration.py:681, in make(id, max_episode_steps, disable_env_checker, **kwargs) 678 assert isinstance(id, str) 680 # The environment name can include an unloaded module in "module:env_name" style --> 681 env_spec = _find_spec(id) 683 assert isinstance(env_spec, EnvSpec) 685 # Update the env spec kwargs with the `make` kwargs File D:\10_The_Programs\4_The_Codes\00_virtual_environment\V25_11_13_RL_gymnasium_pytorch\Lib\site-packages\gymnasium\envs\registration.py:526, in _find_spec(env_id) 520 logger.warn( 521 f"Using the latest versioned environment `{new_env_id}` " 522 f"instead of the unversioned environment `{env_name}`." 523 ) 525 if env_spec is None: --> 526 _check_version_exists(ns, name, version) 527 raise error.Error( 528 f"No registered env with id: {env_name}. Did you register it, or import the package that registers it? Use `gymnasium.pprint_registry()` to see all of the registered environments." 529 ) 531 return env_spec File D:\10_The_Programs\4_The_Codes\00_virtual_environment\V25_11_13_RL_gymnasium_pytorch\Lib\site-packages\gymnasium\envs\registration.py:392, in _check_version_exists(ns, name, version) 389 if get_env_id(ns, name, version) in registry: 390 return --> 392 _check_name_exists(ns, name) 393 if version is None: 394 return File D:\10_The_Programs\4_The_Codes\00_virtual_environment\V25_11_13_RL_gymnasium_pytorch\Lib\site-packages\gymnasium\envs\registration.py:369, in _check_name_exists(ns, name) 366 namespace_msg = f" in namespace {ns}" if ns else "" 367 suggestion_msg = f" Did you mean: `{suggestion[0]}`?" if suggestion else "" --> 369 raise error.NameNotFound( 370 f"Environment `{name}` doesn't exist{namespace_msg}.{suggestion_msg}" 371 ) NameNotFound: Environment `SuperMarioBros-1-1` doesn't exist.
11-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值