Skip to content

config

This module contains all the settings for the system.

config_settings = {'env_prefix': 'roc_', 'env_file': '.env'} module-attribute

Config

Bases: BaseSettings

A Pydantic settings model for configuration of the agent.

Source code in roc/config.py
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class Config(BaseSettings):
    """A Pydantic settings model for configuration of the agent."""

    global config_settings
    model_config = SettingsConfigDict(
        # XXX: can't do **config_settings 'cause of TypedDict?
        env_prefix=config_settings["env_prefix"],
        env_file=config_settings["env_file"],
        extra="forbid",
    )
    # database config
    db_host: str = Field(default="127.0.0.1")
    db_port: int = Field(default=7687)
    db_conn_encrypted: bool = Field(default=False)
    db_username: str = Field(default="")
    db_password: str = Field(default="")
    db_lazy: bool = Field(default=False)
    db_strict_schema: bool = Field(default=True)
    db_strict_schema_warns: bool = Field(default=False)
    # graph config
    node_cache_size: int = Field(default=2**30)
    edge_cache_size: int = Field(default=2**30)
    # log config
    log_enable: bool = Field(default=True)
    log_level: str = Field(default="INFO")
    log_modules: str = Field(default="")
    # agent config
    gym_actions: tuple[int, ...] | None = Field(default=None)  # configured by the gym
    observation_shape: tuple[int, ...] | None = Field(default=None)  # configured by the gym
    allow_unknown_intrinsic: bool = Field(default=True)
    # jupyter config
    status_update: int = Field(default=50)
    experiment_dir: str = Field(default="/home/apowers/experiment")
    data_dir: str = Field(default="/home/apowers/data")
    # gym config
    num_games: int = Field(default=5)
    enable_gym_dump_env: bool = Field(default=False)
    dump_file: str = Field(default=f"env_dump-{datetime.now().strftime('%Y.%m.%d-%H.%M.%S')}.py")
    max_dump_frames: int = Field(default=10)
    # nethack config
    nethack_extra_options: list[str] = ["autoopen"]
    nethack_max_turns: int = Field(default=100000)
    # experiment modules
    expmod_dirs: list[str] = ["experiments/modules"]
    expmods: list[str] = []
    expmods_use: list[str] = ["action:weighted"]
    # component config
    perception_components: list[str] = Field(
        default=[
            "delta:perception",
            "distance:perception",
            "flood:perception",
            "motion:perception",
            "single:perception",
            "line:perception",
            "color:perception",
            "shape:perception",
        ]
    )

    def __str__(self) -> str:
        ret = ""
        d = self.dict()
        for k in d:
            ret += f"{k} = {str(d[k])}\n"

        return ret

    @staticmethod
    def print() -> None:
        print(Config.get())  # noqa: T201

    @staticmethod
    def get() -> Config:
        """Returns the config singleton, which is strongly typed and can be used to
        get or set configuration settings.

        Returns:
            Config: The configuration for ROC.
        """
        global _config_singleton
        if _config_singleton is None:
            warnings.warn(
                "Getting settings before config module was initialized. Please call init() first",
                ConfigInitWarning,
            )
            Config.init()
            assert _config_singleton is not None
        return _config_singleton

    @staticmethod
    def init(
        config: dict[str, Any] | None = None,
        *,
        force: bool = False,
        use_secrets: bool = True,
    ) -> None:
        """Initializes the settings by reading the configuration files and environment variables"""
        global _config_singleton
        initialized = _config_singleton is not None
        if initialized and not force:
            warnings.warn(
                "Config already initialized, returning existing configuration.",
                ConfigInitWarning,
            )
            return

        passed_conf = config or {}
        _config_singleton = Config(**passed_conf)

    @staticmethod
    def reset() -> None:
        """Reset the configuration. Mostly used for testing."""
        global _config_singleton
        _config_singleton = None

allow_unknown_intrinsic = Field(default=True) class-attribute instance-attribute

data_dir = Field(default='/home/apowers/data') class-attribute instance-attribute

db_conn_encrypted = Field(default=False) class-attribute instance-attribute

db_host = Field(default='127.0.0.1') class-attribute instance-attribute

