colosseum.experiment.experiment_instance

 1import os
 2from dataclasses import dataclass
 3from typing import Type, List
 4
 5from colosseum import config
 6from colosseum.agent.agents.base import BaseAgent
 7from colosseum.emission_maps import EmissionMap
 8from colosseum.experiment import ExperimentConfig
 9from colosseum.mdp import BaseMDP
10from colosseum.utils import ensure_folder
11
12
13@dataclass(frozen=True)
14class ExperimentInstance:
15    seed: int
16    """The random seed for agent/MDP interaction."""
17    mdp_class: Type["BaseMDP"]
18    """The class of the MDP."""
19    mdp_scope: str
20    """The gin parameter for the MDP."""
21    agent_class: Type["BaseAgent"]
22    """The class of the agent."""
23    agent_scope: str
24    """The gin parameter for the agent."""
25    result_folder: str
26    """The folder where the results of the interactions will be stored."""
27    gin_config_files: List[str]
28    """The paths to the gin configuration files for the agent and MDPs"""
29    experiment_config: ExperimentConfig
30    """The experiment configuration of the agent/MDP interaction."""
31
32    @property
33    def emission_map(self) -> Type[EmissionMap]:
34        """
35        Returns
36        -------
37        Type[EmissionMap]
38            The emission map class of the experiment configuration.
39        """
40        return self.experiment_config.emission_map
41
42    @property
43    def experiment_name(self) -> str:
44        """
45        Returns
46        -------
47        str
48            The folder where the results are stored.
49        """
50        return self.result_folder[self.result_folder.rfind(os.sep) + 1 :]
51
52    @property
53    def experiment_label(self) -> str:
54        """
55        Returns
56        -------
57        str
58            The label for the experiment, which identifies the agent class, agent gin config, MDP class, and MDP gin
59            config.
60        """
61        return (
62            f"{self.mdp_scope}{config.EXPERIMENT_SEPARATOR_PRMS}{self.mdp_class.__name__}"
63            + f"{config.EXPERIMENT_SEPARATOR_MDP_AGENT}"
64            + f"{self.agent_scope}{config.EXPERIMENT_SEPARATOR_PRMS}{self.agent_class.__name__}"
65        )
66
67    @property
68    def does_log_file_exists(self) -> bool:
69        """
70        Returns
71        -------
72        bool
73            True if the csv log file where the results of the interaction were supposed to be stored exists.
74        """
75        lf = (
76            ensure_folder(self.result_folder)
77            + "logs"
78            + os.sep
79            + self.experiment_label
80            + f"{os.sep}seed{self.seed}_logs.csv"
81        )
82        return os.path.exists(lf)
83
84    def __str__(self):
85        return f"{self.experiment_name} for seed:{self.seed}, " + self.experiment_label
86
87    def __repr__(self):
88        return str(self)
@dataclass(frozen=True)
class ExperimentInstance:
14@dataclass(frozen=True)
15class ExperimentInstance:
16    seed: int
17    """The random seed for agent/MDP interaction."""
18    mdp_class: Type["BaseMDP"]
19    """The class of the MDP."""
20    mdp_scope: str
21    """The gin parameter for the MDP."""
22    agent_class: Type["BaseAgent"]
23    """The class of the agent."""
24    agent_scope: str
25    """The gin parameter for the agent."""
26    result_folder: str
27    """The folder where the results of the interactions will be stored."""
28    gin_config_files: List[str]
29    """The paths to the gin configuration files for the agent and MDPs"""
30    experiment_config: ExperimentConfig
31    """The experiment configuration of the agent/MDP interaction."""
32
33    @property
34    def emission_map(self) -> Type[EmissionMap]:
35        """
36        Returns
37        -------
38        Type[EmissionMap]
39            The emission map class of the experiment configuration.
40        """
41        return self.experiment_config.emission_map
42
43    @property
44    def experiment_name(self) -> str:
45        """
46        Returns
47        -------
48        str
49            The folder where the results are stored.
50        """
51        return self.result_folder[self.result_folder.rfind(os.sep) + 1 :]
52
53    @property
54    def experiment_label(self) -> str:
55        """
56        Returns
57        -------
58        str
59            The label for the experiment, which identifies the agent class, agent gin config, MDP class, and MDP gin
60            config.
61        """
62        return (
63            f"{self.mdp_scope}{config.EXPERIMENT_SEPARATOR_PRMS}{self.mdp_class.__name__}"
64            + f"{config.EXPERIMENT_SEPARATOR_MDP_AGENT}"
65            + f"{self.agent_scope}{config.EXPERIMENT_SEPARATOR_PRMS}{self.agent_class.__name__}"
66        )
67
68    @property
69    def does_log_file_exists(self) -> bool:
70        """
71        Returns
72        -------
73        bool
74            True if the csv log file where the results of the interaction were supposed to be stored exists.
75        """
76        lf = (
77            ensure_folder(self.result_folder)
78            + "logs"
79            + os.sep
80            + self.experiment_label
81            + f"{os.sep}seed{self.seed}_logs.csv"
82        )
83        return os.path.exists(lf)
84
85    def __str__(self):
86        return f"{self.experiment_name} for seed:{self.seed}, " + self.experiment_label
87
88    def __repr__(self):
89        return str(self)
ExperimentInstance( seed: int, mdp_class: Type[colosseum.mdp.base.BaseMDP], mdp_scope: str, agent_class: Type[colosseum.agent.agents.base.BaseAgent], agent_scope: str, result_folder: str, gin_config_files: List[str], experiment_config: colosseum.experiment.config.ExperimentConfig)
seed: int

The random seed for agent/MDP interaction.

mdp_class: Type[colosseum.mdp.base.BaseMDP]

The class of the MDP.

mdp_scope: str

The gin parameter for the MDP.

The class of the agent.

agent_scope: str

The gin parameter for the agent.

result_folder: str

The folder where the results of the interactions will be stored.

gin_config_files: List[str]

The paths to the gin configuration files for the agent and MDPs

The experiment configuration of the agent/MDP interaction.

Returns
  • Type[EmissionMap]: The emission map class of the experiment configuration.
experiment_name: str
Returns
  • str: The folder where the results are stored.
experiment_label: str
Returns
  • str: The label for the experiment, which identifies the agent class, agent gin config, MDP class, and MDP gin config.
does_log_file_exists: bool
Returns
  • bool: True if the csv log file where the results of the interaction were supposed to be stored exists.