autoemulate.simulations.base#

class Simulator(parameters_range, output_names, log_level='progress_bar')[source]#

Bases: ABC, ValidationMixin

Base class for simulations. All simulators should inherit from this class.

This class provides the interface and common functionality for different simulation implementations.

classmethod simulator_name()[source]#

Get the name of the simulator class.

property parameters_range#

Dictionary mapping input parameter names to their (min, max) ranges.

property param_names#

List of parameter names.

property param_bounds#

List of parameter bounds.

property output_names#

List of output parameter names.

property in_dim#

Input dimensionality.

property out_dim#

Output dimensionality.

sample_inputs(n_samples, random_seed=None, method='lhs')[source]#

Generate random samples using Quasi-Monte Carlo methods.

Available methods are Sobol or Latin Hypercube Sampling. For overview, see the scipy documentation: https://docs.scipy.org/doc/scipy/reference/stats.qmc.html

Parameters:
  • n_samples (int) – Number of samples to generate.

  • random_seed (int | None) – Random seed for reproducibility. If None, no seed is set.

  • method (str) – Sampling method to use. One of [“lhs”, “sobol”].

Returns:

Parameter samples (column order is given by self.param_names)

Return type:

TensorLike

forward(x, allow_failures=True)[source]#

Generate samples from input data using the simulator.

Combines the abstract method _forward with some validation checks. If there is a failure during the forward pass of the simulation, the error is logged and None is returned.

Parameters:
  • x (TensorLike) – Input tensor of shape (n_samples, self.in_dim).

  • allow_failures (bool) – Whether to allow failures during simulation. Default is True. When true, failed simulations will return None instead of raising an error. When False, error is raised.

Returns:

Simulated output tensor. None if the simulation failed.

Return type:

TensorLike

forward_batch(x, allow_failures=True)[source]#

Run multiple simulations.

If allow_failures is False, failed simulations will raise an error. Otherwise, failed simulations are skipped, and only successful results are returned along with their corresponding input parameters.

Parameters:
  • x (TensorLike) – Tensor of input parameters to make predictions for.

  • allow_failures (bool) – Whether to allow failures during simulation. Default is True. When true, failed simulations will return None instead of raising an error. When False, error is raised.

Returns:

Tuple of (simulation_results, valid_input_parameters). Only successful simulations are included.

Return type:

tuple[TensorLike, TensorLike]

get_parameter_idx(name)[source]#

Get the index of a specific parameter.

Parameters:

name (str) – Name of the parameter to retrieve.

Returns:

Index of the specified parameter.

Return type:

float

get_outputs_as_dict()[source]#

Return simulation results as a dictionary with output names as keys.

Returns:

Dictionary where keys are output names and values are tensors of shape (n_samples,) for each output dimension.

Return type:

dict[str, TensorLike]