Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update used variable tracking #674

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,22 +530,37 @@ def build_used_variables(self, workspace):
self.build_modifier_instances()
self.add_expand_vars(workspace)

backup_variables = self.variables.copy()

########################
# Define extra variables
########################

# Add modifier mode variables defaults as a placeholder:
for mod_inst in self._modifier_instances:
for var in mod_inst.mode_variables().values():
if var.name not in self.variables:
self.variables[var.name] = var.default

if self.package_manager is not None:
# Add package manager variable defaults as placeholder
for var in self.package_manager.package_manager_variables.values():
self.variables[var.name] = var.default

##########################################
# Expand used variables to track all usage
##########################################

# Add all known keywords
for key in self.keywords.keys:
self.expander._used_variables.add(key)
self.expander.expand_var_name(key)

# Add modifier mode variables:
for mod_inst in self._modifier_instances:
for var in mod_inst.mode_variables().keys():
self.expander._used_variables.add(var)
self.expander.expand_var_name(var)

if self.chained_experiments:
for chained_exp in self.chained_experiments:
if namespace.inherit_variables in chained_exp:
for var in chained_exp[namespace.inherit_variables]:
self.expander._used_variables.add(var)
self.expander.expand_var_name(var)

# Add variables from success criteria
criteria_list = workspace.success_list
Expand All @@ -557,12 +572,22 @@ def build_used_variables(self, workspace):
elif criteria.mode == "application_function":
self.evaluate_success()

if self.package_manager is not None:
self.package_manager.build_used_variables(workspace)

for template_name, template_conf in workspace.all_templates():
self.expander._used_variables.add(template_name)
self.expander.expand_var(template_conf["contents"])

if self.package_manager is not None:
self.package_manager.build_used_variables(workspace)
############################
# Reset variable definitions
############################
for var in self.variables:
if var not in backup_variables:
del self.variables[var]

for var, val in backup_variables.items():
douglasjacobsen marked this conversation as resolved.
Show resolved Hide resolved
self.variables[var] = val

return self.expander._used_variables

Expand Down
23 changes: 21 additions & 2 deletions lib/ramble/ramble/language/application_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def workload_variable(
workload=None,
workloads=None,
workload_group=None,
expandable=True,
expandable: bool = True,
track_used: bool = True,
**kwargs,
):
"""Define a new variable to be used in experiments
Expand All @@ -207,6 +208,19 @@ def workload_variable(
an experiment.

These are specific to each workload.

Args:
name (str): Name of variable to define
default: Default value of variable definition
description (str): Description of variable's purpose
values (list): Optional list of suggested values for this variable
workload (str): Single workload this variable is used in
workloads (list): List of modes this variable is used in
workload_group (str): Name of workload group this variable is used in
expandable (bool): True if the variable should be expanded, False if not.
track_used (bool): True if the variable should be tracked as used,
False if not. Can help with allowing lists without vecotizing
experiments.
"""

def _execute_workload_variable(app):
Expand All @@ -216,7 +230,12 @@ def _execute_workload_variable(app):
)

workload_var = ramble.workload.WorkloadVariable(
name, default=default, description=description, values=values, expandable=expandable
name,
default=default,
description=description,
values=values,
expandable=expandable,
**kwargs,
)

for wl_name in all_workloads:
Expand Down
5 changes: 5 additions & 0 deletions lib/ramble/ramble/language/modifier_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def modifier_variable(
mode: Optional[str] = None,
modes: Optional[list] = None,
expandable: bool = True,
track_used: bool = False,
**kwargs,
):
"""Define a variable for this modifier
Expand All @@ -269,6 +270,9 @@ def modifier_variable(
mode (str): Single mode this variable is used in
modes (list): List of modes this variable is used in
expandable (bool): True if the variable should be expanded, False if not.
track_used (bool): True if the variable should be tracked as used,
False if not. Can help with allowing lists without vecotizing
experiments.
"""

def _define_modifier_variable(mod):
Expand All @@ -288,6 +292,7 @@ def _define_modifier_variable(mod):
description=description,
values=values,
expandable=expandable,
**kwargs,
)

return _define_modifier_variable
Expand Down
4 changes: 4 additions & 0 deletions lib/ramble/ramble/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(
description: str = None,
values=None,
expandable: bool = True,
track_used: bool = True,
**kwargs,
):
"""Constructor for a new variable
Expand All @@ -32,12 +33,15 @@ def __init__(
description (str): Description of variable
values: List of suggested values for variable
expandable (bool): True if variable can be expanded, False otherwise
track_used (bool): True if variable should be considered used,
False to ignore it for vectorizing experiments
"""
self.name = name
self.default = default
self.description = description
self.values = values.copy() if isinstance(values, list) else [values]
self.expandable = expandable
self.track_used = track_used

def __str__(self):
if not hasattr(self, "_str_indent"):
Expand Down