# 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