autoemulate.simulations.base#
- class Simulator(parameters_range, output_names, log_level='progress_bar')[source]#
Bases:
ABC,ValidationMixinBase class for simulations. All simulators should inherit from this class.
This class provides the interface and common functionality for different simulation implementations.
- 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:
- 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]
- class TorchSimulator(parameters_range, output_names, log_level='progress_bar', device=None)[source]#
Bases:
Simulator,TorchDeviceMixinSimulator that runs computations on a specified torch device.
This subclass extends
Simulatorwith theTorchDeviceMixinso that simulators implemented in PyTorch (e.g.,torchcor) can run on CPU or accelerator hardware. Inputs are moved toself.devicebefore the forward pass and the resulting tensors are kept on the same device.- sample_inputs(n_samples, random_seed=None, method='lhs')[source]#
Sample inputs and move them to the simulator’s device.
- forward(x, allow_failures=True)[source]#
Run a single simulation on the configured device.
- Parameters:
x (TensorLike) – Input tensor with shape
(n_samples, in_dim).allow_failures (bool) – When True, failures return
Noneinstead of raising.
- Returns:
Simulation result on
self.deviceorNoneon failure.- Return type:
TensorLike | None