Skip to content

Exception originated from within Sacred. KeyError: 'Invalid key "DogmaticDict.__setitem__". Config-keys cannot contain "." or start with "$"' #920

@hyfwyy

Description

@hyfwyy

Hey,

I have some issues with the originated from within Sacred when i debug my code.

ex = sacred.Experiment('Global (train)', ingredients=[data_ingredient, model_ingredient],interactive=True)
SETTINGS.CAPTURE_MODE = 'sys'
ex.captured_out_filter = apply_backspaces_and_linefeeds
@ex.automain
def main(epochs, cpu, cudnn_flag, temp_dir, seed, no_bias_decay):
       '...'

When i debug until the line of @ex.automain, the error was raised as follows.

Exception originated from within Sacred.
Traceback (most recent calls):
File "/root/anaconda3/lib/python3.10/site-packages/sacred/config/utils.py", line 42, in assert_is_valid_key
raise KeyError(
KeyError: 'Invalid key "DogmaticDict.setitem". Config-keys cannot contain "." or start with "$"'

I find the error happen in line 42, in assert_is_valid_key

def assert_is_valid_key(key):
        if SETTINGS.CONFIG.ENFORCE_KEYS_MONGO_COMPATIBLE and (
                isinstance(key, str) and ("." in key or key[0] == "$")
            ):
                raise KeyError(
                    'Invalid key "{}". Config-keys cannot '
                    'contain "." or start with "$"'.format(key)
                )

And the key is defined as:

def normalize_or_die(obj):
    if isinstance(obj, dict):
        res = dict()
        for key, value in obj.items():
            assert_is_valid_key(key)
            res[key] = normalize_or_die(value)
        return res
    elif isinstance(obj, (list, tuple)):
        return list([normalize_or_die(value) for value in obj])
    return normalize_numpy(obj)

But i cannot find the definition of obj. And I cannot find any solution online.

I would be grateful for some help!

Best,

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