piglot.utils package
Submodules
piglot.utils.assorted module
Assorted utilities.
- change_cwd(path: str)[source]
Context manager to temporarily change the current working directory.
Adapted from https://stackoverflow.com/a/75049063
Parameters
- pathstr
New working directory.
- filter_close_points(data: ndarray, tol: float) ndarray[source]
Remove points from an array that are too close to each other.
Parameters
- datanp.ndarray
Data array.
- tolfloat
Tolerance to use during removal.
Returns
- np.ndarray
Reduced array.
- pretty_time(elapsed_sec: float) str[source]
Return a human-readable representation of a given elapsed time
Parameters
- elapsed_secfloat
Elapsed time, in seconds
Returns
- str
Pretty elapsed time string
- read_custom_module(config: Dict[str, Any], cls: Type[T]) Type[T][source]
Read a custom module from a configuration spec.
Parameters
- configDict[str, Any]
Configuration of the custom module.
- clsType
Base class of the module to load.
Returns
- Type
Custom module type read from the script.
- reverse_pretty_time(time_str: str) float[source]
Return an elapsed time from its human-readable representation
Parameters
- time_strstr
Pretty elapsed time string
Returns
- str
Elapsed time, in seconds
- stats_interp_to_common_grid(responses: List[Tuple[ndarray, ndarray]]) Dict[str, ndarray][source]
Interpolate a set of response to a common grid and compute several statistics.
Parameters
- responsesList[Tuple[np.ndarray, np.ndarray]]
List of responses to interpolate.
Returns
- Dict[str, np.ndarray]
Results for the interpolated responses.
piglot.utils.responses module
Module for reducing the number of points in a response function
- class ResamplingLoss(ref_x: ndarray, ref_y: ndarray, n_points: int)[source]
Bases:
objectLoss for resampling a response function
- errors_interps(x_new: ndarray, y_new: ndarray, x_ref: ndarray, y_ref: ndarray) ndarray[source]
Compute the error associated with removing each point from the grid
Parameters
- x_newnp.ndarray
New time grid
- y_newnp.ndarray
Values on the new grid
- x_refnp.ndarray
Old time grid
- y_refnp.ndarray
Values on the old grid
Returns
- np.ndarray
Error associated with removing each point
- interpolate_response(x_resp: ndarray, y_resp: ndarray, x_grid: ndarray) ndarray[source]
Interpolate a response function.
Parameters
- x_respnp.ndarray
Original time grid.
- y_respnp.ndarray
Values in the original grid.
- x_gridnp.ndarray
New time grid.
Returns
- np.ndarray
Values on the new grid.
- reduce_response(x_old: ndarray, y_old: ndarray, tol: float) Tuple[int, float, Tuple[ndarray, ndarray]][source]
Reduce the number of points in a response function
Parameters
- x_oldnp.ndarray
Original time grid
- y_oldnp.ndarray
Values in the original grid
- tolfloat
Maximum acceptable error
Returns
- Tuple[int, float, Tuple[np.ndarray, np.ndarray]]
Number of points, error, and new grid
piglot.utils.solver_utils module
Utilities for the solver module.
- class VerbosityManager(verbosity: str | None, output_dir: str)[source]
Bases:
objectClass to manage output streams based on verbosity levels.
- AVAILABLE_VERBOSITIES = ['none', 'file', 'error', 'all']
- DEFAULT_VERBOSITY = 'none'
- extract_parameters(input_file: str) ParameterSet[source]
Extract a ParameterSet from an input file.
Parameters
- input_filestr
Input file path.
Returns
- ParameterSet
Set of parameters discovered in the input file.
Raises
- RuntimeError
When a repeated pattern is found.
- RuntimeError
When a pattern is referenced but never defined.
- find_keyword(file: str, keyword: str) str[source]
Finds the first line where a keyword is defined.
Parameters
- filestr
Path for the input file.
- keywordstr
Keyword to locate.
Returns
- str
Line containing the keyword.
Raises
- RuntimeError
If the keyword is not found.
- get_case_name(input_file: str) str[source]
Extracts the name of a given case.
Parameters
- input_filestr
Path for the input file.
Returns
- str
Name of the case.
- has_keyword(input_file: str, keyword: str) bool[source]
Checks whether an input file contains a given keyword.
Parameters
- input_filestr
Path for the input file.
- keywordstr
Keyword to locate.
Returns
- bool
Whether the input file contains the keyword or not.
piglot.utils.surrogate module
Module for surrogate models.
- get_model(x_data: ndarray, y_data: ndarray, var_data: ndarray | None = None, noisy: bool = False) SingleTaskGP[source]
Get a GP regression model for the current data.
Parameters
- x_datanp.ndarray
Input features.
- y_datanp.ndarray
Output outcomes.
- var_datanp.ndarray, optional
Observation variance, by default None
- noisybool, optional
Whether to use a noise-infering GPs or fixed noise ones, by default False
Returns
- SingleTaskGP
GP regression model.
piglot.utils.yaml_parser module
Module for parsing the YAML configuration file.
- class UniqueKeyLoader(stream)[source]
Bases:
SafeLoaderYAML loader that checks for duplicate keys in mappings.
Adapted from https://gist.github.com/pypt/94d747fe5180851196eb.
Module contents
Module with various utility functions and classes.