environment.py 23.7 KB
Newer Older
1
#!/usr/bin/env python3
2
import platform
3
import glob
4 5 6
import json
import os
import shutil
7 8
import subprocess
import time
9
from shutil import copytree, ignore_patterns, rmtree
10 11
from typing import *

12
import pandas as pd
13

14 15 16 17 18 19 20 21 22
from suqc.configuration import SuqcConfig
from suqc.opp.config_parser import OppConfigFileBase, OppConfigType, OppParser
from suqc.utils.general import (
    get_current_suqc_state,
    str_timestamp,
    user_query_yes_no,
    include_patterns,
    removeEmptyFolders,
)
23 24

# configuration of the suq-controller
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
DEFAULT_SUQ_CONFIG = {
    "default_vadere_src_path": "TODO",
    "server": {"host": "", "user": "", "port": -1},
}


class AbstractConsoleWrapper(object):
    @classmethod
    def infer_model(cls, model) -> "AbstractConsoleWrapper":

        if isinstance(model, str):
            if model == "Coupled":
                return CoupledConsoleWrapper(model)
            else:
                return VadereConsoleWrapper.infer_model(model)
        elif isinstance(model, VadereConsoleWrapper) or isinstance(
            model, CoupledConsoleWrapper
        ):
            return model
        else:
            raise ValueError(
                f"Model must be of type string or VadereConsoleWrapper or CoupledConsoleWrapper. Got type {type(model)}."
            )


class CoupledConsoleWrapper(AbstractConsoleWrapper):
    def __init__(self, model):
        self.simulator = model

    def run_simulation(
        self, dirname, start_file, required_files: Union[str, List[str]]
    ):
57

58 59 60 61
        terminal_command = ["python3", start_file, "--qoi"]
        terminal_command.extend(required_files)
        terminal_command.extend(["--run-name", os.path.basename(dirname)])
        terminal_command.extend(["--create-vadere-container"])
62

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        time_started = time.time()
        t = time.strftime("%H:%M:%S", time.localtime(time_started))
        print(f"{t}\t Call {os.path.basename(dirname)}/{start_file} ")

        return_code = subprocess.check_call(
            terminal_command,
            env=os.environ,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL,
            cwd=dirname,
            timeout=10800 # stop simulation after 3h
        )

        process_duration = time.time() - time_started
        output_subprocess = None

        return return_code, process_duration, output_subprocess
80 81


82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
class VadereConsoleWrapper(AbstractConsoleWrapper):

    # Current log level choices, requires to manually add, if there are changes in Vadere
    ALLOWED_LOGLVL = [
        "OFF",
        "FATAL",
        "TOPOGRAPHY_ERROR",
        "TOPOGRAPHY_WARN",
        "INFO",
        "DEBUG",
        "ALL",
    ]

    def __init__(
        self,
        model_path: str,
        loglvl="INFO",
        jvm_flags: Optional[List] = None,
        timeout_sec=None,
    ):
102 103 104

        self.jar_path = os.path.abspath(model_path)

105 106
        if not os.path.exists(self.jar_path):
            raise FileNotFoundError(
107 108
                f"Vadere console .jar file {self.jar_path} does not exist."
            )
109

110 111
        loglvl = loglvl.upper()
        if loglvl not in self.ALLOWED_LOGLVL:
112 113 114 115
            raise ValueError(
                f"set loglvl={loglvl} not contained "
                f"in allowed: {self.ALLOWED_LOGLVL}"
            )
116

117 118
        if jvm_flags is not None and not isinstance(jvm_flags, list):
            raise TypeError(
119 120
                f"jvm_flags are required to be a list. Got: {type(jvm_flags)}"
            )
121 122

        if timeout_sec is None:
123
            pass  # do nothing, no timeout
124
        elif not isinstance(timeout_sec, int) or timeout_sec <= 0:
125 126 127
            raise TypeError(
                "vadere_run_timeout_sec must be of type int and positive " "value"
            )
128 129 130 131 132

        self.loglvl = loglvl
        # Additional Java Virtual Machine options / flags
        self.jvm_flags = jvm_flags if jvm_flags is not None else []
        self.timeout_sec = timeout_sec
