ramble.language namespace
Submodules
ramble.language.application_language module
- ramble.language.application_language.cleanup(name, regex, directory=None, recurse=False, description='', pre=False, post=False, when=None, **kwargs)[source]
Adds a cleanup operation to the application.
This directive defines a cleanup step that removes files matching a regular expression from a specified directory.
- Parameters:
name (str) – Name of the cleanup operation.
regex (str) – Regex passed to find to match files and directories to be deleted.
directory (str) – The directory to perform the cleanup in. Defaults to {experiment_run_dir}.
recurse (bool) – Whether to search for files recursively in subdirectories.
description (str) – Description of the cleanup operation.
pre (bool) – Whether to run this cleanup before the main application execution.
post (bool) – Whether to run this cleanup after the main application execution.
when (list | None) – List of when conditions to apply to this directive.
- ramble.language.application_language.executable(name, template, when=None, **kwargs)[source]
Adds an executable to this application
Defines a new executable that can be used to configure workloads and experiments with.
Executables may or may not use MPI.
- Parameters:
name (str) – Name of the executable
template (list[str] | str) – The template command this executable should generate from
use_mpi (bool) – determines if this executable should be wrapped with an mpirun like command or not
mpi (bool) – Alias for
use_mpivariables (dict) – Dictionary of variable definitions to use for this executable only
redirect (str) – Optional, sets the path for outputs to be written to. defaults to {log_file}
output_capture (str) – Optional, Declare which output (stdout, stderr, both) to capture. Defaults to stdout
run_in_background (bool) – Optional, Declare if the command should run in the background. Defaults to False
when (list | None) – List of when conditions to apply to directive
- ramble.language.application_language.input_file(name, url, description, target_dir='{workload_input_dir}', sha256=None, extension=None, expand=True, when=None, **kwargs)[source]
Adds an input file definition to this application
Defines a new input file. An input file must define it’s name, and a url where the input can be fetched from.
- Parameters:
name (str) – Name of the input file
url (str) – Path to the input file / archive
description (str) – Description of this input file
target_dir (str) – Optional, the directory where the archive will be expanded. Defaults to the ‘{workload_input_dir}’ + os.sep + ‘{input_name}’
sha256 (str) – Optional, the expected sha256 checksum for the input file
extension (str) – Optiona, the extension to use for the input, if it isn’t part of the file name.
expand (bool) – Optional. Whether the input should be expanded or not. Defaults to True
when (list | None) – List of when conditions to apply to directive
- ramble.language.application_language.license_name(name, **kwargs)[source]
Add a new license name directive, to specify license name in a declarative way.
- Parameters:
name (str) – name to use during license lookup and propagation
- ramble.language.application_language.stage_files(src=None, dst=None, stages=None, name=None, method='user-defined', when=None, **kwargs)[source]
Adds an executable that stages an input file or directory.
Defines a new executable that copies or links a file or directory from a source to a destination. This is useful for staging input files that are not managed by the input_file directive.
The staging method is controlled by the stage_method configuration option, which can be set to ‘cp’, ‘rsync’, ‘symbolic_link’, ‘hard_link’, or ‘install’ (for files only).
- Parameters:
src (str | None) – The source path of the file or directory.
dst (str | None) – The destination path. If src is passed in, and dst is not, dst defaults to the experiment_run_dir.
stages (list(tuple(str, str)) | None) – A list of tuples describing pairs of src, dest locations to stage.
name (str | None) – The name of the executable. Defaults to ‘stage-files’.
method (str) – The method to use for this stage. Can be one of: “user-defined”, “cp”, “rsync”, “symbolic_link”, “hard_link”, “install”
when (list | None) – List of when conditions to apply to this directive.
- ramble.language.application_language.workload(name, executables=None, executable=None, input=None, inputs=None, tags=None, when=None, where=None, exclude_where=None, **kwargs)[source]
Adds a workload to this application
Defines a new workload that can be used within the context of its application.
- Parameters:
One of executable, or executables is required as an input argument.
- ramble.language.application_language.workload_group(name, workloads=None, mode=None, when=None, **kwargs)[source]
Adds a workload group to this application
Defines a new workload group that can be used within the context of its application.
- ramble.language.application_language.workload_variable(name, default=None, description='', values=None, strict: bool = True, workload=None, workloads=None, workload_group=None, workload_defaults=None, expandable: bool = True, track_used: bool = True, when=None, environment_variable_name=None, **kwargs)[source]
Define a new variable to be used in experiments
Defines a new variable that can be defined within the experiments.yaml config file, to control various aspects of an experiment.
These are specific to each workload.
- Parameters:
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
strict (bool) – If True (the default) and values is not None, the variable’s value will be validated against the values list.
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.
workload_defaults (dict) – Dictionary mapping workload names to default values. Mututally exclusive with workload, workloads, workload_group, and default.
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 vectorizing experiments.
when (list | None) – List of when conditions to apply to directive
environment_variable_name (str | None) – If not None, an environment variable of this name will be defined with the value of this variable.
ramble.language.language_base module
This package contains the underlying implementation for the language directives, which are to allow functions to be invoked at class level
- class ramble.language.language_base.DirectiveDictDescriptor(name: str)[source]
Bases:
objectA descriptor that lazily executes directives on first access.
- exception ramble.language.language_base.DirectiveError(message: str, long_message: str | None = None)[source]
Bases:
RambleErrorThis is raised when something is wrong with a language directive.
- class ramble.language.language_base.DirectiveMeta(name: str, bases: tuple, attr_dict: dict)[source]
Bases:
ABCMetaFlushes the directives that were temporarily stored in the staging area into the package.
- classmethod directive(dicts: Sequence[str] | str | None = None, init_value: Any = <object object>, language_type: str = 'shared') Callable[[...], Any][source]
Decorator for Ramble directives.
- static get_cached_execution_plan(target_dict: str) Tuple[List[str], Set[str]][source]
Returns cached execution plan with directives as a set for O(1) membership check.
- static push_default_args(default_args: Dict[str, Any]) None[source]
Push default arguments onto the stack.
ramble.language.language_helpers module
- ramble.language.language_helpers.add_variable_validator(obj, var_name, var_values, when_list, wl_name=None)[source]
Adds a validator to an object to ensure a variable’s value is in a list of values.
- ramble.language.language_helpers.are_when_compatible(when_set1, when_set2)[source]
Determine if two sets of when conditions are compatible
- ramble.language.language_helpers.build_when_list(when_arg: str | List[str] | None, obj: Any, directive_id: str, directive_name: str) List[str][source]
Construct list of when conditions based on a directives input argument Also, validate that when is passed in with the right type.
- Parameters:
when_arg (str | list(str)) – Single or list of string conditions that were input into the calling directive.
obj – A ramble object (i.e. application, modifier, etc..)
directive_id (str) – Directive identifier. The calling directive can define what is used here, but it should be something that can help users identify where errors from this method originate from.
directive_name (str) – Name of the calling directive
- Returns:
List of strings for all of the when conditions.
- Return type:
- ramble.language.language_helpers.check_definition(single_type, multiple_type, single_arg_name, multiple_arg_name, directive_name)[source]
Sanity check definitions before merging or require
- Parameters:
single_type – Single string for type name
multiple_type – List of strings for type names, may contain wildcards
multiple_pattern_match – List of strings to match against patterns in multiple_type
single_arg_name – String name of the single_type argument in the directive
multiple_arg_name – String name of the multiple_type argument in the directive
directive_name – Name of the directive requiring a type
- ramble.language.language_helpers.expand_patterns(merged_types: list, multiple_pattern_match: list | dict)[source]
Expand wildcard patterns within a list of names
This method takes an input list containing wildcard patterns and expands the wildcard with values matching a list of names. Returns a list containing matching names and any inputs with zero matches.
If multiple_pattern_match is a dict keyed on ‘when’, it checks the input against patterns in all ‘when’ conditions, without evaluating them, and returns a list containing names that match under any when condition, and any inputs with zero matches.
- Parameters:
merged_types – List of strings for type names, may contain wildcards
multiple_pattern_match – List of strings (optional: nested in when_set dict) to match against patterns in merged_types
- Returns:
List of expanded patterns matching the names list plus patterns not found in the names list.
- Return type:
- ramble.language.language_helpers.is_when_impossible(when_list)[source]
Determine if a single list of when conditions is self-contradictory
- ramble.language.language_helpers.merge_conditions(obj, directive_name: str, single_arg_name: str | None = None, multiple_arg_name: str | None = None, **kwargs) List[List[str]][source]
Merge conditions for a type in a directive, and converts all conditions to when conditions
If single/multiple values are provided, this method will validate that they are properly defined, and will merge them into a list of when conditions for each mode.
- Parameters:
obj – Object instance
directive_name – Name of the calling directive
single_arg_name – Name of the singular kwarg being required
multiple_arg_name – Name of the plural kwarg being required
- Kwargs:
when (list | None): List of when conditions to apply to directive mode (str | None): Modifier mode to be applied as a when condition modes (list(str) | None): List of modifier modes to be applied as when conditions
- ramble.language.language_helpers.merge_definitions(single_type, multiple_type, multiple_pattern_match, single_arg_name, multiple_arg_name, directive_name)[source]
Merge definitions of a type
This method will merge two optional definitions of single_type and multiple_type.
- Parameters:
single_type – Single string for type name
multiple_type – List of strings for type names, may contain wildcards
multiple_pattern_match – List of strings to match against patterns in multiple_type
single_arg_name – String name of the single_type argument in the directive
multiple_arg_name – String name of the multiple_type argument in the directive
directive_name – Name of the directive requiring a type
- Returns:
List of all type names (Merged if both
single_typeandmultiple_typedefinitions are valid)- Return type:
- ramble.language.language_helpers.require_definition(single_type, multiple_type, multiple_pattern_match, single_arg_name, multiple_arg_name, directive_name)[source]
Require at least one definition for a type in a directive
This method will validate that single_type / multiple_type are properly defined.
It will raise an error if at least one type is not defined, or if either are the incorrect type.
- Parameters:
single_type – Single string for type name
multiple_type – List of strings for type names, may contain wildcards
multiple_pattern_match – List of strings to match against patterns in multiple_type
single_arg_name – String name of the single_type argument in the directive
multiple_arg_name – String name of the multiple_type argument in the directive
directive_name – Name of the directive requiring a type
- Returns:
List of all type names (Merged if both single_type and multiple_type definitions are valid)
- Return type:
ramble.language.modifier_language module
- ramble.language.modifier_language.default_mode(name, **kwargs)[source]
Define a default mode for this modifier.
The default mode will be used if modifier mode is not specified in an experiment.
- Parameters:
name (str) – Name of mode to be used as default
- ramble.language.modifier_language.env_var_modification(name, modification=None, method='set', mode=None, modes=None, when=None, **kwargs)[source]
Define an environment variable modifier
Environment variable modifications modify the values of environment variables within the application instance.
- Parameters:
name (str) – The name of the environment variable that will be modified
modification (str) – The value of the modification
method (str) – The method of the modification.
mode (str | None) – Name of mode this env_var_modification should apply in
modes (list(str) | None) – List of mode names this env_var_modification should apply in
when (list | None) – List of when conditions this env_var_modification should apply in
Supported values for method are:
set: Defines the variable to equal the modification value
unset: Removes any definition of the variable from the environment
prepend: Prepends the modification to the beginning of the variable. Always uses the separator ‘:’
append: Appends the modification value to the end of the value. Allows a keyword argument of ‘separator’ to define the delimiter between values.
- ramble.language.modifier_language.executable_modifier(name, usage_filter=None, when=None, **kwargs)[source]
Register an executable modifier
Executable modifiers can modify various aspects of non-builtin application executable definitions.
These behave similarly to builtins, in that a python method defines the actual modifications
For example:
executable_modifier('write_exec_name') def write_exec_name(self, executable_name, executable, app_inst=None): prepend_execs = [] append_execs = [ExecutableCommand( template='echo "{executable_name}"', mpi=False, redirect='{log_file}', output_capture=OUTPUT_CAPTURE.DEFAULT )] return prepend_execs, append_execs
Would append the echo “{executable_name}” to every non-builtin executable in an experiment.
Executable modifiers are allowed to modify the input executable in place. Executable modifiers must return two lists of executables.
- Parameters:
name (str) – Name of executable modifier to use. Should be the name of a class method.
usage_filter (str) – Filters the application of this executable modifier. Modifiers can register filters to select how to apply this. Valid default options include: None, “once”, “first_mpi”, “all_mpi”
when (list | None) – List of when conditions this executable modifier should apply in
Each executable modifier needs to return:
prepend_execs (list(CommandExecutable)): List of executables to inject before the base executable
append_execs (list(CommandExecutable)): List of executables to inject after the base executable
- ramble.language.modifier_language.mode(name, description, **kwargs)[source]
Define a new mode for this modifier.
Modes allow a modifier to bundle a set of modifications together.
NOTE: A mode ‘disabled’ is defined by default for all modifiers.
- ramble.language.modifier_language.modifier_conflict(conflict_type, when=None, **kwargs)[source]
Define a conflict with other modifiers on the same experiment.
Allowed values are defined in the MODIFIER_CONFLICT class in conflicts.py
- Parameters:
conflict_type – Either a string or integer based on the options in ramble.util.conflicts.MODIFIER_CONFLICT
- ramble.language.modifier_language.modifier_variable(name: str, default, description: str, values: list | None = None, mode: str | None = None, modes: list | None = None, expandable: bool = True, track_used: bool = False, when=None, **kwargs)[source]
Define a variable for this modifier
- Parameters:
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
mode (str) – Single mode this variable is used in, if no mode/modes are specified, will apply to all modes.
modes (list) – List of modes this variable is used in, if no mode/modes are specified, will apply to all modes.
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 vectorizing experiments.
when (list | None) – List of when conditions to apply to directive
- ramble.language.modifier_language.package_manager_requirement(command: str, validation_type: str, mode: str | None = None, modes: list | None = None, regex=None, package_manager: str = '*', when=None, **kwargs)[source]
Define a requirement when this modifier is used in an experiment with a package manager.
This allows modifiers to inject additional requirements on packages managers. These can be used to ensure package manager commands return specific values.
- Parameters:
command (str) – Package manager command to execute, when evaluating the requirement
validation_type (str) – Type of validation to perform on output of command. Valid types are: ‘empty’, ‘not_empty’, ‘contains_regex’, ‘does_not_contain_regex’
mode (str) – Usage mode this requirement should apply to
modes (list(str)) – List of usage modes this requirement should apply to
regex (str) – Regular expression to use when validation_type is either ‘contains_regex’ or ‘does_no_contain_regex’
package_manager (str) – Name of the package manager this requirement applies to
when (list | None) – List of when conditions this requirement should apply to
- ramble.language.modifier_language.variable_modification(name, modification, method='set', mode=None, modes=None, separator=' ', when=None, **kwargs)[source]
Define a new variable modification for a mode in this modifier.
A variable modification will apply a change to a defined variable within an experiment.
- Parameters:
name (str) – The variable to modify
modification (str) – The value to modify ‘name’ with
method (str) – How the modification should be applied
mode (str) – Single mode to group this modification into
modes (str) – List of modes to group this modification into
separator (str) – Optional separator to use when modifying with ‘append’ or ‘prepend’ methods.
when (list | None) – List of when conditions this modification should apply in
- Supported values are ‘append’, ‘prepend’, and ‘set’:
‘append’ will add the modification to the end of ‘name’ ‘prepend’ will add the modification to the beginning of ‘name’ ‘set’ (Default) will overwrite ‘name’ with the modification
ramble.language.package_manager_language module
- ramble.language.package_manager_language.package_manager_family(*names: str, **kwargs)[source]
Add a new family to this package manager
- Parameters:
name (str) – Name of family to apply to this package manager
- ramble.language.package_manager_language.package_manager_variable(name: str, default, description: str, values: list | None = None, expandable: bool = True, track_used: bool = False, when=None, **kwargs)[source]
Define a variable for this package manager
- Parameters:
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
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 vectorizing
when (list | None) – List of when conditions to apply to directive
ramble.language.platform_language module
ramble.language.system_language module
- ramble.language.system_language.available_platforms(platforms, **kwargs)[source]
Sets the available platforms for this system
- Parameters:
platforms (list) – List of available platforms
- ramble.language.system_language.default_package_manager(name, **kwargs)[source]
Sets the default package manager for this system
- Parameters:
name (str) – The name of the default package manager
- ramble.language.system_language.default_platform(name, **kwargs)[source]
Sets the default platform for this system
- Parameters:
name (str) – The name of the default platform
- ramble.language.system_language.default_workflow_manager(name, **kwargs)[source]
Sets the default workflow manager for this system
- Parameters:
name (str) – The name of the default workflow manager
- ramble.language.system_language.platform_variable_map(variable_name, var_map, **kwargs)[source]
Defines a mapping of platform to variable values
ramble.language.utility_language module
- ramble.language.utility_language.bootstrappable(is_bootstrappable: bool, when=None, **kwargs)[source]
ramble.language.workflow_manager_language module
- ramble.language.workflow_manager_language.workflow_manager_family(*names: str, **kwargs)[source]
Add a new family to this workflow manager
- Parameters:
name (str) – Name of family to apply to this workflow manager
- ramble.language.workflow_manager_language.workflow_manager_variable(name: str, default, description: str, values: list | None = None, expandable: bool = True, track_used: bool = False, when=None, **kwargs)[source]
Define a variable for this wm
- Parameters:
name – Name of variable
default – Default value if the variable is not defined
description – Description of the variable
values – Optional list of suggested values for this variable
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 vectorizing
when (list | None) – List of when conditions to apply to directive