Skip to content

Consistency Checks

NetworkConsistencyMixin


              flowchart TD
              pypsa.Network[NetworkConsistencyMixin]
              pypsa.network.abstract._NetworkABC[_NetworkABC]

                              pypsa.network.abstract._NetworkABC --> pypsa.Network
                


              click pypsa.Network href "" "pypsa.Network"
              click pypsa.network.abstract._NetworkABC href "" "pypsa.network.abstract._NetworkABC"
            

Mixin class for network consistency checks.

Class inherits to pypsa.Network. All attributes and methods can be used within any Network instance.

Methods:

pypsa.Network.consistency_check

consistency_check(check_dtypes: bool = False, strict: Sequence | None = None) -> None

Check network for consistency.

v0.7.0

Runs a series of checks on the network to ensure that it is consistent, e.g. that all components are connected to existing buses and that no impedances are singular.

Parameters:

  • check_dtypes (bool, default: False ) –

    If True, check the dtypes of the attributes in the components.

  • strict (list, default: None ) –

    If some checks should raise an error instead of logging a warning, pass a list of strings with the names of the checks to be strict about. If 'all' is passed, all checks will be strict. By default, 'dispatch_delays' is always strict.

Raises:

  • ConsistencyError

    If any of the checks fail and strict mode is activated.

pypsa.Network.consistency_check_plots

consistency_check_plots(strict: Sequence | None = None) -> None

Check network for consistency for plotting functions.

v0.34.0

Parameters:

  • strict (list, default: None ) –

    If some checks should raise an error instead of logging a warning, pass a list of strings with the names of the checks to be strict about. If 'all' is passed, all checks will be strict. The default is no strict checks.

Raises:

  • ConsistencyError

    If any of the checks fail and strict mode is activated.

See Also

pypsa.Network.consistency_check, pypsa.consistency.check_for_unknown_buses, pypsa.consistency.check_for_unknown_carriers

pypsa.Network.sanitize

sanitize() -> None

Sanitize the network to ensure data integrity.

v1.1.0

This method performs a set of operations to heal the networks data integrity. For a full list of operations which are done, check the See Also section below.

See Also

pypsa.components.Buses.add_missing_buses, pypsa.components.Carriers.add_missing_carriers, pypsa.components.Carriers.assign_colors

Specific checks

Consistency check functions for PyPSA networks.

Mainly used in the Network.consistency_check() method.

Functions:

pypsa.consistency.check_big_m_exceeded

check_big_m_exceeded(n: Network, strict: bool = False) -> None

Check if optimized capacities exceed big-M bounds for committable extendables.

For committable+extendable components, the big-M formulation uses p_nom_max as an upper bound. If the optimized capacity exceeds this bound, the unit commitment constraints may not be binding correctly.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_cost_consistency

check_cost_consistency(component: Components, strict: bool = False) -> None

Check if both overnight_cost and capital_cost are set for the same asset.

When both are specified, overnight_cost takes precedence and capital_cost is ignored.

Activate strict mode in general consistency check by passing ['cost_consistency'] to the strict argument.

Parameters:

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_dispatch_delays

check_dispatch_delays(n: NetworkType, component: Components, strict: bool = False) -> None

Check that delay attributes are valid for Link and Process components.

Validates that delay values are non-negative and do not exceed the number of snapshots in the optimization horizon.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_dtypes_

check_dtypes_(component: Components, strict: bool = False) -> None

Check if the dtypes of the attributes in the component are as expected.

Activate strict mode in general consistency check by passing ['dtypes'] to the strict argument.

Parameters:

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_for_disconnected_buses

check_for_disconnected_buses(n: NetworkType, strict: bool = False) -> None

Check if network has buses that are not connected to any component.

Activate strict mode in general consistency check by passing ['disconnected_buses'] the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_for_missing_carrier_colors

check_for_missing_carrier_colors(n: Network, strict: bool = False) -> None

Check if carriers are missing colors.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check, pypsa.Network.sanitize

pypsa.consistency.check_for_unknown_buses

check_for_unknown_buses(n: NetworkType, component: Components, strict: bool = False) -> None

Check if buses are attached to component but are not defined in the network.

Activate strict mode in general consistency check by passing ['unknown_buses'] to the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check, pypsa.Network.sanitize

pypsa.consistency.check_for_unknown_carriers

check_for_unknown_carriers(n: NetworkType, component: Components, strict: bool = False) -> None

Check if carriers are attached to component but are not defined in the network.

Activate strict mode in general consistency check by passing ['unknown_carriers'] the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check, pypsa.Network.sanitize

pypsa.consistency.check_for_zero_impedances

check_for_zero_impedances(n: NetworkType, component: Components, strict: bool = False) -> None

Check if component has zero impedances. Only checks passive branch components.

Activate strict mode in general consistency check by passing ['zero_impedances'] the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_for_zero_s_nom

