diff --git a/carl/envs/mario/carl_mario.py b/carl/envs/mario/carl_mario.py index bf4af52c..dd18ea2b 100644 --- a/carl/envs/mario/carl_mario.py +++ b/carl/envs/mario/carl_mario.py @@ -1,8 +1,9 @@ from __future__ import annotations -import sys from typing import List +import sys + import numpy as np from carl.context.context_space import ( @@ -46,9 +47,7 @@ def __init__( def _update_context(self) -> None: self.env: MarioEnv - self.context = CARLMarioEnv.get_context_space().insert_defaults( - self.context - ) + self.context = CARLMarioEnv.get_context_space().insert_defaults(self.context) if not self.levels: for context in self.contexts.values(): level, _ = generate_level( @@ -66,11 +65,15 @@ def _update_context(self) -> None: @staticmethod def get_context_features() -> dict[str, ContextFeature]: return { - "level_width": UniformIntegerContextFeature("level_width", 16, 1000, default_value=100), + "level_width": UniformIntegerContextFeature( + "level_width", 16, 1000, default_value=100 + ), "level_index": CategoricalContextFeature( "level_index", choices=np.arange(0, 14), default_value=0 ), - "noise_seed": UniformIntegerContextFeature("noise_seed", 0, sys.maxsize, default_value=0), + "noise_seed": UniformIntegerContextFeature( + "noise_seed", 0, sys.maxsize, default_value=0 + ), "mario_state": CategoricalContextFeature( "mario_state", choices=[0, 1, 2], default_value=0 ), diff --git a/carl/envs/mario/pcg_smb_env/mario_env.py b/carl/envs/mario/pcg_smb_env/mario_env.py index 369e815b..31f67e8c 100644 --- a/carl/envs/mario/pcg_smb_env/mario_env.py +++ b/carl/envs/mario/pcg_smb_env/mario_env.py @@ -1,9 +1,10 @@ +from typing import Any, Dict, List, Literal, Optional, cast + import atexit import os import random import socket from collections import deque -from typing import Any, Dict, List, Literal, Optional, cast import cv2 import gymnasium @@ -94,7 +95,10 @@ def __init__( self.display = Display(use_xauth=True) def reset( - self, seed: Optional[int] = None, options: Optional[Dict[str, Any]] = None, **kwargs + self, + seed: Optional[int] = None, + options: Optional[Dict[str, Any]] = None, + **kwargs, ): self._reset_obs() if self.game is None: diff --git a/carl/envs/mario/pcg_smb_env/toadgan/generate_sample.py b/carl/envs/mario/pcg_smb_env/toadgan/generate_sample.py index 47a0b603..5565dc27 100644 --- a/carl/envs/mario/pcg_smb_env/toadgan/generate_sample.py +++ b/carl/envs/mario/pcg_smb_env/toadgan/generate_sample.py @@ -9,9 +9,16 @@ # Generates a noise tensor. Uses torch.randn. def generate_spatial_noise( - size: Union[Any, List[int], Tuple[int]], device: Union[str, torch.device] = "cpu", seed: int = 0 + size: Union[Any, List[int], Tuple[int]], + device: Union[str, torch.device] = "cpu", + seed: int = 0, ) -> Tensor: - return torch.randn(size, device=device, dtype=torch.float32, generator=torch.Generator().manual_seed(seed)) + return torch.randn( + size, + device=device, + dtype=torch.float32, + generator=torch.Generator().manual_seed(seed), + ) # Generate a sample given a TOAD-GAN and additional parameters diff --git a/carl/envs/mario/pcg_smb_env/toadgan/toad_gan.py b/carl/envs/mario/pcg_smb_env/toadgan/toad_gan.py index b31f57f6..309eebf2 100644 --- a/carl/envs/mario/pcg_smb_env/toadgan/toad_gan.py +++ b/carl/envs/mario/pcg_smb_env/toadgan/toad_gan.py @@ -111,7 +111,9 @@ def generate_level( return "".join(level), initial_noise.numpy() -def generate_initial_noise(width: int, height: int, level_index: int, seed: int) -> Tensor: +def generate_initial_noise( + width: int, height: int, level_index: int, seed: int +) -> Tensor: toad_gan = load_generator(level_index) base_noise_map = toad_gan.noise_maps[0] nzx = ( diff --git a/carl/envs/mario/pcg_smb_env/utils.py b/carl/envs/mario/pcg_smb_env/utils.py index 4b49d0c0..4dcb6d81 100644 --- a/carl/envs/mario/pcg_smb_env/utils.py +++ b/carl/envs/mario/pcg_smb_env/utils.py @@ -38,7 +38,7 @@ def launch_gateway(): die_on_exit=True, port=free_port, java_path=str(JAVA), - javaopts=["-Djava.awt.headless=false"] + javaopts=["-Djava.awt.headless=false"], ), free_port, )