SystemValues

class cubie.odesystems.SystemValues(values_dict: Mapping[str, float] | Sequence[str] | None, precision: type[float16] | type[float32] | type[float64] | dtype[float16] | dtype[float32] | dtype[float64], defaults: Mapping[str, float] | Sequence[str] | None = None, name: str | None = None, **kwargs: float)[source]

Bases: object

Manage keyed parameter values and their packed array representation.

Parameters:
  • values_dict (dict[str, float]) – Dictionary defining parameter values. Lists of parameter names are expanded to a dictionary with 0.0 defaults.

  • precision (type[numpy.float16] | type[numpy.float32] | type[numpy.float64] | numpy.dtype[numpy.float16] | numpy.dtype[numpy.float32] | numpy.dtype[numpy.float64]) – Precision factory applied when creating the packed values array.

  • defaults – Optional dictionary supplying baseline parameter values.

  • name (str | None) – Display label used in repr output.

  • **kwargs – Individual parameter overrides applied after defaults and values_dict.

Notes

Dictionary-style and array-style indexing both operate on the packed values_array and backing values_dict.

__init__(values_dict: Mapping[str, float] | Sequence[str] | None, precision: type[float16] | type[float32] | type[float64] | dtype[float16] | dtype[float32] | dtype[float64], defaults: Mapping[str, float] | Sequence[str] | None = None, name: str | None = None, **kwargs: float) None[source]

Initialise the packed values dictionary and array.

Parameters:
  • values_dict – Full parameter dictionary or iterable of parameter names. Names are expanded to 0.0 defaults before precision coercion.

  • precision – Precision used when materialising values_array.

  • defaults – Baseline parameter dictionary applied before values_dict.

  • name – Friendly identifier displayed by repr.

  • **kwargs – Parameter overrides applied after values_dict.

Notes

Keyword arguments replace identically named entries in values_dict and defaults.

_convert_symbol_keys(input_dict: Any) Any[source]

Return a dictionary whose keys are converted to strings.

Parameters:

input_dict – Dictionary potentially keyed by sympy.Symbol objects.

Returns:

Dictionary with symbol keys converted to strings, or the original input_dict if it is not a dictionary.

Return type:

Any

property empty: bool

Return True if this SystemValues instance has no values.

get_index_of_key(parameter_key: str, silent: bool = False) int[source]

Return the array index associated with a parameter name.

Parameters:
  • parameter_key – Parameter name to locate within indices_dict.

  • silent – When True missing keys do not trigger an exception.

Returns:

Index of parameter_key within values_array.

Return type:

int

Raises:
  • KeyError – Raised when parameter_key is not present and silent is False.

  • TypeError – Raised when parameter_key is not a string.

get_indices(keys_or_indices: str | int | slice | list[str | int] | ndarray, silent: bool = False) ndarray[source]

Convert parameter identifiers into packed array indices.

Parameters:
  • keys_or_indices – Parameter descriptors supplied as names, indices, slices, or sequences of either.

  • silent – When True missing keys do not trigger an exception.

Returns:

Array of np_int32 indices targeting values_array.

Return type:

numpy.ndarray

Raises:
  • KeyError – Raised when a requested name is missing and silent is False.

  • IndexError – Raised when an index is outside the valid range.

  • TypeError – Raised when the provided descriptors are of unsupported or mixed types.

get_labels(indices: list[int] | ndarray) list[str][source]

Return parameter labels for supplied indices.

Parameters:

indices – Integer indices referencing values_array.

Returns:

Labels corresponding to indices.

Return type:

list[str]

Raises:

TypeError – Raised when indices is not a sequence or array.

get_values(keys_or_indices: str | int | list[str | int] | ndarray) ndarray[source]

Return parameter values selected by name or index.

Parameters:

keys_or_indices – Parameter descriptors accepted by get_indices().

Returns:

Precision-coerced view of the requested parameter values.

Return type:

numpy.ndarray

Raises:
  • KeyError – Raised when a requested name is missing.

  • IndexError – Raised when an index is outside the valid range.

  • TypeError – Raised when the descriptors are of unsupported types.

indices_dict: dict[str, int] | None
keys_by_index: dict[int, str] | None
n: int
name: str | None
property names: list[str]

List of parameter names.

precision: type[float16] | type[float32] | type[float64] | dtype[float16] | dtype[float32] | dtype[float64]
set_values(keys: str | int | slice | list[str | int] | ndarray, values: float | Sequence[float] | ndarray) None[source]

Assign new values to the selected parameters.

Parameters:
  • keys – Parameter descriptors accepted by get_indices().

  • values – Replacement values aligned with keys.

Raises:

ValueError – Raised when the number of values does not match keys.

update_from_dict(values_dict: Mapping[str, float] | None, silent: bool = False, **kwargs: float) set[str][source]

Update stored parameter values from dictionaries.

Parameters:
  • values_dict – Dictionary of key-value pairs to apply.

  • silent – When True missing keys do not trigger an exception.

  • **kwargs – Additional key-value pairs to apply after values_dict.

Returns:

Keys successfully updated in the stored values.

Return type:

set[str]

Raises:
  • KeyError – Raised when a key is missing and silent is False.

  • TypeError – Raised when a value cannot be cast to precision.

update_param_array_and_indices() None[source]

Populate values_array and index mappings from values_dict.

Notes

The mapping order follows dictionary insertion so lookup indices stay aligned with values_array.

values_array: ndarray | None
values_dict: dict[str, float]