check_for_zero_s_nom(component: Components, strict: bool = False) -> None

Check if component has zero s_nom. Only checks transformers.

Activate strict mode in general consistency check by passing ['zero_s_nom'] to the strict argument.

Parameters:

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_generators

check_generators(component: Components, strict: bool = False) -> None

Check the consistency of generator attributes before the simulation.

This function performs the following checks on generator components: 1. Ensures that committable generators are not both up and down before the simulation. 2. Verifies that the minimum total energy to be produced (e_sum_min) is not greater than the maximum total energy to be produced (e_sum_max).

A numerical tolerance from params.consistency.numerical_tolerance is applied when comparing e_sum_min and e_sum_max.

Activate strict mode in general consistency check by passing ['generators'] to the the strict argument.

Parameters:

  • component (Component) –

    The generator component to be checked.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_investment_periods

check_investment_periods(n: NetworkType, strict: bool = False) -> None

Check if investment periods are aligned with snapshots.

Activate strict mode in general consistency check by passing ['investment_periods'] to the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_line_types_consistency

check_line_types_consistency(n: NetworkType, strict: bool = False) -> None

Check that line_types are identical across all scenarios.

In stochastic networks, line_types must be identical across all scenarios

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

check_link_delays(n: NetworkType, component: Components, strict: bool = False) -> None

Check that delay attributes are valid for Link and Process components.

Deprecated since 1.2: Use check_dispatch_delays instead.

pypsa.consistency.check_nans_for_component_default_attrs

check_nans_for_component_default_attrs(n: NetworkType, component: Components, strict: bool = False) -> None

Check for missing values in component attributes.

Activate strict mode in general consistency check by passing ['nans_for_component_default_attrs'] the strict argument.

Checks for all attributes if they are nan but have a default value, which is not nan.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_no_modular_committables

check_no_modular_committables(n: Network) -> None

Check that no modular committable components exist.

Raises ValueError if linearized_unit_commitment is used with modular committable components, as this combination is semantically invalid.

Parameters:

  • n (Network) –

    The network to check.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_scenario_invariant_attributes

check_scenario_invariant_attributes(n: NetworkType, strict: bool = False) -> None

Check if invariant component attributes are not changed across scenarios.

There are some component attributes that must remain the same across scenarios. These attributes define the topology of the network or the mathematical structure. We raise an error if user attemps to modify them across scenarios. Any difference in values (including NaN vs non-NaN) will trigger an error.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_scenarios_sum_to_one

check_scenarios_sum_to_one(n: NetworkType, strict: bool = False) -> None

Check if scenarios probabilities sum to 1.

This check verifies that scenario probabilities have not been modified after initialization to break the constraint that they must sum to 1.

Activate strict mode in general consistency check by passing ['scenarios_sum'] to the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_shapes

check_shapes(n: NetworkType, strict: bool = False) -> None

Check if shapes are aligned with related components.

Activate strict mode in general consistency check by passing ['shapes'] to the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_static_power_attributes

check_static_power_attributes(n: NetworkType, component: Components, strict: bool = False) -> None

Check static attrs p_now, s_nom, e_nom in any component.

Activate strict mode in general consistency check by passing ['static_power_attrs'] the strict argument.

A numerical tolerance from params.consistency.numerical_tolerance is applied when comparing minimum and maximum expansion limits.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_stochastic_slack_bus_consistency

check_stochastic_slack_bus_consistency(n: NetworkType, strict: bool = False) -> None

Check that the same bus is chosen as slack across all scenarios in stochastic networks.

Ensure that the same bus is consistently chosen as the slack bus to maintain mathematical consistency of the optimization problem.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_time_series

check_time_series(n: NetworkType, component: Components, strict: bool = False) -> None

Check if time series of component are aligned with network snapshots.

Activate strict mode in general consistency check by passing ['time_series'] to the strict argument.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_time_series_power_attributes

check_time_series_power_attributes(n: NetworkType, component: Components, strict: bool = False) -> None

Check p_max_pu and e_max_pu nan and infinite values in time series.

Activate strict mode in general consistency check by passing ['time_series_power_attrs'] the strict argument.

A numerical tolerance from params.consistency.numerical_tolerance is applied when comparing minimum and maximum operational limits.

Parameters:

  • n (Network) –

    The network to check.

  • component (Component) –

    The component to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check

pypsa.consistency.check_transformer_types_consistency

check_transformer_types_consistency(n: NetworkType, strict: bool = False) -> None

Check that transformer_types are identical across all scenarios.

In stochastic networks, transformer_types must be identical across all scenarios since they define physical characteristics of transformers.

Parameters:

  • n (Network) –

    The network to check.

  • strict (bool, default: False ) –

    If True, raise an error instead of logging a warning.

See Also

pypsa.Network.consistency_check