Skip to content

Experiment config_hook does not change ingredient's config #936

@cmditch

Description

@cmditch

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions