How to use the sacred.config.ConfigDict function in sacred

To help you get started, we’ve selected a few sacred examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IDSIA / sacred / tests / test_config / test_config_dict.py View on Github external
def test_conf_scope_contains_presets():
    conf_dict = ConfigDict({"answer": 42})
    cfg = conf_dict(preset={"a": 21, "unrelated": True})
    assert set(cfg.keys()) == {"a", "answer", "unrelated"}
    assert cfg["a"] == 21
    assert cfg["answer"] == 42
    assert cfg["unrelated"] is True
github IDSIA / sacred / tests / test_config / test_config_dict.py View on Github external
def test_config_dict_raises_on_invalid_keys(key):
    with pytest.raises(KeyError):
        ConfigDict({key: True})
github IDSIA / sacred / tests / test_config / test_config_dict.py View on Github external
def test_fixed_subentry_of_preset():
    config_dict = ConfigDict({})

    cfg = config_dict(preset={"d": {"a": 1, "b": 2}}, fixed={"d": {"a": 10}})

    assert set(cfg.keys()) == {"d"}
    assert set(cfg["d"].keys()) == {"a", "b"}
    assert cfg["d"]["a"] == 10
    assert cfg["d"]["b"] == 2
github IDSIA / sacred / tests / test_config / test_config_dict.py View on Github external
def conf_dict():
    cfg = ConfigDict(
        {
            "a": 1,
            "b": 2.0,
            "c": True,
            "d": "string",
            "e": [1, 2, 3],
            "f": {"a": "b", "c": "d"},
        }
    )
    return cfg
github IDSIA / sacred / tests / test_config / test_config_dict.py View on Github external
def test_add_config_dict_sequential():
    # https://github.com/IDSIA/sacred/issues/409

    adict = ConfigDict(dict(dictnest2={"key_1": "value_1", "key_2": "value_2"}))

    bdict = ConfigDict(
        dict(
            dictnest2={"key_2": "update_value_2", "key_3": "value3", "key_4": "value4"}
        )
    )

    final_config = bdict(preset=adict())
    assert final_config == {
        "dictnest2": {
            "key_1": "value_1",
            "key_2": "update_value_2",
            "key_3": "value3",
            "key_4": "value4",
        }
github IDSIA / sacred / sacred / ingredient.py View on Github external
def _create_config_dict(cfg_or_file, kw_conf):
        if cfg_or_file is not None and kw_conf:
            raise ValueError(
                "cannot combine keyword config with " "positional argument"
            )
        if cfg_or_file is None:
            if not kw_conf:
                raise ValueError("attempted to add empty config")
            return ConfigDict(kw_conf)
        elif isinstance(cfg_or_file, dict):
            return ConfigDict(cfg_or_file)
        elif isinstance(cfg_or_file, str):
            if not os.path.exists(cfg_or_file):
                raise OSError("File not found {}".format(cfg_or_file))
            abspath = os.path.abspath(cfg_or_file)
            return ConfigDict(load_config_file(abspath))
        else:
            raise TypeError("Invalid argument type {}".format(type(cfg_or_file)))
github IDSIA / sacred / sacred / ingredient.py View on Github external
def _create_config_dict(cfg_or_file, kw_conf):
        if cfg_or_file is not None and kw_conf:
            raise ValueError(
                "cannot combine keyword config with " "positional argument"
            )
        if cfg_or_file is None:
            if not kw_conf:
                raise ValueError("attempted to add empty config")
            return ConfigDict(kw_conf)
        elif isinstance(cfg_or_file, dict):
            return ConfigDict(cfg_or_file)
        elif isinstance(cfg_or_file, str):
            if not os.path.exists(cfg_or_file):
                raise OSError("File not found {}".format(cfg_or_file))
            abspath = os.path.abspath(cfg_or_file)
            return ConfigDict(load_config_file(abspath))
        else:
            raise TypeError("Invalid argument type {}".format(type(cfg_or_file)))
github IDSIA / sacred / sacred / ingredient.py View on Github external
def _create_config_dict(cfg_or_file, kw_conf):
        if cfg_or_file is not None and kw_conf:
            raise ValueError(
                "cannot combine keyword config with " "positional argument"
            )
        if cfg_or_file is None:
            if not kw_conf:
                raise ValueError("attempted to add empty config")
            return ConfigDict(kw_conf)
        elif isinstance(cfg_or_file, dict):
            return ConfigDict(cfg_or_file)
        elif isinstance(cfg_or_file, str):
            if not os.path.exists(cfg_or_file):
                raise OSError("File not found {}".format(cfg_or_file))
            abspath = os.path.abspath(cfg_or_file)
            return ConfigDict(load_config_file(abspath))
        else:
            raise TypeError("Invalid argument type {}".format(type(cfg_or_file)))