Skip to content

Simulator Base

simulator

Base class of the simulators.

Classes

Simulator

Simulator(*args: object, **kwargs: object)

Bases: ABC

Abstract base class for generating simulated populations.

Initialize the instance.

Parameters:

Name Type Description Default
*args object

Positional arguments.

()
**kwargs object

Keyword arguments.

{}
Attributes
parameter_names abstractmethod property
parameter_names: list[str]

Get the names of the parameters.

Returns:

Type Description
list[str]

List of parameter names.

Functions
register_node
register_node(name: str, func: Callable, depends_on: list[str] | None = None) -> None

Register a node function on this instance.

Parameters:

Name Type Description Default
name str

Parameter name.

required
func Callable

A function to simulate this parameter.

required
depends_on list[str] | None

A list of dependent parameters.

None
node
node(depends_on: list[str] | None = None) -> Callable

Implement a decorator to bind a node to this instance.

Parameters:

Name Type Description Default
depends_on list[str] | None

A list of dependencies.

None

Returns:

Type Description
Callable

A callable.

simulate
simulate(*args: object, **kwargs: object) -> Mapping[str, Array]

Simulate a population of sources.

Parameters:

Name Type Description Default
*args object

Positional arguments.

()
**kwargs object

Keyword arguments.

{}

Returns:

Type Description
Mapping[str, Array]

Mapping from parameter names to 1D arrays of length n_samples.

save
save(output_path: str | Path, file_format: str | None = None, data: Mapping[str, Array] | Array | None = None, compression: str | None = None, metadata: dict[str, Any] | None = None) -> None

Save the simulated data to a file.

Parameters:

Name Type Description Default
output_path str | Path

Path to save the file.

required
file_format str | None

File format (npy, npz, csv, hdf5). If None, infers from extension.

None
data Mapping[str, Array] | Array | None

Data to save. If None, uses last simulated data. Mapping inputs are converted to a 2D array with columns ordered by parameter_names.

None
compression str | None

Optional compression setting for supported formats. For HDF5, this specifies the compression filter (e.g., "gzip"). For NPZ, any non-None value enables default zlib compression.

None
metadata dict[str, Any] | None

Optional metadata to store alongside the samples.

None
load
load(input_path: str | Path) -> Array

Load data from a file.

Parameters:

Name Type Description Default
input_path str | Path

Path to load the file from.

required

Returns:

Type Description
Array

Loaded data as numpy array.