Base class

melissa.server.sensitivity_analysis.sensitivity_analysis_server

SensitivityAnalysisServer

Bases: BaseServer

SensitivityAnalysisServer class extends the BaseServer class and provides specialized functionalities for sensitivity analysis. The primary tasks of this class include:

  • Generating parameters and scripts using pick-freeze sampling.
  • Calculating statistical moments with the IterativeSensitivityMartinez method.
  • Overriding or redefining abstract methods.
Parameters
  • config_dict (Dict[str, Any]): A dictionary containing configuration settings for initializing the sensitivity analysis server.
Attributes
  • sobol_op (bool): Indicates if Sobol sensitivity analysis is enabled.
  • second_order (bool): Flag to activate second order for parameter sampling during pick-freeze.
  • __mean (bool): Flag for computing the mean as part of the statistical analysis.
  • __variance (bool): Flag for computing the variance as part of the statistical analysis.
  • __skewness (bool): Flag for computing the skewness as part of the statistical analysis.
  • __kurtosis (bool): Flag for computing the kurtosis as part of the statistical analysis.
  • __seen_ranks (Set[int]): Set of ranks corresponding to clients that have been processed.
  • __checkpoint_count (int): Counter for the number of checkpoints performed.
  • __checkpoint_interval (int): Interval at which checkpoints are taken, specified in the configuration.
  • __max_order (int): The maximum statistical moment order to compute (For example, mean = 1, variance = 2, etc.).
  • __melissa_moments (Dict[tuple, IterativeMoments]): Dictionary to store statistical moments for each field, rank, and time step.
  • __pick_freeze_matrix (List[List[Union[int, float]]]): Matrix to freeze parameters for Sobol computations(used if Sobol analysis is enabled).
  • __melissa_sobol (Dict[tuple, IterativeSensitivityMartinez]): Dictionary to store Sobol sensitivity indices for each field, rank, and time step, if enabled.

__unimplemented_stats(sa_config)

No implementation available for the following yet.

_check_group_size()

Based on sobol, validates the given group size, and updates the number of clients.

__draw_from_pick_freeze()

Retrieves a single row from the pick-freeze matrix and builds it, if empty.

Returns
  • List: A list representing a single row of parameters.

__build_pick_freeze_matrix()

Builds the pick-freeze matrix for one group.

_get_next_parameters()

Retrieves the next parameters for, - Group: if sobol_op is active, it uses the pick-freeze matrix. - Client: it retrieves parameters from the parent implementation.

Returns
  • List: A row of parameters.

_receive()

Handles data from the server.

_server_online()

Steps to perform while the server is online.

_server_offline()

Optional. Post processing steps.

start()

The main entrypoint for the server events.

__get_cached_sobol_data(pdata)

Caches time steps received from each simulation in a group for Sobol sampling.

Parameters
  • pdata (PartialSimulationData): The data message received from the simulation.
Returns
  • Union[bool, Optional[NDArray]]:
    • NDArray if all timesteps for a specific group are available.
    • False otherwise.

_compute_stats(pdata)

Computes statistics iteratively and Sobol sensitivity indices, if sobol_op is set. - Initializes IterativeMoments and IterativeSensitivityMartinez objects per new combination of field, client rank, and time step. - Handles Sobol calculations by caching received data for a specific group.

Parameters
  • pdata (PartialSimulationData): The data message received from the simulation.

__gather_data(local_vect_sizes, d_buffer)

Gathers data from all ranks to rank 0 using MPI's Gatherv function.

Parameters:
  • local_vect_sizes (NDArray[np.int32]): An array containing the size of the data vector per rank.
  • d_buffer (NDArray[np.float64]): An array containing the local data to be gathered.
Returns:
  • NDArray[np.float64]: An array with the gathered data at rank 0.

__gather_and_write_moments(field, global_vect_size, local_vect_sizes, stat_type, values_fn)

Gathers data from all ranks based on the specified statistical type, and writes the results.

Parameters:
  • field (str): The field for which the data is to be gathered.
  • global_vect_size (int): The size of the global vector.
  • local_vect_sizes (NDArray[np.int32]): An array containing the size of the data vector per rank.
  • stat_type (str): A string specifying the type of statistics to gather (called per moment. For example, mean).
  • values_fn (Callable): A function that takes __melissa_moments object which calls get_stat_type() already defined. (called per moment. For example, lambda m: m.get_mean()).

__gather_and_write_sobol(field, global_vect_size, local_vect_sizes)

Gathers sobol data from all ranks, and writes the results.

Parameters:
  • field (str): The field for which the data is to be gathered.
  • global_vect_size (int): The size of the global vector.
  • local_vect_sizes (NDArray[np.int32]): An array containing the size of the data vector per rank.

_melissa_write_stats()

Gathers and writes all results to results/ folder.

checkpoint_state()

Checkpoint moments and sobol information.

_restart_from_checkpoint()

Loads from the last checkpoint, in case of a restart.

Others

melissa.server.sensitivity_analysis.sensitivity_analysis_server

FieldMetadata

A class to store and manage metadata for a field.

Parameters
  • size (int): The number of local vectors i.e client ranks.
Attributes
  • local_vect_sizes (NDArray): An array containing the local vector sizes for each process.
  • global_vect_size (int): The total global vector size, calculated as the sum.

compute_global_size()

Computes the global vector size by summing.