133

134 135 136 137 138 139 140 141 142 143 144 145
    @classmethod
    def infer_model(cls, model):
        if isinstance(model, str):
            if os.path.exists(model):
                return VadereConsoleWrapper.from_model_path(os.path.abspath(model))
            else:
                return VadereConsoleWrapper.from_default_models(model)
        elif isinstance(model, VadereConsoleWrapper):
            return model
        else:
            raise ValueError(f"Failed to infer Vadere model. \n {model}")

146 147
    def run_simulation(self, scenario_fp, output_path):
        start = time.time()
148 149 150 151 152 153 154 155 156 157 158

        subprocess_cmd = ["java"]
        subprocess_cmd += self.jvm_flags
        subprocess_cmd += ["-jar", self.jar_path]
        # Vadere console commands
        subprocess_cmd += ["--loglevel", self.loglvl]
        subprocess_cmd += ["suq", "-f", scenario_fp, "-o", output_path]

        output_subprocess = dict()

        try:
159 160 161
            subprocess.check_output(
                subprocess_cmd, timeout=self.timeout_sec, stderr=subprocess.PIPE
            )
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
            process_duration = time.time() - start

            # if return_code != 0 a subprocess.CalledProcessError is raised
            return_code = 0
            output_subprocess = None
        except subprocess.TimeoutExpired as exception:
            return_code = 1
            process_duration = self.timeout_sec
            output_subprocess["stdout"] = exception.stdout
            output_subprocess["stderr"] = None
        except subprocess.CalledProcessError as exception:
            return_code = exception.returncode
            process_duration = time.time() - start
            output_subprocess["stdout"] = exception.stdout
            output_subprocess["stderr"] = exception.stderr

        return return_code, process_duration, output_subprocess
179 180 181 182 183 184 185 186 187 188 189

    @classmethod
    def from_default_models(cls, model):
        if not model.endswith(".jar"):
            model = ".".join([model, "jar"])
        return cls(os.path.join(SuqcConfig.path_models_folder(), model))

    @classmethod
    def from_model_path(cls, model_path):
        return cls(model_path)

190

191
class AbstractEnvironmentManager(object):
192 193
    def __init__(self, base_path, env_name: str):

194 195 196
        self.base_path, self.env_name = self.handle_path_and_env_input(
            base_path, env_name
        )
197

198 199
        self.env_name = env_name
        self.env_path = self.output_folder_path(self.base_path, self.env_name)
200

201 202 203 204 205 206
        # output is usually of the following format:
        # 000001_000002 for variation 1 and run_id 2
        # Change these attributes externally, if less digits are required to have
        # shorter/longer paths.
        self.nr_digits_variation = 6
        self.nr_digits_runs = 6
207 208 209

        print(f"INFO: Set environment path to {self.env_path}")
        if not os.path.exists(self.env_path):
210 211 212 213 214
            raise FileNotFoundError(
                f"Environment {self.env_path} does not exist. Use function "
                f"'EnvironmentManager.create_new_environment'"
            )
        self._vadere_scenario_basis = None
215 216

    @property
217 218 219
    def vadere_basis_scenario(self):
        if self._vadere_scenario_basis is None:
            path_basis_scenario = self.vadere_path_basis_scenario
220 221 222

            with open(path_basis_scenario, "r") as f:
                basis_file = json.load(f)
223
            self._vadere_scenario_basis = basis_file
224

225
        return self._vadere_scenario_basis
226 227

    @property
228 229 230 231
    def vadere_path_basis_scenario(self):
        sc_files = glob.glob(
            os.path.join(self.env_path, f"*{self.VADERE_SCENARIO_FILE_TYPE}")
        )
232 233

        if len(sc_files) != 1:
234 235 236 237
            raise RuntimeError(
                f"None or too many '{self.VADERE_SCENARIO_FILE_TYPE}' files "
                "found in environment."
            )
238 239 240
        return sc_files[0]

    @classmethod
241 242
    def create_variation_env_from_info_file(cls, path_info_file):
        raise NotImplemented
