Ejemplo n.º 1
0
    def load_sweep_config(self, master_config, sweep_overrides):
        # Recreate the config for this sweep instance with the appropriate overrides
        overrides = master_config.hydra.overrides.hydra.to_container() + sweep_overrides
        sweep_config = self.load_configuration(overrides)

        # Copy old config cache to ensure we get the same resolved values (for things like timestamps etc)
        OmegaConf.copy_cache(from_config=master_config, to_config=sweep_config)

        return sweep_config
Ejemplo n.º 2
0
def test_copy_cache():
    OmegaConf.register_resolver("random",
                                lambda _: random.randint(0, 10000000))
    c1 = OmegaConf.create(dict(k='${random:_}', ))
    assert c1.k == c1.k

    c2 = OmegaConf.create(dict(k='${random:_}', ))
    assert c2.k != c1.k
    OmegaConf.set_cache(c2, OmegaConf.get_cache(c1))
    assert c2.k == c1.k

    c3 = OmegaConf.create(dict(k='${random:_}', ))

    assert c3.k != c1.k
    OmegaConf.copy_cache(c1, c3)
    assert c3.k == c1.k
Ejemplo n.º 3
0
def test_copy_cache(restore_resolvers: Any) -> None:
    OmegaConf.register_resolver("random", lambda _: random.randint(0, 10000000))
    d = {"k": "${random:_}"}
    c1 = OmegaConf.create(d)
    assert c1.k == c1.k

    c2 = OmegaConf.create(d)
    assert c2.k != c1.k
    OmegaConf.set_cache(c2, OmegaConf.get_cache(c1))
    assert c2.k == c1.k

    c3 = OmegaConf.create(d)

    assert c3.k != c1.k
    OmegaConf.copy_cache(c1, c3)
    assert c3.k == c1.k
Ejemplo n.º 4
0
    def load_sweep_config(self, master_config, sweep_overrides):
        # Recreate the config for this sweep instance with the appropriate overrides
        overrides = (
            OmegaConf.to_container(master_config.hydra.overrides.hydra) +
            sweep_overrides)
        sweep_config = self.load_configuration(
            config_file=master_config.hydra.job.config_file,
            strict=self.default_strict,
            overrides=overrides,
        )

        with open_dict(sweep_config):
            sweep_config.hydra.runtime.merge_with(master_config.hydra.runtime)

        # Copy old config cache to ensure we get the same resolved values (for things like timestamps etc)
        OmegaConf.copy_cache(from_config=master_config, to_config=sweep_config)

        return sweep_config