Skip to content

Commit

Permalink
Add default value for met_subset when not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
C. Carouge authored and ccarouge committed Sep 30, 2022
1 parent d06f9b4 commit 344bd21
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
=======

* new version
* Add specification of a subset of met. sites
* Handling of revision number for branches
* Formatting

v0.1.5
------

Expand Down
63 changes: 38 additions & 25 deletions benchcab/bench_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,58 @@
from benchcab.set_default_paths import set_paths
from benchcab.benchtree import BenchTree


class BenchSetup(object):
def __init__(self, myconfig:str):
def __init__(self, myconfig: str):
"""
myconfig: str, Name of the config file to use for setup."""

self.myconfig = myconfig

@staticmethod
def check_config(opt:dict):
def check_config(opt: dict):
"""Run some checks on the config file to ensure the data is coherent.
check1: make sure the names in use_branches are keys in the dictionary.
check2: make sure all required entries are listed
check3: add revision pointing to HEAD of branch if missing for one branch
check4: add met_subset entry if not in input file
"""

assert all([x in opt for x in opt["use_branches"][0:2]]), "At least one of the first 2 aliases " \
assert all([x in opt for x in opt["use_branches"][0:2]]), (
"At least one of the first 2 aliases "
" listed in 'use_branches' is not an entry in the config file to define a CABLE branch."

assert all([x in opt for x in [
"use_branches",
"project",
"user",
"modules",
]]), "The config file does not list all required entries. "\
"Those are 'use_branches', 'project', 'user', 'modules'"

assert len(opt["use_branches"]) >= 2, "You need to list 2 branches in 'use_branches'"
)

assert all(
[
x in opt
for x in [
"use_branches",
"project",
"user",
"modules",
]
]
), (
"The config file does not list all required entries. "
"Those are 'use_branches', 'project', 'user', 'modules'"
)

assert (
len(opt["use_branches"]) >= 2
), "You need to list 2 branches in 'use_branches'"
if len(opt["use_branches"]) > 2:
print("------------------------------------------------------")
print("Warning: more than 2 branches listed in 'use_branches'")
print("Only the first 2 branches will be used.")
print("------------------------------------------------------")
# Add "revision" to each branch description if not provided with default value -1, i.e. HEAD of branch

# Add "revision" to each branch description if not provided with default value -1, i.e. HEAD of branch
for req_branch in opt["use_branches"][:2]:
opt[req_branch].setdefault("revision",-1)
opt[req_branch].setdefault("revision", -1)

# Add a "met_subset" key set to empty list if not found in config.yaml file.
opt.setdefault("met_subset", [])

def read_config(self):
"""Read config file for the CABLE benchmarking"""
Expand All @@ -48,15 +64,15 @@ def read_config(self):

with open(Path(self.myconfig), "r") as fin:
opt = yaml.safe_load(fin)

self.check_config(opt)
return opt

@staticmethod
def compilation_setup(ModToLoad:list):
"""Load the modules and define the paths to libraries
def compilation_setup(ModToLoad: list):
"""Load the modules and define the paths to libraries
depending on the machine name as needed for CABLE compilation.
ModToLoad: list, list of modules to load for Gadi. Empty list for other cases"""

(_, nodename, _, _, _) = os.uname()
Expand All @@ -72,11 +88,8 @@ def setup_bench(self):
compilation_opt = self.compilation_setup(opt["modules"])

# Setup the minimal benchmarking directory tree
myworkdir=Path.cwd()
benchdirs=BenchTree(myworkdir)
myworkdir = Path.cwd()
benchdirs = BenchTree(myworkdir)
benchdirs.create_minbenchtree()

return (opt, compilation_opt, benchdirs)



0 comments on commit 344bd21

Please sign in to comment.