243 244

    @classmethod
245 246 247
    def create_new_environment(
        cls, base_path=None, env_name=None, handle_existing="ask_user_replace"
    ):
248

249
        base_path, env_name = cls.handle_path_and_env_input(base_path, env_name)
250

251
        # TODO: Refactor, make handle_existing an Enum
252 253 254 255 256 257
        assert handle_existing in [
            "ask_user_replace",
            "force_replace",
            "write_in_if_exist_else_create",
            "write_in",
        ]
258

259 260 261
        # set to True if env already exists, and it shouldn't be overwritten
        about_creating_env = False
        env_man = None
262

263 264 265 266 267 268 269 270 271
        env_exists = os.path.exists(cls.output_folder_path(base_path, env_name))

        if handle_existing == "ask_user_replace" and env_exists:
            if not cls.remove_environment(base_path, env_name):
                about_creating_env = True
        elif handle_existing == "force_replace" and env_exists:
            if env_exists:
                cls.remove_environment(base_path, env_name, force=True)
        elif handle_existing == "write_in":
272 273 274
            assert (
                env_exists
            ), f"base_path={base_path} env_name={env_name} does not exist"
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
            env_man = cls(base_path=base_path, env_name=env_name)
        elif handle_existing == "write_in_if_exist_else_create":
            if env_exists:
                env_man = cls(base_path=base_path, env_name=env_name)

        if about_creating_env:
            raise ValueError("Could not create new environment.")

        if env_man is None:
            # Create new environment folder
            os.mkdir(cls.output_folder_path(base_path, env_name))
            env_man = cls(base_path=base_path, env_name=env_name)

        return env_man

290 291 292 293 294 295 296 297 298 299 300 301 302 303
    @classmethod
    def remove_environment(cls, base_path, name, force=False):
        target_path = cls.output_folder_path(base_path, name)

        if force or user_query_yes_no(
            question=f"Are you sure you want to remove the current environment? Path: \n "
            f"{target_path}"
        ):
            try:
                rmtree(target_path)
            except FileNotFoundError:
                print(f"INFO: Tried to remove environment {name}, but did not exist.")
            return True
        return False
304 305

    @classmethod
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
    def from_full_path(cls, env_path):
        assert os.path.isdir(env_path)
        base_path = os.path.dirname(env_path)

        if env_path.endswith(os.pathsep):
            env_path = env_path.rstrip(os.path.sep)
        env_name = os.path.basename(env_path)

        cls(base_path=base_path, env_name=env_name)

    @staticmethod
    def handle_path_and_env_input(base_path, env_name):
        if env_name is None:
            env_name = "_".join(["output", str_timestamp()])

        if base_path is None:
            base_path = SuqcConfig.path_container_folder()

        return base_path, env_name

    @staticmethod
    def output_folder_path(base_path, env_name):
        base_path, env_name = VadereEnvironmentManager.handle_path_and_env_input(
            base_path, env_name
        )
        assert os.path.isdir(base_path)
        output_folder_path = os.path.join(base_path, env_name)
        return output_folder_path

    def scenario_variation_path(self, par_id, run_id):
        return os.path.join(
            self.get_env_outputfolder_path(),
            self._scenario_variation_filename(par_id, run_id),
        )

    def save_scenario_variation(self, par_id, run_id, content):
        scenario_path = self.scenario_variation_path(par_id, run_id)
        assert not os.path.exists(
            scenario_path
        ), f"File {scenario_path} already exists!"

        with open(scenario_path, "w") as outfile:
            json.dump(content, outfile, indent=4)
        return scenario_path

    def get_temp_folder(self):
        raise NotImplemented

    def get_env_outputfolder_path(self):
        raise NotImplemented

    def get_variation_output_folder(self, parameter_id, run_id):
        scenario_filename = self._scenario_variation_filename(
            parameter_id=parameter_id, run_id=run_id
        )
        scenario_filename = scenario_filename.replace(
            self.VADERE_SCENARIO_FILE_TYPE, ""
        )
        return os.path.join(
            self.get_env_outputfolder_path(), "".join([scenario_filename, "_output"])
        )

    def _scenario_variation_filename(self, parameter_id, run_id):
        digits_parameter_id = str(parameter_id).zfill(self.nr_digits_variation)
        digits_run_id = str(run_id).zfill(self.nr_digits_variation)
        numbered_scenario_name = "_".join([digits_parameter_id, digits_run_id])

        return "".join([numbered_scenario_name, self.VADERE_SCENARIO_FILE_TYPE])

    def get_env_info(self):
        return self.env_info_df

    @classmethod
    def set_env_info(cls, basis_scenario, base_path, env_name, ini_scenario):

        info = {
            "basis_scenario": basis_scenario,
            "ini_path": ini_scenario,
            "base_path": base_path,
            "env_name": env_name,
        }

        info = pd.DataFrame(data=info, index=[0])
        cls.env_info_df = info


