diff --git a/scripts/configs/env/base.yaml b/scripts/configs/env/base.yaml deleted file mode 100644 index 3939b5a0..00000000 --- a/scripts/configs/env/base.yaml +++ /dev/null @@ -1 +0,0 @@ -device: cpu # cpu, cuda, cuda:0, cuda:1, ... diff --git a/scripts/configs/env/discrete-ebm.yaml b/scripts/configs/env/discrete-ebm.yaml deleted file mode 100644 index c8cd247c..00000000 --- a/scripts/configs/env/discrete-ebm.yaml +++ /dev/null @@ -1,2 +0,0 @@ -ndim: 4 -alpha: 1.0 diff --git a/scripts/configs/env/hypergrid.yaml b/scripts/configs/env/hypergrid.yaml deleted file mode 100644 index 5da08551..00000000 --- a/scripts/configs/env/hypergrid.yaml +++ /dev/null @@ -1,7 +0,0 @@ -ndim: 2 -height: 8 -R0: 0.1 -R1: 0.5 -R2: 2.0 -reward_cos: False -preprocessor_name: KHot # choice("KHot", "OneHot", "Identity", default="KHot") diff --git a/scripts/configs/loss/base.yaml b/scripts/configs/loss/base.yaml deleted file mode 100644 index e07155fd..00000000 --- a/scripts/configs/loss/base.yaml +++ /dev/null @@ -1,4 +0,0 @@ -module_name: NeuralNet # choice("NeuralNet", "Tabular", "Uniform", "Zero", default="NeuralNet") -n_hidden_layers: 2 -hidden_dim: 256 -activation_fn: relu diff --git a/scripts/configs/loss/detailed-balance.yaml b/scripts/configs/loss/detailed-balance.yaml deleted file mode 100644 index d223505f..00000000 --- a/scripts/configs/loss/detailed-balance.yaml +++ /dev/null @@ -1 +0,0 @@ -forward_looking: False diff --git a/scripts/configs/loss/flowmatching.yaml b/scripts/configs/loss/flowmatching.yaml deleted file mode 100644 index f11efb87..00000000 --- a/scripts/configs/loss/flowmatching.yaml +++ /dev/null @@ -1 +0,0 @@ -alpha: 1.0 diff --git a/scripts/configs/loss/sub-tb.yaml b/scripts/configs/loss/sub-tb.yaml deleted file mode 100644 index 26485208..00000000 --- a/scripts/configs/loss/sub-tb.yaml +++ /dev/null @@ -1,7 +0,0 @@ -weighing: - geometric_within # choice( - # "equal", "equal_within", "geometric", "TB", "DB", "ModifiedDB", "geometric_within", - # default="geometric_within" - # ) -forward_looking: False -lamda: 0.9 diff --git a/scripts/configs/loss/trajectory-balance.yaml b/scripts/configs/loss/trajectory-balance.yaml deleted file mode 100644 index b187a4b4..00000000 --- a/scripts/configs/loss/trajectory-balance.yaml +++ /dev/null @@ -1,2 +0,0 @@ -logZ_init: 0.0 -log_reward_clip_min: -12 diff --git a/scripts/configs/optim/adam.yaml b/scripts/configs/optim/adam.yaml deleted file mode 100644 index 3e407be8..00000000 --- a/scripts/configs/optim/adam.yaml +++ /dev/null @@ -1 +0,0 @@ -betas: [0.9, 0.999] diff --git a/scripts/configs/optim/base.yaml b/scripts/configs/optim/base.yaml deleted file mode 100644 index 84f7f5de..00000000 --- a/scripts/configs/optim/base.yaml +++ /dev/null @@ -1,2 +0,0 @@ -lr: 0.001 -lr_Z: 0.1 diff --git a/scripts/configs/optim/sgd.yaml b/scripts/configs/optim/sgd.yaml deleted file mode 100644 index 126d5eec..00000000 --- a/scripts/configs/optim/sgd.yaml +++ /dev/null @@ -1 +0,0 @@ -momentum: 0.0 diff --git a/scripts/configs/parser.py b/scripts/configs/parser.py deleted file mode 100644 index b87a68ab..00000000 --- a/scripts/configs/parser.py +++ /dev/null @@ -1,177 +0,0 @@ -import ast -import collections -from argparse import ArgumentParser -from copy import deepcopy -from os.path import expandvars -from pathlib import Path -from typing import Any, Tuple, Union - -from yaml import safe_load - - -def resolve(path: Union[str, Path]) -> Path: - """ - Resolve a path to an absolute ``pathlib.Path``, expanding environment variables and - user home directory. - - Args: - path: The path to resolve. - - Returns: - The resolved path. - """ - return Path(expandvars(path)).expanduser().resolve() - - -def update(orig_dict: dict, new_dict: dict) -> dict: - """ - Update a nested dictionary or similar mapping. - Not in-place. - - .. code-block:: python - - >>> orig_dict = {'a': {'b': 1, 'c': 2}} - >>> new_dict = {'a': {'b': 3, 'd': 4}} - >>> update(orig_dict, new_dict) - {'a': {'b': 3, 'c': 2, 'd': 4}} - - Args: - orig_dict (dict): Dict to update - new_dict (dict): Dict to update with - - Returns: - dict: Deeply merged dict - """ - orig_dict = deepcopy(orig_dict) - for key, val in new_dict.items(): - if isinstance(val, collections.abc.Mapping): - tmp = update(orig_dict.get(key, {}), val) - orig_dict[key] = tmp - elif isinstance(val, list): - orig_dict[key] = orig_dict.get(key, []) + val - else: - orig_dict[key] = new_dict[key] - return orig_dict - - -def parse_value(value: Any) -> Any: - """ - Parse string as Python literal if possible and fallback to string. - """ - try: - if value.lower() == "true": - return True - elif value.lower() == "false": - return False - return ast.literal_eval(value) - except (ValueError, SyntaxError): - # Use as string if nothing else worked - return value - - -def dict_set_recursively(dictionary, key_sequence, val): - top_key = key_sequence.pop(0) - if len(key_sequence) == 0: - dictionary[top_key] = val - else: - if top_key not in dictionary: - dictionary[top_key] = {} - dict_set_recursively(dictionary[top_key], key_sequence, val) - - -def create_dict_from_args(args: list, sep: str = "."): - """ - Create a (nested) dictionary from console arguments. - Keys in different dictionary levels are separated by sep. - """ - return_dict = {} - ignore_next = False - for a, arg in enumerate(args): - if ignore_next: - ignore_next = False - continue - arg = arg.strip("-").replace("-", "_") - if "=" in arg: - parts = arg.split("=") - else: - if a == len(args) - 1 or args[a + 1].startswith("--"): - parts = [arg, True] - else: - parts = [arg, args[a + 1]] - ignore_next = True - if len(parts) == 2: - keys_concat, val = parts - elif len(parts) > 2: - keys_concat, val = parts[0], "=".join(parts[1:]) - else: - raise ValueError(f"Invalid argument {arg}") - val = parse_value(val) - key_sequence = keys_concat.split(sep) - dict_set_recursively(return_dict, key_sequence, val) - return return_dict - - -def parse_args_to_dict(parser: ArgumentParser) -> Tuple[dict, dict]: - """ - Parse default arguments in a dictionary, - and arbitrary extra command line arguments to another dictionary. - - Returns: - Tuple[dict, dict]: command-line args as dictionaries - """ - # Parse args - args, override_args = parser.parse_known_args() - - return vars(args), create_dict_from_args(override_args) - - -def load_named_config(namespace: str, value: str) -> dict: - """ - Load a named config from a namespace. - Starts with ./{namespace}/base.yaml and overrides with ./{namespace}/{value}.yaml. - - Args: - namespace (str): Folder to look for configs in - value (str): Name of the config to load in the namespace - - Raises: - ValueError: If the config name does not exist in the folder. - - Returns: - dict: Config for that namespace - """ - base = resolve(Path(__file__)).parent - config = safe_load((base / f"{namespace}/base.yaml").read_text()) - - if value is None: - return config - - value = value.replace(".yaml", "") - value = base / f"{namespace}/{value}.yaml" - - if not value.exists(): - raise ValueError(f"Config {value.name} does not exist in {str(base)}.") - - return update(config, safe_load(value.read_text())) - - -def load_config(parser: ArgumentParser) -> dict: - """ - Parse command line arguments and load config files. - - {namespace}/base.yaml is always loaded first and will be overridden by other config - files specified from the command-line. - - Raises: - ValueError: If the config file/name does not exist. - - Returns: - dict: GFlowNet run config - """ - config, cli = parse_args_to_dict(parser) - namespaces = {b.parent.name for b in Path(__file__).parent.glob("*/base.yaml")} - for namespace in namespaces: - value = config.get(namespace.replace(".yaml", "")) - config[namespace] = load_named_config(namespace, value) - config[namespace]["name"] = value - return update(config, cli) diff --git a/scripts/configs/sampler/base.yaml b/scripts/configs/sampler/base.yaml deleted file mode 100644 index 8f64e720..00000000 --- a/scripts/configs/sampler/base.yaml +++ /dev/null @@ -1,3 +0,0 @@ -temperature: 1.0 -sf_bias: 0.0 -epsilon: 0.0