rizer.misc.check_utils#

Functions#

validate_positive(…)

Check if the value is a positive, finite, number.

validate_positive_optional(→ int | float | None)

Return None unchanged, otherwise validate_positive(name, value, allow_zero).

require_resistive_source(→ None)

Raise ValueError unless source_type is "resistive".

check_keys_in_dict(→ None)

Check if the required keys are present in the dictionary.

Module Contents#

rizer.misc.check_utils.validate_positive(name: str, value: _Number, allow_zero: bool = False) → _Number#
rizer.misc.check_utils.validate_positive(name: str, value, allow_zero: bool = False) → int | float

Check if the value is a positive, finite, number.

Parameters:
  • name (str) – Name of the variable for error messages.

  • value (int or float) – Value to check.

  • allow_zero (bool, optional) – Whether to allow zero as a valid value. Default is False.

Raises:
  • TypeError – Raised if the value is not a number.

  • ValueError – Raised if the value is not finite.

  • ValueError – Raised if the value is not positive.

rizer.misc.check_utils.validate_positive_optional(name: str, value, allow_zero: bool = False) → int | float | None#

Return None unchanged, otherwise validate_positive(name, value, allow_zero).

For a genuinely optional numeric input, where None means “not given” rather than a value to validate.

Parameters:
  • name (str) – Name of the variable for error messages.

  • value (int, float, or None) – Value to check, or None.

  • allow_zero (bool, optional) – Whether to allow zero as a valid value. Default is False.

Raises:
  • TypeError – Raised if value is neither None nor a number.

  • ValueError – Raised if value is not finite, or not positive.

rizer.misc.check_utils.require_resistive_source(source_type: str, field_name: str) → None#

Raise ValueError unless source_type is “resistive”.

Shared by every caller that only accepts a TransmissionLineResistiveCircuit/TransmissionLineRCLoadCircuit (e.g. PulsedPlasmaReactor), so a “c_shunt”/”c_parallel” source is rejected here rather than silently dropped.

Parameters:
  • source_type (str) – The source’s type (“resistive”, “c_shunt”, or “c_parallel”).

  • field_name (str) – The field name to report in the error message (e.g. “circuit config source_circuit.type”).

Raises:

ValueError – If source_type is not “resistive”.

rizer.misc.check_utils.check_keys_in_dict(d: dict, required_keys: list[str] | str, dict_name: str = '') → None#

Check if the required keys are present in the dictionary.

Parameters:
  • d (dict) – The dictionary to check.

  • required_keys (list of str or str) – The list of required keys or a single key as a string.

  • dict_name (str, optional) – A custom error message to include in the KeyError.

Raises:

KeyError – Raised if any of the required keys are missing from the dictionary.