Graph Simulator
graph
¶
Graph-based population simulator.
Classes¶
GraphSimulator
¶
GraphSimulator(config: dict[str, Any], source_type: str | None = None, **kwargs: Any)
Bases: RandomMixin, Simulator
Graph-based population simulator.
This simulator uses a probabilistic graphical model to generate populations. Parameters are defined in a configuration with dependencies, and the simulator executes sampling in topological order based on the dependency graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
Configuration dictionary defining parameters and their sampling/transform rules. |
required |
**kwargs
|
Any
|
Additional arguments passed to parent class. |
{}
|
Note
source_type must be set before calling simulate(). Construction
without source_type is allowed (e.g. for builder patterns), but
simulate() raises :exc:ValueError if source_type is None
at call time. Pass source_type=<str> to the constructor to avoid
this.
Example
config = { ... "mass_1": { ... "sampler": { ... "function": "planck_tapered_broken_power_law_plus_two_peaks", ... "arguments": { ... "alpha_1": 1.72, ... "alpha_2": 4.51, ... "transition": 35.6, ... "minimum": 5.06, ... "maximum": 300.0, ... }, ... }, ... }, ... "mass_ratio": { ... "sampler": { ... "function": "planck_tapered_conditional_ratio_power_law", ... "arguments": {"denominator": "@mass_1"}, ... }, ... }, ... } simulator = GraphSimulator(config=config) population = simulator()
Initialize the graph-based simulator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
Configuration dictionary with parameter definitions. |
required |
source_type
|
str | None
|
Logical source identifier for higher-level orchestration. |
None
|
**kwargs
|
Any
|
Additional arguments passed to parent class. |
{}
|
Attributes¶
parameter_names
property
¶
parameter_names: list[str]
source_type
property
¶
source_type: str
rng_manager
property
¶
rng_manager: RNGManager
rng_key_data
property
¶
rng_key_data: Array
Get the key data of the random number generator.
Returns:
| Type | Description |
|---|---|
Array
|
Key data of the random number generator. |
Functions¶
from_config_file
classmethod
¶
from_config_file(config_path: str | Path, encoding: str = 'utf-8', **kwargs: Any) -> GraphSimulator
Create simulator from configuration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path
|
Path to YAML/TOML configuration file. |
required |
encoding
|
str
|
Encoding of the file. |
'utf-8'
|
**kwargs
|
Any
|
Additional arguments passed to init. |
{}
|
Returns:
| Type | Description |
|---|---|
GraphSimulator
|
Configured simulator instance. |
register_node
¶
register_node(name: str, func: Callable, depends_on: list[str] | None = None) -> None
node
¶
node(depends_on: list[str] | None = None) -> Callable
simulate
¶
simulate(*args: object, **kwargs: object) -> Mapping[str, Array]
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
|
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
|