Skip to content

Commit

Permalink
Updated config util
Browse files Browse the repository at this point in the history
Signed-off-by: Max <mcschrader@crimson.ua.edu>
  • Loading branch information
mschrader15 committed Jul 22, 2024
1 parent 1b2e5df commit b1933b9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions sumo_pipelines/utils/config_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
from pathlib import Path
from typing import TYPE_CHECKING, List, Union
import re

from omegaconf import DictConfig, ListConfig, OmegaConf
from simpleeval import simple_eval
Expand Down Expand Up @@ -228,7 +229,15 @@ def open_config_structured(
)
all_confs.append(c)
except Exception:
update_dotpaths.append(str(p).split("="))
try:
# check if a [<int>] is in the path using regex
if re.findall(r"\[\d+\]", p):
update_dotpaths.append(('dot', tuple(p.split("="))))

else:
update_dotpaths.append(('conf', OmegaConf.from_cli([p])))
except Exception:
raise Exception(f"Failed to load: {p}")

# all_confs = [OmegaConf.load(p) for p in path]
# special merge behavior for Blocks.SimulationConfig.addiational_files & Blocks.SimulationConfig.additional_sim_params
Expand Down Expand Up @@ -278,8 +287,12 @@ def open_config_structured(
c.Blocks.SimulationConfig.additional_sim_params = additional_sim_params

# for dot paths that failed to load
for key, value in update_dotpaths:
OmegaConf.update(c, key, value, force_add=True, merge=True)
for type_, conf in update_dotpaths:
# OmegaConf.update(c, key, value, force_add=True, merge=True)
if type_ == "dot":
OmegaConf.update(c, conf[0], conf[1], force_add=True, merge=True)
else:
c = OmegaConf.merge(c, conf)

else:
c = OmegaConf.load(
Expand Down

0 comments on commit b1933b9

Please sign in to comment.