class VadereEnvironmentManager(AbstractEnvironmentManager):

    PREFIX_BASIS_SCENARIO = "BASIS_"
    VADERE_SCENARIO_FILE_TYPE = ".scenario"
    simulation_runs_output_folder = "vadere_output"

    def __init__(self, base_path, env_name: str):
        super().__init__(base_path, env_name)

    @classmethod
    def create_variation_env(
        cls,
        basis_scenario: Union[str, dict],
        base_path=None,
        env_name=None,
        handle_existing="ask_user_replace",
    ):

        cls.set_env_info(
            basis_scenario=basis_scenario,
            base_path=base_path,
            env_name=env_name,
            ini_scenario="",
        )
416

417
        # Check if environment already exists
418 419 420
        env_man = cls.create_new_environment(
            base_path=base_path, env_name=env_name, handle_existing=handle_existing
        )
421 422 423 424 425 426 427
        path_output_folder = env_man.env_path

        # Add basis scenario used for the variation (i.e. sampling)
        if isinstance(basis_scenario, str):  # assume that this is a path
            if not os.path.isfile(basis_scenario):
                raise FileExistsError("Filepath to .scenario does not exist")
            elif basis_scenario.split(".")[-1] != cls.VADERE_SCENARIO_FILE_TYPE[1:]:
428 429 430 431
                raise ValueError(
                    "basis_scenario has to be a Vadere '*"
                    f"{cls.VADERE_SCENARIO_FILE_TYPE}' file"
                )
432 433 434 435

            with open(basis_scenario, "r") as file:
                basis_scenario = file.read()

436
        # add prefix to scenario file:
437 438 439
        basis_fp = os.path.join(
            path_output_folder, f"{cls.PREFIX_BASIS_SCENARIO}{env_name}.scenario"
        )
440 441 442 443 444 445 446 447 448 449 450

        # FILL IN THE STANDARD FILES IN THE NEW SCENARIO:
        with open(basis_fp, "w") as file:
            if isinstance(basis_scenario, dict):
                json.dump(basis_scenario, file, indent=4)
            else:
                file.write(basis_scenario)

        # Create and store the configuration file to the new folder
        cfg = dict()

451 452
        # TODO it may be good to write the git hash / version number in the file
        if not SuqcConfig.is_package_paths():
453 454
            cfg["suqc_state"] = get_current_suqc_state()

455 456 457 458 459 460
            with open(
                os.path.join(path_output_folder, "suqc_commit_hash.json"), "w"
            ) as outfile:
                s = "\n".join(
                    ["commit hash at creation", cfg["suqc_state"]["git_hash"]]
                )
461 462
                outfile.write(s)

463
        # Create the folder where all output is stored
464 465 466 467 468 469
        os.mkdir(
            os.path.join(
                path_output_folder,
                VadereEnvironmentManager.simulation_runs_output_folder,
            )
        )
470

471
        return cls(base_path, env_name)
472

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    def get_env_outputfolder_path(self):
        rel_path = os.path.join(
            self.env_path, VadereEnvironmentManager.simulation_runs_output_folder
        )
        return os.path.abspath(rel_path)


