IDSIA / sacred

Sacred is a tool to help you configure, organize, log and reproduce experiments developed at IDSIA.
MIT License
4.26k stars 383 forks source link

Experiment config_hook does not change ingredient's config #936

Open cmditch opened 2 weeks ago

cmditch commented 2 weeks ago

It seems that any ingredient level changes within an experiment's config hook do not actually alter the ingredient's config. It seems they are being overwritten right about here.

Code to reproduce the issue:

import sacred

feats = sacred.Ingredient("feats")
feats.add_config({"name": "feats"})

ex = sacred.Experiment("coury_sacred_test", ingredients=[feats])
ex.add_config({"name": "experiment"})

@ex.config_hook
def ex_config_hook(config, command_name, logger):
    config["feats"]["name"] = "feats_changed"
    print("Config hook changes:", config)
    return config

@ex.automain
def main(_run):
    print(_run.config)

Output:

> python scratch_sacred_config_hook_debug.py print_config

Config hook changes: {'name': 'experiment', 'feats': {'name': 'feats_changed'}}
INFO - coury_sacred_test - Running command 'print_config'
INFO - coury_sacred_test - Started
Configuration (modified, added, typechanged, doc):
  name = 'experiment'
  seed = 149828750
  feats:
    name = 'feats'
INFO - coury_sacred_test - Completed after 0:00:00
thequilo commented 6 days ago

Hi @cmditch! Thanks for reporting this. Do you have an idea how to fix this issue and would prepare a PR? Unfortunately, I currently don't have much time to work on this.