Skip to content

Options

PyPSA package options.

v0.33.0 | Options

This class provides a hierarchical structure for managing package options and the functionality can be accessed via pypsa.options.

pypsa.__getattr__

__getattr__(name: str) -> Any

Get the value of an option at the specified path.

Examples:

>>> pypsa.options.general.allow_network_requests
True
>>> pypsa.options.params.statistics.round
5

pypsa.__setattr__

__setattr__(name: str, value: Any) -> None

Set the value of an option at the specified path.

Examples:

Set the option to False:

>>> pypsa.options.general.allow_network_requests = False
>>> pypsa.options.general.allow_network_requests
False

Reset back to default:

>>> pypsa.options.reset_all()

pypsa.describe

describe() -> None

Print documentation for options node via attribute access.

Examples:

Print all options:

>>> pypsa.options.describe()
PyPSA Options
=============
general.allow_network_requests:
    Default: True
    Description: Allow PyPSA to make network requests...
...

pypsa.get_option

get_option(path: str) -> Any

Get the value of an option at the specified path.

Parameters:

  • path (str) –

    Path to the option. Must be in the format "category.option_name" or "category.subcategory.option_name"

Returns:

  • Any

    The value of the option.

Examples:

>>> pypsa.options.get_option("general.allow_network_requests")
True
>>> pypsa.options.get_option("params.statistics.round")
5

pypsa.set_option

set_option(path: str, value: Any) -> None

Set the value of an option at the specified path.

Parameters:

  • path (str) –

    Path to the option. Must be in the format "category.option_name" or "category.subcategory.option_name"

  • value (Any) –

    Value to set for the option.

Examples:

Set the option to False:

>>> pypsa.options.set_option("general.allow_network_requests", False)
>>> pypsa.options.general.allow_network_requests
False

Reset back to default:

>>> pypsa.options.reset_all()
>>> pypsa.options.general.allow_network_requests
True

pypsa.reset_option

reset_option(path: str) -> None

Reset a single option to its default value.

Parameters:

  • path (str) –

    Path to the option. Must be in the format "category.option_name" or "category.subcategory.option_name"

Examples:

Set an option to a non-default value:

>>> pypsa.set_option("general.allow_network_requests", False)
>>> pypsa.options.general.allow_network_requests
False

Reset just that option:

>>> pypsa.reset_option("general.allow_network_requests")
>>> pypsa.options.general.allow_network_requests
True

pypsa._options.option_context

option_context(*args: Any) -> Generator[None, None, None]

Context manager to temporarily set options.

Parameters:

  • *args ((str, Any), default: () ) –

    Must be passed in pairs of option_name and value. Option_name must be in the format "category.option_name" or "category.subcategory.option_name"

Piecewise-constraint helpers for PyPSA optimization models.

pypsa.optimization.piecewise.PiecewiseOptions dataclass

PiecewiseOptions(component: str, attribute: str, sign: SIGNS_T, name: tuple[str, ...] = tuple(), method: str = 'auto', cumulative_attr: bool = False)

Options for piecewise constraint formulation.

pypsa.optimization.piecewise.PiecewiseOptions.attribute instance-attribute

attribute: str

Component attribute for which piecewise data is defined.

pypsa.optimization.piecewise.PiecewiseOptions.component instance-attribute

component: str

PyPSA component name.

pypsa.optimization.piecewise.PiecewiseOptions.cumulative_attr class-attribute instance-attribute

cumulative_attr: bool = False

Whether the y-axis breakpoints represent marginal values which should be integrated to define y breakpoints.

If True, the integral of the piecewise curve will be used to define y breakpoints. If False, the nominal values at each x breakpoint will be used to define y breakpoints.

pypsa.optimization.piecewise.PiecewiseOptions.method class-attribute instance-attribute

method: str = 'auto'

The method to use for the piecewise constraint formulation, passed to linopy's add_piecewise_formulation method.

pypsa.optimization.piecewise.PiecewiseOptions.name class-attribute instance-attribute

name: tuple[str, ...] = field(default_factory=tuple)

Optional filter for a component name to apply the piecewise constraint to, e.g. a specific generator.

pypsa.optimization.piecewise.PiecewiseOptions.sign instance-attribute

sign: SIGNS_T

Sign for the piecewise constraint, interpreted as y f(x).

pypsa.optimization.piecewise.PiecewiseOptions.__post_init__

__post_init__() -> None

Ensure that name is stored as a tuple for consistent processing later.