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)[source]#

Generate random samples using Latin Hypercube Sampling.

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

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

Returns:

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

Return type:

TensorLike

forward(x)[source]#

Generate samples from input data using the simulator.

Combines the abstract method _forward with some validation checks.

Parameters:

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

Returns:

Simulated output tensor. None if the simulation failed.

Return type:

TensorLike

forward_batch(x)[source]#

Run multiple simulations with different parameters.

For infallible simulators that always succeed. If your simulator might fail, use forward_batch_skip_failures() instead.

Parameters:

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

Returns:

Tensor of simulation results of shape (n_batch, self.out_dim).

Return type:

TensorLike

Raises:

RuntimeError – If the number of simulations does not match the input. Use forward_batch_skip_failures() to handle failures.

forward_batch_skip_failures(x)[source]#

Run multiple simulations, skipping any that fail.

For simulators where for some inputs the simulation can fail. 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.

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