src.pydasa.workflows.practical#

Module for MonteCarloSimulation to manage the Monte Carlo experiments in PyDASA.

This module provides classes for managing Monte Carlo simulations of the dimensionless coefficients.

Classes:

MonteCarloSimulation: Manages Monte Carlo simulation runs, including configuration and execution of the experiments.

IMPORTANT: Based on the theory from:

# H.Gorter, Dimensionalanalyse: Eine Theoririe der physikalischen Dimensionen mit Anwendungen

Classes#

MonteCarloSimulation

MonteCarloSimulation class for managing Monte Carlo simulations in PyDASA.

Module Contents#

class src.pydasa.workflows.practical.MonteCarloSimulation#

Bases: pydasa.core.basic.Foundation, pydasa.workflows.basic.WorkflowBase

MonteCarloSimulation class for managing Monte Carlo simulations in PyDASA.

Manages the creation, configuration, and execution of Monte Carlo simulations of dimensionless coefficients.

Parameters:
  • Foundation (Foundation) – Inherits common validation logic.

  • WorkflowBase (WorkflowBase) – Inherits workflow basic functionalities.

# From Foundation

_name (str): User-friendly name of the Monte Carlo simulation handler. description (str): Brief summary of the Monte Carlo simulation handler. _idx (int): Index/precedence of the simulation handler. _sym (str): Symbol representation (LaTeX or alphanumeric). _alias (str): Python-compatible alias for use in code. _fwk (str): Frameworks context (PHYSICAL, COMPUTATION, SOFTWARE, CUSTOM).

Type:

Identification and Classification

# From WorkflowBase

_variables (Dict[str, Variable]): All available parameters/variables in the model (Variable). Accepts Variable instances or dicts. _schema (Optional[Schema]): Dimensional framework schema for the workflow. After __post_init__, this will always be a Schema instance (inherited but not actively used in MonteCarloSimulation). _coefficients (Dict[str, Coefficient]): All available coefficients in the model (Coefficient). Accepts Coefficient instances or dicts. _results (Dict[str, Dict[str, Any]]): Consolidated results from Monte Carlo simulations. _is_solved (bool): Flag indicating if the simulation workflow has been completed.

Type:

Common Workflow Components

# Specific to MonteCarloSimulation

_cat (str): Category of simulation run (DIST, DATA). _distributions (Dict[str, Dict[str, Any]]): All distribution functions used in the simulations (specific name, parameters, and function). _experiments (int): Number of simulations to run. Default is -1. _simulations (Dict[str, MonteCarlo]): All Monte Carlo simulations performed for each coefficient. _shared_cache (Dict[str, NDArray[np.float64]]): In-memory cache for simulation data shared between coefficients.

__post_init__()#

__post_init__() Initializes the Monte Carlo handler.

Return type:

None

configure_distributions()#

configure_distributions() Set up distribution specs (type, params, functions) for all variables.

Raises:
  • ValueError – If variables are not defined.

  • ValueError – If distribution specifications are invalid.

Return type:

None

configure_simulations()#

configure_simulations() Create MonteCarlo objects for each coefficient with distributions and dependencies.

Raises:
  • ValueError – If distributions are not configured.

  • ValueError – If coefficients or variables are not defined.

  • ValueError – If coefficient variables are invalid.

  • RuntimeError – If simulation creation fails for a coefficient.

Return type:

None

create_simulations()#

create_simulations() Convenience method to configure distributions and simulations in sequence.

Return type:

None

run_simulation(iters=None, mode=None)#

run_simulation() Configure and execute Monte Carlo simulations for all coefficients.

Parameters:
  • iters (Optional[int], optional) – Number of iterations (experiments) to run. If None, uses self._experiments value. Defaults to None.

  • mode (Optional[str], optional) – Simulation mode to set before running. If None, uses existing self._cat value. Defaults to None.

Raises:
  • ValueError – If simulations are not configured.

  • ValueError – If a required simulation is not found.

  • ValueError – If the number of experiments is not positive.

  • RuntimeError – If a simulation fails during execution.

Return type:

None

get_simulation(name)#

get_simulation() Get a simulation by name.

Parameters:

name (str) – Name of the simulation.

Returns:

The requested simulation.

Return type:

MonteCarlo

Raises:

ValueError – If the simulation doesn’t exist.

get_distribution(name)#

get_distribution() Get the distribution by name.

Parameters:

name (str) – Name of the distribution.

Returns:

The requested distribution.

Return type:

Dict[str, Any]

Raises:

ValueError – If the distribution doesn’t exist.

get_results(name)#

get_results() Get the results of a simulation by name.

Parameters:

name (str) – Name of the simulation.

Returns:

The results of the requested simulation.

Return type:

Dict[str, Any]

Raises:

ValueError – If the results for the simulation don’t exist.

property cat: str#

cat Get the Monte Carlo Simulation category.

Returns:

Category (DIST, DATA).

Return type:

str

property experiments: int#

experiments Get the number of experiments.

Returns:

Number of experiments to run.

Return type:

int

property simulations: Dict[str, pydasa.analysis.simulation.MonteCarlo]#

simulations Get the dictionary of Monte Carlo simulations.

Returns:

Dictionary of Monte Carlo simulations.

Return type:

Dict[str, MonteCarlo]

property is_configured: bool#

is_configured Check if simulations are configured and ready to run.

Returns:

True if both distributions and simulations are configured.

Return type:

bool

property has_results: bool#

has_results Check if simulation results are available.

Returns:

True if simulations have been run and results exist.

Return type:

bool

reset()#

reset() Reset simulation state while preserving input configuration.

Clears results, solved state, and simulation-specific attributes (simulations, distributions, cache) while keeping variables, schema, and coefficients.

Return type:

None

clear()#

clear() Clear all attributes to default values.

Resets all simulation properties to their initial state, including variables, coefficients, and results from WorkflowBase.

Return type:

None

to_dict()#

to_dict() Convert the handler’s state to a dictionary.

Returns:

Dictionary representation of the handler’s state.

Return type:

Dict[str, Any]

classmethod from_dict(data)#

from_dict() Create a MonteCarloSimulation instance from a dictionary.

Parameters:

data (Dict[str, Any]) – Dictionary containing the handler’s state.

Returns:

New instance of MonteCarloSimulation.

Return type:

MonteCarloSimulation