utils.py - DPRS
Author: Colin P. Stark
Description: Directed percolation and related models implemented in Rust and wrapped in Python.

Skip to content

# utils.py

# `` Parameters `dataclass`

    Parameters(
        dim: D1,
        n_x: int,
        n_y: int,
        n_z: int,
        p: float,
        p0: float,
        seed: int,
        n_iterations: int,
        sample_rate: int,
        axis_topology_x: Topology,
        axis_topology_y: Topology,
        axis_topology_z: Topology,
        axis_bcs_x: tuple[BoundaryCondition, BoundaryCondition],
        axis_bcs_y: tuple[BoundaryCondition, BoundaryCondition],
        axis_bcs_z: tuple[BoundaryCondition, BoundaryCondition],
        axis_bc_values_x: tuple[bool, bool],
        axis_bc_values_y: tuple[bool, bool],
        axis_bc_values_z: tuple[bool, bool],
        do_edge_buffering: bool,
        processing: Processing,
        n_threads: int,
    )

Dummy declaration: shadows definition in Rust.

Used by:

- Python modules
  - `` make_name
  - `` make_title

# `` make_name

    make_name(parameters: Parameters, variable: str, i_slice: int | None = None)

Generate a string summarizing the sim for file naming.

Source code in `python/dprs/utils.py`

    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    def make_name(parameters: Parameters, variable: str, i_slice: int|None = None):
        """Generate a string summarizing the sim for file naming."""
        return (
              f"{variable}"
            + f"_p{parameters.p:0.6f}".replace(".", "p")
            + f"_s{parameters.seed}"
            + f"_nx{parameters.n_x}"
            + (
                f"_ny{parameters.n_y}" if parameters.n_y>1
                else ""
            )
            + (
                f"_nz{parameters.n_z}" if parameters.n_z>1
                else ""
            )
            + (f"_i{i_slice*parameters.sample_rate:0{5}}"
               if i_slice is not None else "")
        )

# `` make_title

    make_title(parameters: Parameters, i_slice: int | None = None)

Generate a string summarizing the sim for entitling plots.

Source code in `python/dprs/utils.py`

    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    def make_title(parameters: Parameters, i_slice: int|None = None):
        """Generate a string summarizing the sim for entitling plots."""
        return (
            rf"$p={parameters.p:0.6f}$"
            + rf"   $s={parameters.seed}$"
            + rf"   $n_x={parameters.n_x}$"
            + (
                rf"   $n_y={parameters.n_y}$" if parameters.n_y>1
               else ""
            )
            + (
                rf"   $n_z={parameters.n_z}$" if parameters.n_z>1
               else ""
            )
            + (rf"   $i={i_slice*parameters.sample_rate:0{5}}$"
               if i_slice is not None else "")
        )