class CoupledEnvironmentManager(AbstractEnvironmentManager):

    PREFIX_BASIS_SCENARIO = ""
    VADERE_SCENARIO_FILE_TYPE = ".scenario"
    simulation_runs_output_folder = "simulation_runs"
    simulation_runs_single_folder_name = "Sample_"
    run_file = "run_script.py"
    temp_folder_rover = "temp"

    def __init__(self, base_path, env_name: str):
        super().__init__(base_path, env_name)
        self._omnet_ini_basis = None

    @property
    def omnet_basis_ini(self):
        if self._omnet_ini_basis is None:
            path_basis_ini = self.omnet_path_ini
            ini_file = OppConfigFileBase.from_path(
                ini_path=path_basis_ini,
                config="final",
                cfg_type=OppConfigType.EXT_DEL_LOCAL,
            )
            self._omnet_ini_basis = ini_file
        return self._omnet_ini_basis

    @property
    def omnet_path_ini(self):
        sc_files = glob.glob(os.path.join(self.env_path, "*ini"))

        if len(sc_files) != 1:
            raise RuntimeError(f"None or too many 'ini' files " "found in environment.")
        return sc_files[0]

513
    @classmethod
514
    def create_variation_env_from_info_file(cls, path_info_file):
515

516
        d = pd.read_pickle(path_info_file)
517

518 519 520 521 522 523 524
        env = cls.create_variation_env(
            basis_scenario=d["basis_scenario"].values[0],
            ini_scenario=d["ini_path"].values[0],
            base_path=d["base_path"].values[0],
            env_name=d["env_name"].values[0],
            handle_existing="write_in",
        )
525

526
        return env
527

528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    @classmethod
    def create_variation_env(
        cls,
        basis_scenario: Union[str, dict],
        ini_scenario: Union[str, dict],
        base_path=None,
        env_name=None,
        handle_existing="ask_user_replace",
    ):

        cls.set_env_info(
            basis_scenario=basis_scenario,
            base_path=base_path,
            env_name=env_name,
            ini_scenario=ini_scenario,
        )

        cls.basis_scenario_name = os.path.basename(basis_scenario)
        # Check if environment already exists
        env_man = cls.create_new_environment(
            base_path=base_path, env_name=env_name, handle_existing=handle_existing
        )
        path_output_folder = env_man.env_path
551

552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
        ini_path = os.path.dirname(ini_scenario)

        new_path = os.path.join(path_output_folder, "additional_rover_files")

        if os.path.exists(new_path) is False:
            copytree(ini_path, new_path, ignore=include_patterns("*.py", "*.xml"))
            removeEmptyFolders(new_path)

        # Add vadere basis scenario used for the variation (i.e. sampling)
        if isinstance(basis_scenario, str):  # assume that this is a path
            if not os.path.isfile(basis_scenario):
                raise FileExistsError("Filepath to .scenario does not exist")
            elif basis_scenario.split(".")[-1] != cls.VADERE_SCENARIO_FILE_TYPE[1:]:
                raise ValueError(
                    "basis_scenario has to be a Vadere '*"
                    f"{cls.VADERE_SCENARIO_FILE_TYPE}' file"
                )

            with open(basis_scenario, "r") as file:
                basis_scenario = file.read()

        # add prefix to scenario file:
        basis_fp = os.path.join(
            path_output_folder,
            f"{cls.PREFIX_BASIS_SCENARIO}{env_man.get_scenario_name()}.scenario",
        )

        # FILL IN THE STANDARD FILES IN THE NEW SCENARIO:
        with open(basis_fp, "w") as file:
            if isinstance(basis_scenario, dict):
                json.dump(basis_scenario, file, indent=4)
            else:
                file.write(basis_scenario)  # this is where the scenario is defined

        # Add omnet basis scenario used for the variation (i.e. sampling)
        if isinstance(ini_scenario, str):  # assume that this is a path
            if not os.path.isfile(ini_scenario):
                raise FileExistsError("Filepath to .ini does not exist")
            elif ini_scenario.split(".")[-1] != "ini":
                raise ValueError("omnet ini has to be a ini file")

            with open(ini_scenario, "r") as file:
                ini_scenario = file.read()

        # add prefix to scenario file:
        basis_fp = os.path.join(path_output_folder, "omnetpp.ini")

        # FILL IN THE STANDARD FILES IN THE NEW SCENARIO:
        with open(basis_fp, "w") as file:
            if isinstance(ini_scenario, dict):
                OppConfigFileBase.writer()  # not working yet!
            else:
                file.write(ini_scenario)  # this is where the scenario is defined

        # Create and store the configuration file to the new folder
        cfg = dict()

        # TODO it may be good to write the git hash / version number in the file
        if not SuqcConfig.is_package_paths():
            cfg["suqc_state"] = get_current_suqc_state()

            with open(
                os.path.join(path_output_folder, "suqc_commit_hash.json"), "w"
            ) as outfile:
                s = "\n".join(
                    ["commit hash at creation", cfg["suqc_state"]["git_hash"]]
                )
                outfile.write(s)

        # Create the folder where all output is stored

        path_output_folder_rover = os.path.join(
            path_output_folder, CoupledEnvironmentManager.simulation_runs_output_folder,
        )

        if os.path.exists(path_output_folder_rover) is False:
            os.mkdir(path_output_folder_rover)

        temp_folder_rover = os.path.join(
            path_output_folder, CoupledEnvironmentManager.temp_folder_rover,
        )

        if os.path.exists(temp_folder_rover):
            shutil.rmtree(temp_folder_rover)

        if os.path.exists(temp_folder_rover) is False:
            os.mkdir(temp_folder_rover)

        return cls(base_path, env_name)

    def get_temp_folder(self):
        rel_path = os.path.join(
            self.env_path, CoupledEnvironmentManager.temp_folder_rover
        )
        return os.path.abspath(rel_path)
