ramble.util package
Subpackages
Submodules
ramble.util.class_attributes module
- ramble.util.class_attributes.convert_class_attributes(obj)[source]
Convert class attributes defined from directives to instance attributes Class attributes that are valid for conversion are stored in the _directive_names attribute.
- Parameters:
obj (object) – Input object instance to convert attributes in
ramble.util.colors module
- exception ramble.util.colors.ColorParseError(message)[source]
Bases:
ExceptionRaised when a color format fails to parse.
- ramble.util.colors.auto_escape(s)[source]
Escapes @ characters that are not part of valid color formats.
- ramble.util.colors.cescape(string)[source]
Escapes special characters needed for color codes.
Replaces the following symbols with their equivalent literal forms:
@@@}}}
- ramble.util.colors.clen(string)[source]
Return the length of a string, excluding ansi color sequences.
- ramble.util.colors.colorize(string, **kwargs)[source]
Wrapper for llnl.util.tty.color.colorize that automatically escapes @
- ramble.util.colors.cprint(string, **kwargs)[source]
Wrapper for llnl.util.tty.color.cprint that automatically escapes @ characters in the string if they do not match valid color codes.
- ramble.util.colors.cwrite(string, **kwargs)[source]
Wrapper for llnl.util.tty.color.cwrite that automatically escapes @ characters in the string if they do not match valid color codes.
ramble.util.command_runner module
- class ramble.util.command_runner.CommandRunner(name: str | None = None, command: str | None = None, shell: str = 'bash', dry_run: bool = False, path: str | None = None)[source]
Bases:
objectRunner for executing external commands
This class provides a generic wrapper on external commands, to provide a unified way to handle dry-run execution of external commands.
Can be inherited to construct custom command runners.
- execute(executable: Executable, args: List[str], allow_failure: bool = False, return_output: bool = False) str | None[source]
Wrapper around execution of a command
Handles execution of a command when the execution path is dependent on whether dry run is enabled or disabled.
- exception ramble.util.command_runner.NoPathRunnerError[source]
Bases:
RunnerErrorRaised when a runner is used that does not have a path set
- exception ramble.util.command_runner.RunnerError[source]
Bases:
ExceptionRaised when a problem occurs with a spack environment
- exception ramble.util.command_runner.ValidationFailedError[source]
Bases:
RunnerErrorRaised when a package manager requirement was not met
ramble.util.conflicts module
ramble.util.conversions module
- ramble.util.conversions.canonical_none(maybe_none: Any) Any | None[source]
Convert a small set of “none-looking” inputs to None
- ramble.util.conversions.convert_to_number(val: Any) Any[source]
Convert (in order of preference) to int, or float, or simply return itself
ramble.util.directives module
ramble.util.editor module
Module for finding the user’s preferred text editor.
Defines one function, editor(), which invokes the editor defined by the user’s VISUAL environment variable if set. We fall back to the editor defined by the EDITOR environment variable if VISUAL is not set or the specified editor fails (e.g. no DISPLAY for a graphical editor). If neither variable is set, we fall back to one of several common editors, raising an EnvironmentError if we are unable to find one.
- ramble.util.editor.editor(*args, **kwargs)[source]
Invoke the user’s editor.
This will try to execute the following, in order:
$VISUAL <args> # the “visual” editor (per POSIX)
$EDITOR <args> # the regular editor (per POSIX)
some default editor (see
_default_editors) with <args>
If an environment variable isn’t defined, it is skipped. If it points to something that can’t be executed, we’ll print a warning. And if we can’t find anything that can be executed after searching the full list above, we’ll raise an error.
- Optional Arguments:
_exec_func (function): invoke this function instead of
os.execv()
ramble.util.env module
ramble.util.executable module
- class ramble.util.executable.CommandExecutable(name: str, template: str | List[str], use_mpi: bool = False, mpi: bool = False, variables: Dict[str, Any] | None = None, redirect: str = '{log_file}', output_capture: OUTPUT_CAPTURE = OUTPUT_CAPTURE.ALL, run_in_background: bool = False, allow_extension: bool = False, when: List[str] | None = None, **kwargs: Any)[source]
Bases:
objectCommandExecutable class This class is used to represent internal executables in Ramble.
These executables are portions of an experiment definition. They are generally used to group one or more commands together into an executable name.
- copy() CommandExecutable[source]
Replicate a CommandExecutable instance
- exception ramble.util.executable.CommandExecutableError(message: str, long_message: str | None = None)[source]
Bases:
RambleErrorClass for errors when using command executable classes
- class ramble.util.executable.PrefixedExecutable(name)[source]
Bases:
ExecutableA version of spack.util.executable.Executable that allows command prefixes to be added
- copy() PrefixedExecutable[source]
- ramble.util.executable.which(*args: str, **kwargs: Any) PrefixedExecutable | None[source]
Finds an executable in the path like command-line which.
If given multiple executables, returns the first one that is found. If no executables are found, returns None.
- Parameters:
*args (str) – One or more executables to search for
- Keyword Arguments:
- Returns:
The first executable that is found in the path
- Return type:
ramble.util.file_cache module
- exception ramble.util.file_cache.CacheError(message: str, long_message: str | None = None)[source]
Bases:
RambleError
- class ramble.util.file_cache.FileCache(root, timeout=120)[source]
Bases:
objectThis class manages cached data in the filesystem.
Cache files are fetched and stored by unique keys. Keys can be relative paths, so that there can be some hierarchy in the cache.
The FileCache handles locking cache files for reading and writing, so client code need not manage locks for cache entries.
- init_entry(key)[source]
Ensure we can access a cache file. Create a lock for it if needed.
Return whether the cache file exists yet or not.
- mtime(key)[source]
Return modification time of cache file, or 0 if it does not exist.
Time is in units returned by os.stat in the mtime field, which is platform-dependent.
ramble.util.file_util module
- ramble.util.file_util.create_symlink(base, link)[source]
Create symlink of a file to give a known and predictable path
- ramble.util.file_util.get_file_path(path: str, workspace) str[source]
A wrapper for file paths used in a Ramble application, to facilitate testing.
- Parameters:
path (str) – A file path
workspace (ramble.workspace.Workspace) – A ramble workspace
- Returns:
A file path
- Return type:
(str)
ramble.util.foms module
- class ramble.util.foms.BetterDirection(*values)[source]
Bases:
Enum- HIGHER = 1
- INAPPLICABLE = 4
- INDETERMINATE = 3
- LOWER = 2
- class ramble.util.foms.FomType(*values)[source]
Bases:
Enum- CATEGORY = 4
- INFO = 5
- MEASURE = 3
- THROUGHPUT = 2
- TIME = 1
- UNDEFINED = 6
- class ramble.util.foms.SummaryFoms(*values)[source]
Bases:
Enum- N_SUCCESS = 'n_success_repeats'
- N_TOTAL = 'n_total_repeats'
- SUMMARY = 'Experiment Summary'
- ramble.util.foms.get_literal_from_regex(regex_str: str) str[source]
Extracts a first-encountered required literal string from a regex pattern.
This is used to create fast string pre-filters to avoid executing complex regex matching. This is not exhaustive, as it doesn’t recurse into sub-patterns. It is only intended as a heuristic to short-circuit the matching process.
ramble.util.format module
ramble.util.graph module
- class ramble.util.graph.GraphNode(key, attribute=None, obj_inst=None)[source]
Bases:
objectClass representing a node of a graph, where the node can have an attribute attached to it.
This allows nodes to be added into a graph, have the topological order of the graph returned, and be able to refer to the attribute of the original node easily.
- order_after(key)[source]
Adds information that this node should come after another node
- Parameters:
key (str) – Key of node that should come before this node.
ramble.util.hashing module
ramble.util.install_cache module
Provide data structures to assist with caching operations
ramble.util.lock module
Wrapper for llnl.util.lock allows locking to be enabled/disabled.
- class ramble.util.lock.Lock(*args, **kwargs)[source]
Bases:
LockLock that can be disabled.
This overrides the
_lock()and_unlock()methods fromllnl.util.lockso that all the lock API calls will succeed, but the actual locking mechanism can be disabled via_enable_locks.
- exception ramble.util.lock.LockError[source]
Bases:
ExceptionRaised for any errors related to locks.
- exception ramble.util.lock.LockTimeoutError[source]
Bases:
LockErrorRaised when an attempt to acquire a lock times out.
- exception ramble.util.lock.LockUpgradeError(path)[source]
Bases:
LockErrorRaised when unable to upgrade from a read to a write lock.
- class ramble.util.lock.ReadTransaction(lock, acquire=None, release=None, timeout=None)[source]
Bases:
LockTransactionLockTransaction context manager that does a read and releases it.
- class ramble.util.lock.WriteTransaction(lock, acquire=None, release=None, timeout=None)[source]
Bases:
LockTransactionLockTransaction context manager that does a write and releases it.
- ramble.util.lock.check_lock_safety(path)[source]
Do some extra checks to ensure disabling locks is safe.
This will raise an error if
pathcan is group- or world-writable AND the current user can write to the directory (i.e., if this user AND others could write to the path).This is intended to run on the Ramble prefix, but can be run on any path for testing.
ramble.util.logger module
- class ramble.util.logger.Logger[source]
Bases:
objectLogger class
This class providers additional functionality on top of LLNL’s tty utility. Namely, this class provides a stack of log files, and allows errors to be printed to all log files instead of only one.
- active_log()[source]
Return the path for the active log
If any logs are in the log stack, return the filepath of the active log. Otherwise, return the string ‘stdout’
- active_stream()[source]
Return the stream for the active log
If any logs are in the log stack, return the stream object of the active log. Otherwise, return None to indicate the system is handling printing.
- add_log(path)[source]
Add a log to the current log stack
Opens (with ‘a+’ permissions) the file provided by the ‘path’ argument, and stores both the path, and the opened stream object in the current stack in the active position.
- Parameters:
path – File path for the new log file
- add_log_context(path)[source]
Context manager to add and remove a log file
Ensures that the log is removed from the stack even if an exception occurs. If inner add_log/remove_log calls disrupt the stack order, it ensures it only removes the log it added.
- all_msg(*args, **kwargs)[source]
Print a message to all logs
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for all logs and the default log (to screen).
- all_warnings()[source]
Print all warnings that have been encountered
This is intended to be called once, and will print all warnings that were encountered over the course of the execution.
- debug(*args, **kwargs)[source]
Print a debug message to the active log
Pass all args and kwargs to tty.debug (which will concatenate and print). Perform this action for the active log only.
- die(*args, **kwargs)[source]
Print an error message and terminate execution
Pass all args and kwargs to tty.error (which will concatenate and print). Perform this action all logs. After all logs are printed to, terminate execution (and error) using tty.die.
- error(*args, **kwargs)[source]
Print an error message
Pass all args and kwargs to tty.error (which will concatenate and print). Perform this action all logs, and the default stream (print to screen).
- info(*args, **kwargs)[source]
Print a message to the active log
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for the active log only.
- msg(*args, **kwargs)[source]
Print a message to the active log
Pass all args and kwargs to tty.info (which will concatenate and print). Perform this action for the active log only.
- remove_log()[source]
Remove the active stack
Pop the active log from the log stack, and close the log stream.
ramble.util.matrices module
- ramble.util.matrices.extract_matrices(action, name, in_dict)[source]
Extract matrix definitions from a dictionary
- Parameters:
action – The action of an object definition where matrices are being extracted from
name – The name of the object
in_dict – The dictionary containing definitions
- Returns:
list of matrix definitions
ramble.util.module_utils module
A utility for dynamically importing modules.
ramble.util.naming module
- ramble.util.naming.match_pattern(pattern, string)[source]
Match a string against a pattern (regex or glob)
- ramble.util.naming.mod_to_class(mod_name)[source]
Convert a name from module style to class name style. Ramble mostly follows PEP-8:
Module and package names use lowercase_with_underscores.
Class names use the CapWords convention.
Regular source code follows these conventions. Ramble is a bit more liberal with its Application names:
They can contain ‘-’ as well as ‘_’, but cannot start with ‘-‘.
They can start with numbers, e.g. “3proxy”.
This function converts from the module convention to the class convention by removing _ and - and converting surrounding lowercase text to CapWords. If mod_name starts with a number, the class name returned will be prepended with ‘_’ to make a valid Python identifier.
- ramble.util.naming.possible_ramble_module_names(python_mod_name)[source]
Given a Python module name, return a list of all possible ramble module names that could correspond to it.
- ramble.util.naming.ramble_module_to_python_module(mod_name)[source]
Given a Ramble module name, returns the name by which it can be imported in Python.
- ramble.util.naming.simplify_name(name)[source]
Simplify package name to only lowercase, digits, and dashes.
Simplifies a name which may include uppercase letters, periods, underscores, and pluses. In general, we want our package names to only contain lowercase letters, digits, and dashes.
- ramble.util.naming.valid_fully_qualified_module_name(mod_name)[source]
Return whether mod_name is a valid namespaced module name.
- ramble.util.naming.valid_module_name(mod_name)[source]
Return whether mod_name is valid for use in Ramble.
ramble.util.object_utils module
Module for providing utils related to Ramble objects.
- ramble.util.object_utils.filter_by_name(glob_patterns: List[str], search_description: bool, obj_type: Any) List[str][source]
Filters the sequence of object names by the given glob patterns.
- Parameters:
glob_patterns – patterns to match against object names
search_description – whether to search inside object descriptions
obj_type – type of the Ramble objects to search for
- Returns:
filtered and sorted list of object names
ramble.util.output_capture module
ramble.util.path module
Utilities for managing paths in ramble.
TODO: this is really part of ramble.config. Consolidate it.
- ramble.util.path.canonicalize_path(path)[source]
Same as substitute_path_variables, but also take absolute path.
- ramble.util.path.substitute_config_variables(path, local_replacements)[source]
Substitute placeholders into paths.
Ramble allows paths in configs to have some placeholders, as follows:
$ramble The ramble instance’s prefix
$user The current user’s username
$tempdir Default temporary directory returned by tempfile.gettempdir()
These are substituted case-insensitively into the path, and users can use either
$varor${var}syntax for the variables.
ramble.util.shell_utils module
Utils for handling shell specialization
- exception ramble.util.shell_utils.UnsupportedError(message: str, long_message: str | None = None)[source]
Bases:
RambleErrorError when certain shell features are not supported.
- ramble.util.shell_utils.cmd_sub_str(shell, cmd: str)[source]
Get the command substitution string of the given shell
- ramble.util.shell_utils.gen_dict_definition(var_name, dict, shell='bash')[source]
A utility for generating commands for defining a dict in a shell. It currently supports bash only. It maps a python dict into an associative array in bash.
- Parameters:
var_name – the variable name for the generated dict in the shell.
dict – the input dict.
shell – the shell used. Currently this is bash-only.
- Returns:
The string of the generated shell commands.
ramble.util.spec_utils module
ramble.util.stats module
- class ramble.util.stats.ConfidenceLevel(*values)[source]
Bases:
Enum- CL_50 = 0.5
- CL_90 = 0.9
- CL_95 = 0.95
- CL_99 = 0.99
- class ramble.util.stats.StatsConfidenceIntervalBase[source]
Bases:
StatsBase- confidence_level: ConfidenceLevel
- class ramble.util.stats.StatsConfidenceIntervalLower50[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.5
- class ramble.util.stats.StatsConfidenceIntervalLower90[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.9
- class ramble.util.stats.StatsConfidenceIntervalLower95[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.95
- class ramble.util.stats.StatsConfidenceIntervalLower99[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.99
- class ramble.util.stats.StatsConfidenceIntervalUpper50[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.5
- class ramble.util.stats.StatsConfidenceIntervalUpper90[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.9
- class ramble.util.stats.StatsConfidenceIntervalUpper95[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.95
- class ramble.util.stats.StatsConfidenceIntervalUpper99[source]
Bases:
StatsConfidenceIntervalBase- confidence_level: ConfidenceLevel = 0.99
ramble.util.version module
ramble.util.web module
- class ramble.util.web.LinkParser[source]
Bases:
HTMLParserThis parser just takes an HTML page and strips out the hrefs on the links. Good enough for a really simple spider.
- ramble.util.web.RAMBLE_USER_AGENT = 'Ramblebot/0.6.0'
User-Agent used in Request objects
- exception ramble.util.web.SpackWebError(message, long_message=None)[source]
Bases:
SpackErrorSuperclass for Spack web spidering errors.
- ramble.util.web.get_header(headers, header_name)[source]
Looks up a dict of headers for the given header value.
Looks up a dict of headers, [headers], for a header value given by [header_name]. Returns headers[header_name] if header_name is in headers. Otherwise, the first fuzzy match is returned, if any.
This fuzzy matching is performed by discarding word separators and capitalization, so that for example, “Content-length”, “content_length”, “conTENtLength”, etc., all match. In the case of multiple fuzzy-matches, the returned value is the “first” such match given the underlying mapping’s ordering, or unspecified if no such ordering is defined.
If header_name is not in headers, and no such fuzzy match exists, then a KeyError is raised.
- ramble.util.web.push_to_url(local_file_path, remote_path, keep_original=True, extra_args=None)[source]
ramble.util.yaml_generation module
Module representing utility functions for managing YAML configuration files within application definition files
These functions are intended to help read, write, and manipulate YAML based configuration files that an experiment might use as input.
Workload variables that represent configuration files should be defined using a ‘.’ delimiter between YAML object names. As an example:
foo:
bar:
baz: 1.0
Would translate to foo.bar.baz = 1.0 in Ramble syntax.
- ramble.util.yaml_generation.all_config_options(config_data: Dict)[source]
Extract all config options from config_data dictionary
- ramble.util.yaml_generation.apply_default_config_values(config_data, app_inst, default_config_string)[source]
Apply default config values (from config_data) to an experiment
Process all workloads variables (for the current workload in app_inst). Any variable who’s expanded value is equal to default_config_string will have its value overwritten to the value in the config_dict dictionary.
- ramble.util.yaml_generation.get_config_value(config_data: Dict, option_name: str)[source]
Get a config option based on dictionary attribute syntax
Given an option_name of the format: attr1.attr2.attr3 return its value from config_data.
- ramble.util.yaml_generation.read_config_file(conf_path: str)[source]
Read an existing YAML file and return its data as a dictionary
- ramble.util.yaml_generation.remove_config_value(config_data: Dict, option_name: str)[source]
Remove a config option based on dictionary attribute syntax
Given an option_name of the format: attr1.attr2.attr3 remote it from config_data. Also, remove any parent scopes that are empty.