db_lazy = Field(default=False) class-attribute instance-attribute

db_password = Field(default='') class-attribute instance-attribute

db_port = Field(default=7687) class-attribute instance-attribute

db_strict_schema = Field(default=True) class-attribute instance-attribute

db_strict_schema_warns = Field(default=False) class-attribute instance-attribute

db_username = Field(default='') class-attribute instance-attribute

dump_file = Field(default=f'env_dump-{datetime.now().strftime('%Y.%m.%d-%H.%M.%S')}.py') class-attribute instance-attribute

edge_cache_size = Field(default=2 ** 30) class-attribute instance-attribute

enable_gym_dump_env = Field(default=False) class-attribute instance-attribute

experiment_dir = Field(default='/home/apowers/experiment') class-attribute instance-attribute

expmod_dirs = ['experiments/modules'] class-attribute instance-attribute

expmods = [] class-attribute instance-attribute

expmods_use = ['action:weighted'] class-attribute instance-attribute

gym_actions = Field(default=None) class-attribute instance-attribute

log_enable = Field(default=True) class-attribute instance-attribute

log_level = Field(default='INFO') class-attribute instance-attribute

log_modules = Field(default='') class-attribute instance-attribute

max_dump_frames = Field(default=10) class-attribute instance-attribute

model_config = SettingsConfigDict(env_prefix=config_settings['env_prefix'], env_file=config_settings['env_file'], extra='forbid') class-attribute instance-attribute

nethack_extra_options = ['autoopen'] class-attribute instance-attribute

nethack_max_turns = Field(default=100000) class-attribute instance-attribute

node_cache_size = Field(default=2 ** 30) class-attribute instance-attribute

num_games = Field(default=5) class-attribute instance-attribute

observation_shape = Field(default=None) class-attribute instance-attribute

perception_components = Field(default=['delta:perception', 'distance:perception', 'flood:perception', 'motion:perception', 'single:perception', 'line:perception', 'color:perception', 'shape:perception']) class-attribute instance-attribute

status_update = Field(default=50) class-attribute instance-attribute

__str__()

Source code in roc/config.py
 98
 99
100
101
102
103
104
def __str__(self) -> str:
    ret = ""
    d = self.dict()
    for k in d:
        ret += f"{k} = {str(d[k])}\n"

    return ret

get() staticmethod

Returns the config singleton, which is strongly typed and can be used to get or set configuration settings.

Returns:

Name Type Description
Config Config

The configuration for ROC.

Source code in roc/config.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@staticmethod
def get() -> Config:
    """Returns the config singleton, which is strongly typed and can be used to
    get or set configuration settings.

    Returns:
        Config: The configuration for ROC.
    """
    global _config_singleton
    if _config_singleton is None:
        warnings.warn(
            "Getting settings before config module was initialized. Please call init() first",
            ConfigInitWarning,
        )
        Config.init()
        assert _config_singleton is not None
    return _config_singleton

init(config=None, *, force=False, use_secrets=True) staticmethod

Initializes the settings by reading the configuration files and environment variables

Source code in roc/config.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
@staticmethod
def init(
    config: dict[str, Any] | None = None,
    *,
    force: bool = False,
    use_secrets: bool = True,
) -> None:
    """Initializes the settings by reading the configuration files and environment variables"""
    global _config_singleton
    initialized = _config_singleton is not None
    if initialized and not force:
        warnings.warn(
            "Config already initialized, returning existing configuration.",
            ConfigInitWarning,
        )
        return

    passed_conf = config or {}
    _config_singleton = Config(**passed_conf)

print() staticmethod

Source code in roc/config.py
106
107
108
@staticmethod
def print() -> None:
    print(Config.get())  # noqa: T201

reset() staticmethod

Reset the configuration. Mostly used for testing.

Source code in roc/config.py
148
149
150
151
152
@staticmethod
def reset() -> None:
    """Reset the configuration. Mostly used for testing."""
    global _config_singleton
    _config_singleton = None

ConfigInitWarning

Bases: Warning

A Warning for when attempting to access config before it has been initialized.

Source code in roc/config.py
14
15
class ConfigInitWarning(Warning):
    """A Warning for when attempting to access config before it has been initialized."""