Skip to content

nested_imports

Utilies for importing multiple executors, samplers and runners.

RunGroup dataclass

RunGroup(executor, sampler, runner)

Container for a group of executors, samplers, and runners

import_executors

import_executors(args)

Imports all executors from config, under 'executors' key

Args Dictionary or namespace object, parsed from yaml Returns Dictionary mapping executor unique name to class instance

Source code in src/enchanted_surrogates/supervisor/nested_imports.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def import_executors(args) -> dict[str, Executor]:
    """
    Imports all executors from config, under 'executors' key

    Args
        Dictionary or namespace object, parsed from yaml
    Returns
        Dictionary mapping executor unique name to class instance
    """
    executors = {}
    for name, executor_config in args.executors.items():
        executors[name] = import_executor(executor_config["type"], executor_config)

    return executors

import_run_groups

import_run_groups(args)

Imports supervisor/run_order from config.

Returns List of dicts with keys 'executor', 'sampler' and 'runner' mapping to their unique names.

Source code in src/enchanted_surrogates/supervisor/nested_imports.py
49
50
51
52
53
54
55
56
57
def import_run_groups(args) -> list[dict]:
    """
    Imports supervisor/run_order from config. 

    Returns
        List of dicts with keys 'executor', 'sampler' and 'runner' mapping
        to their unique names.
    """
    return args.supervisor["run_order"]

import_samplers

import_samplers(args)

Imports all samplers from config, under 'samplers' key

Args Dictionary or namespace object, parsed from yaml Returns Dictionary mapping sampler unique name to class instance

Source code in src/enchanted_surrogates/supervisor/nested_imports.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def import_samplers(args) -> dict[str, Sampler]:
    """
    Imports all samplers from config, under 'samplers' key

    Args
        Dictionary or namespace object, parsed from yaml
    Returns
        Dictionary mapping sampler unique name to class instance
    """
    samplers = {}
    for name, sampler_config in args.samplers.items():
        samplers[name] = import_sampler(sampler_config["type"], sampler_config)

    return samplers

import_saved_files_list

import_saved_files_list(args)

Imports supervisor/save_files_list from config.

Returns List of strings containing names of files to be saved

Source code in src/enchanted_surrogates/supervisor/nested_imports.py
59
60
61
62
63
64
65
66
def import_saved_files_list(args) -> list[str]:
    """
    Imports supervisor/save_files_list from config.

    Returns
        List of strings containing names of files to be saved
    """
    return args.supervisor.get("save_files_list",[])