Environments API
Base Environment
UrbanMARL Environment Base Wrappers.
Provides TorchRL-compatible multi-agent environment wrappers for 3D urban UAV/MEC simulations supporting batched execution across CPU and GPU devices.
- class urbanmarl.envs.base_env.UrbanEnvBase(*args, **kwargs)[source]
Bases:
_EnvWrapperBase TorchRL environment wrapper for UrbanMARL environments.
Manages multi-agent grouping, scenario initialization, batch environment map allocations, tensor specifications, and vectorized step/reset mechanics.
- scenario
Active UrbanScenario instance.
- Type:
UrbanScenario
- property lib
Returns the imported urbanmarl module package reference.
- property available_envs
Lists available environment identifiers registered in the library.
- __init__(device=None, batch_size=None, scenario='navigate', **kwargs)[source]
Initializes the UrbanEnvBase environment.
- Parameters:
device (
DEVICE_TYPING, optional) – Computation device (e.g. ‘cpu’, ‘cuda’).batch_size (
torch.Size | None, optional) – Tensor batch size of parallel envs.scenario (
str | UrbanScenario) – Scenario name string or UrbanScenario instance.**kwargs – Additional scenario and environment configuration parameters.
- Return type:
None
- read_obs(observations)[source]
Formats and unsqueezes observation data matching batch size.
- Parameters:
observations (
torch.Tensor | dict) – Raw observation input.- Returns:
Unsandwiched batch observation structure.
- Return type:
torch.Tensor | TensorDict
- to(device)[source]
Moves environment tensors to specified target device.
- Parameters:
device (
DEVICE_TYPING) – Target device.- Returns:
Self reference after device migration.
- Return type:
EnvBase
- render(mode='rgb_array', **kwargs)[source]
Renders the environment using the active scenario renderer.
- Parameters:
mode (
str) – Rendering mode (‘rgb_array’ or ‘human’). Defaults to ‘rgb_array’.**kwargs – Extra arguments passed to scenario.render().
- Returns:
Rendered frame (np.ndarray if ‘rgb_array’) or Matplotlib figure (if ‘human’).
- class urbanmarl.envs.base_env.UrbanEnv(*args, **kwargs)[source]
Bases:
UrbanEnvBaseHigh-level multi-agent Urban MARL environment class.
Convenience wrapper over UrbanEnvBase that accepts num_envs integer batch sizing.
- __init__(num_envs, continuous_actions, seed, device, scenario='default', **kwargs)[source]
Initializes an UrbanEnv instance.
- Parameters:
num_envs (
int) – Number of parallel environments in the batch.continuous_actions (
bool) – Whether actions are continuous vector spaces.seed (
Optional[int]) – Random seed.device (
torch.device) – PyTorch compute device.scenario (
str | UrbanScenario) – Scenario identifier or instance.**kwargs – Extra environment parameters.
- Return type:
None
3D Renderer
UrbanMARL 3D Environment Renderer.
Provides high-performance, vectorized 3D/2D visualization for urban multi-agent reinforcement learning environments including buildings, UAVs, ground UEs, base stations, and radio communication links.
- class urbanmarl.envs.rendering.UrbanRenderConfig(figsize=(1280, 820), dpi=100, heatmap_color='gist_yarg', heatmap_alpha=0.7, building_color='#C0C0C0', building_alpha=0.2, uav_color='#FF4444', uav_marker='^', ue_color='#4444FF', ue_marker='.', base_station_color='#FF4444', base_station_marker='v', trajectory_color='#FFA500', show_trajectory=True, trajectory_length=100, link_los_color='#00FF00', link_nlos_color='#FF0000', camera_elev=45.0, camera_azim=-120.0, show_labels=True, show_telemetry_hud=True, hud_fontsize=8, show_rem_contours=False)[source]
Bases:
objectConfiguration settings for urban environment rendering.
- Parameters:
dpi (int)
heatmap_color (str)
heatmap_alpha (float)
building_color (str)
building_alpha (float)
uav_color (str)
uav_marker (str)
ue_color (str)
ue_marker (str)
base_station_color (str)
base_station_marker (str)
trajectory_color (str)
show_trajectory (bool)
trajectory_length (int)
link_los_color (str)
link_nlos_color (str)
camera_elev (float)
camera_azim (float)
show_labels (bool)
show_telemetry_hud (bool)
hud_fontsize (int)
show_rem_contours (bool)
- figsize
Figure dimensions in pixels (width, height).
- Type:
Tuple[int, int]
- class urbanmarl.envs.rendering.Urban3DRenderer(config=None)[source]
Bases:
objectVectorized 3D & 2D renderer for UrbanMARL environments.
Renders: - 3D buildings as cuboid collections. - UAVs as 3D/2D flying markers with historical flight trajectories. - Ground User Equipments (UEs) on top-view and 3D maps. - Base Stations (BS) with vertical ground-projection indicators. - Vectorized communication links classified by LoS/NLoS state.
- Parameters:
config (UrbanRenderConfig | None)
- config
Renderer configuration parameters.
- Type:
- __init__(config=None)[source]
Initializes the Urban3DRenderer.
- Parameters:
config (
Optional[UrbanRenderConfig]) – Rendering configuration. If None, uses default settings.- Return type:
None
- render(state, mode='rgb_array')[source]
Renders the urban environment.
- Parameters:
state (
Dict) – Environment state payload containing: - ‘volume_size’: [x, y, z] environment bounds. - ‘buildings’: list of building dicts. - ‘uav_positions’: (N, 3) UAV locations. - ‘ue_positions’: (M, 3) UE locations. - ‘base_station_positions’: (K, 3) BS locations. - ‘links’: optional list of link dicts. - ‘heatmap’: optional 2D tensor/array for heatmap overlay. - ‘collisions’: optional array of collision points.mode (
str) – Rendering mode: ‘rgb_array’ returns (H, W, 3) uint8 image array, ‘human’ returns the Matplotlib figure handle. Defaults to ‘rgb_array’.
- Returns:
- RGB image numpy array if mode==’rgb_array’,
or matplotlib Figure handle if mode==’human’.
- Return type:
Optional[Union[np.ndarray, object]]
PettingZoo Wrapper
UrbanMARL PettingZoo ParallelEnv Standardization Wrapper.
Provides a standard PettingZoo ParallelEnv interface for UrbanMARL:
Fully compatible with CleanRL, Ray RLlib, Stable-Baselines3 (via shimmy/SuperSuit), and standard MARL evaluation pipelines.
Supports continuous 3D velocity actions and localized agent observation spaces.
- class urbanmarl.envs.pettingzoo_wrapper.UrbanPettingZooEnv(scenario='uav_navigation', render_mode='rgb_array', **env_kwargs)[source]
Bases:
objectPettingZoo ParallelEnv wrapper for UrbanMARL environments.
Wraps a single-environment UrbanEnv instance into standard PettingZoo format.
- metadata = {'name': 'urbanmarl_v1', 'render_modes': ['rgb_array', 'human']}
- __init__(scenario='uav_navigation', render_mode='rgb_array', **env_kwargs)[source]
Initializes PettingZoo wrapper.
- Parameters:
scenario (
str) – UrbanMARL scenario name. Defaults to ‘uav_navigation’.render_mode (
Optional[str]) – Rendering mode (‘rgb_array’ or ‘human’).**env_kwargs – Arguments passed directly to UrbanEnv.
- Return type:
None
- observation_space(agent)[source]
Returns the observation space for an agent.
- Parameters:
agent (str)
- Return type:
Space
- action_space(agent)[source]
Returns the action space for an agent.
- Parameters:
agent (str)
- Return type:
Space