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]
Methods:¶
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_catalogue
¶
save_catalogue(output_path: str | Path, *, data: Mapping[str, Array] | None = None, provenance: Mapping[str, Any] | None = None, compression: str | None = None) -> None
Persist a simulated population as a named-column catalogue.
Persistence goes through :func:~gwmock_pop.loaders.write_population_catalogue,
the one writer in this package, so a file written here is one the
package's own readers accept and it carries the same provenance record
as a file written by the CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str | Path
|
Destination |
required |
data
|
Mapping[str, Array] | None
|
Population to write. Defaults to the last simulated population. |
None
|
provenance
|
Mapping[str, Any] | None
|
Record to store with the catalogue. Defaults to the one this simulator can describe itself with. |
None
|
compression
|
str | None
|
Optional HDF5 compression filter. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no population is given and none has been simulated. |
TypeError
|
If the population is not a mapping of named columns. |
build_provenance_record
¶
build_provenance_record(*, n_samples: int, file_format: str, parameter_names: Sequence[str] | None = None, run: Mapping[str, Any] | None = None, writer: str | None = None) -> dict[str, Any]
Build the provenance record describing a catalogue from this simulator.
This is the single record builder behind both persistence paths: the CLI
calls it with the run settings it resolved, and :meth:save_catalogue
calls it with what the simulator knows about itself. Neither assembles a
record of its own, so the two cannot drift apart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_samples
|
int
|
Number of rows being written. |
required |
file_format
|
str
|
Format the catalogue is written in. |
required |
parameter_names
|
Sequence[str] | None
|
Column names in output order. Defaults to this simulator's parameter names. |
None
|
run
|
Mapping[str, Any] | None
|
Block from :func: |
None
|
writer
|
str | None
|
Import path of the code writing the file. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The record. |