647 648

    def get_env_outputfolder_path(self):
649 650 651
        rel_path = os.path.join(
            self.env_path, CoupledEnvironmentManager.simulation_runs_output_folder
        )
652 653
        return os.path.abspath(rel_path)

654
    def get_variation_output_folder(self, parameter_id, run_id):
655 656 657 658 659 660 661 662 663 664 665 666
        scenario_filename = self._scenario_variation_filename(
            parameter_id=parameter_id, run_id=run_id
        )
        scenario_filename = scenario_filename.replace(
            self.VADERE_SCENARIO_FILE_TYPE, ""
        )

        variation_output_folder = os.path.join(
            self.get_env_outputfolder_path(), "".join([scenario_filename, "_output"])
        )

        return variation_output_folder
667 668 669 670 671

    def _scenario_variation_filename(self, parameter_id, run_id):
        digits_parameter_id = str(parameter_id).zfill(self.nr_digits_variation)
        digits_run_id = str(run_id).zfill(self.nr_digits_variation)
        numbered_scenario_name = "_".join([digits_parameter_id, digits_run_id])
672

673
        return "".join([numbered_scenario_name, self.VADERE_SCENARIO_FILE_TYPE])
674

675
    def scenario_variation_path(self, par_id, run_id, simulator=None):
676

677 678 679 680 681 682
        if simulator is None:
            subdirs = "vadere/scenarios"
            original_name_scenario = os.path.basename(self.vadere_path_basis_scenario)
        else:
            subdirs = ""
            original_name_scenario = "omnetpp.ini"
683

684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
        sim_name = self.get_simulation_directory(par_id, run_id)
        sim_path = os.path.join(self.get_env_outputfolder_path(), sim_name)
        sim_path = os.path.join(sim_path, subdirs)

        os.makedirs(sim_path, exist_ok=True)

        scenario_variation_path = os.path.join(sim_path, original_name_scenario)

        return scenario_variation_path

    def get_scenario_name(cls):
        scenario_name = cls.basis_scenario_name
        scenario_name = os.path.splitext(scenario_name)[0]
        return scenario_name

    def get_name_run_script_file(self):

        return CoupledEnvironmentManager.run_file

    def get_simulation_directory(self, par_id, run_id):
        prefix = CoupledEnvironmentManager.simulation_runs_single_folder_name
        return f"{prefix}_{par_id}_{run_id}"