Skip to content

ic

RL4CRN.utils.ic

Initial-condition (IC) helpers for CRN simulations.

This module provides a lightweight IC container that stores one or more sets of initial concentrations keyed by species names, and can project/reorder those initial conditions to match the species ordering of a given CRN.

Typical use:

  • Define ICs in a human-friendly order (by name).
  • Call get_ic(crn) to obtain NumPy vectors aligned with crn.species_labels, ready to be passed to simulation / transient-response routines.

IC

Container for named initial conditions for CRN species.

The object stores one or multiple initial-condition vectors defined over a fixed list of species names. When used with a CRN instance, it can reorder each vector to match the CRN's internal species_labels ordering.

PARAMETER DESCRIPTION
names

Species names corresponding to the entries in each IC vector.

TYPE: list[str]

values

One or more IC vectors. Each vector must have length len(names) and is interpreted as concentrations aligned with names.

TYPE: list[array - like]

ATTRIBUTE DESCRIPTION
names

Species names used as the IC coordinate system.

TYPE: list[str]

values

Stored IC vectors aligned with names.

TYPE: list[array - like]

name_to_index

Map from species name to its index in names.

TYPE: dict[str, int]

index_to_name

Alias for names (kept for convenience).

TYPE: list[str]

__init__(names, values)

Initialize an IC container.

PARAMETER DESCRIPTION
names

Species names.

TYPE: list[str]

values

One or more initial condition vectors aligned with names.

TYPE: list[array - like]

get_ic(crn)

Reorder stored IC vectors to match a CRN's species ordering.

The CRN is expected to expose crn.species_labels (list[str]). For each stored IC vector, this method produces a NumPy array whose entries are ordered exactly as crn.species_labels.

PARAMETER DESCRIPTION
crn

CRN-like object with attribute species_labels (list[str]).

RETURNS DESCRIPTION

list[np.ndarray]: List of IC arrays, one per entry in self.values,

each of shape (len(crn.species_labels),).

RAISES DESCRIPTION
ValueError

If the CRN contains a species label that is not present in self.names.

__str__()

Return a readable string representation of the IC container.