energia.modeling.indices.sample#

Sample of an Aspect

Functions

inf(function)

Minimize the function

merge_trees(d1, d2)

Recursively merge two tree-like dicts (values always dicts).

sigma(variable[, over, position])

Summation without recursion, also allows better printing

sup(function)

Maximize the function

Classes

Bind(sample, parameter[, leq, geq, eq, ...])

Bind constraint

FuncOfSamples(F, program)

Some Function of Samples

Idx

alias of I

Sample(aspect, domain[, timed, spaced, report])

Sets a bound on a variable (V) within a particular domain.

V(*index[, itg, nn, bnr, mutable, tag, ltx])

Ordered set of variables (Var).

cached_property(func)

chain(*iterables)

Return a chain object whose .__next__() method returns elements from the first iterable until it is exhausted, then elements from the next iterable, until all of the iterables are exhausted.

class Sample(aspect: Aspect, domain: Domain, timed: bool = False, spaced: bool = False, report: bool = False)[source]#

Bases: _Hash

Sets a bound on a variable (V) within a particular domain.

Parameters:
  • aspect (Aspect | None) – Aspect to which the constraint is applied.

  • domain (Domain | None) – Domain over which the aspect is defined.

  • timed (bool | None) – If the temporal index is predetermined. Defaults to None.

  • spaced (bool | None) – If the spatial index is predetermined. Defaults to None.

  • report (bool, optional) – If a reporting binary variable is needed. Defaults to False.

Variables:
  • hasinc (bool) – If incidental calculation is generated.

  • nominal (float | None) – If nominal is provided and multiplied by the nominal value.

  • norm (bool) – The input argument is normalized if True.

  • parameter (P) – Parameter

  • length (int) – Length of the parameter set.

Note

  • timed and spaced help skip the calculation of finding the appropriate index.

    For time, this is done based on the length of the input parameter.

  • opr is useful if providing a combined bound to different variables.

  • name is generated based on the variable.

  • domains are updated as the program is built.

property of: Self | None#

Sample being calculated

property name: str[source]#

Name of the constraint

property index: list[_Component]#

_Index

property index_short: list[_X | Sample]#

Short Index

property I: I[source]#

gana index set (I)

property x: Self#

Binary Reporting Variable

property add: Self#

Positive Control Response

property sub: Self#

Negative Control Response

property F#

Function

property constraints#

Constraints

property space[source]#

Assigns to network is spatial index is not given

property time[source]#

Matches an appropriate temporal scale Sets domain.periods if needed and returns domain.periods

prep(nominal: float = 1, norm: bool = True) Self[source]#

Nominal value

Parameters:
  • nominal (float, optional) – If the input argument (bounds) are to be scaled, defaults to 1

  • norm (bool, optional) – If the input argument (bounds) are normalized, defaults to True

forall(index) Self[source]#

Returns the function at the given index

V(parameter: float | list[float] | None = None, length: int | None = None) V[source]#

Returns a gana variable (V) using .domain as the index. If time and space are (or) not given, i.e. .spaced or .timed are False, They can be determined.

For identifying the appropriate temporal scale (index):

The length of the parameter set is used Alternatively, the length of the parameter set can passed directly If neither are passed, it defaults to horizon

If the spatial index is not given, it defaults to the network.

Parameters:
  • parameters (int | list, optional) – the parameter/parameter set. Defaults to None.

  • length (int, optional) – length of the parameter set. Defaults to None.

  • report (bool, optional) – to make a binary reporting variable. Defaults to False.

  • incidental (bool, optional) – if this is an incidental calculation. Defaults to False.

Note

  • parameters and length are mutually exclusive

Vinc(parameters: float | list = None, length: int = None) V[source]#

Returns the incidental variable

Parameters:
  • parameters (float | list, optional) – the parameter/parameter set. Defaults to None.

  • length (int, optional) – length of the parameter set. Defaults to None.

Returns:

the incidental variable

Return type:

V

Vb() V[source]#

Bound Variable These apply when there are multiple levels of variable-making Endogenous bounds apply, i.e.

Returns:

the bound variable

Return type:

V

\[\mathbf{v}_{\dots, t^{+}} <= {\theta}_{\dots, t^{+}} \cdot \mathbf{v}_{\dots, t^{-}}\]

where : - \(\mathbf{v}\) is the variable - \(\theta\) is the parameter set - \(t^{i}\) are bespoke discretizations of the horizon - \(i \in \{-, +\}\) are variable-making levels

X(parameters: float | list[float] | None = None, length: int | None = None) V[source]#

Binary Reporting Variable These report whether a variable has been made or not Also useful to make the variable space semi-continuous

\[\mathbf{v}_{\dots, t} <= {\theta}_{\dots, t} \cdot \mathbf{x}_{\dots, t}\]
where :
  • \(\mathbf{v}\) is the variable

  • \(\mathbf{x}\) is the binary reporting variable

  • \(\theta\) is the parameter set

  • \(t\) some bespoke discretization of the horizon

Vlag()[source]#

Handles lagged domains

obj(maximize: bool = False)[source]#

Set the sample itself as the objective

Parameters:

max (bool, optional) – if maximization, defaults to False

opt(maximize: bool = False)[source]#

Optimize

Parameters:

maximize (bool, optional) – if maximization, defaults to False

bounds()[source]#

Finds the bounds of the variable

eval(*values: float)[source]#

Evaluate the variable using parametric variable values

Parameters:

values (float) – values for the parametric variables

output(aslist: bool = False, asdict: bool = False, compare: bool = False)[source]#

Solution

Parameters:
  • aslist (bool, optional) – Returns the solution as list, otherwise as a variable

  • asdict (bool, optional) – Returns the solution as dict, otherwise as a variable

  • compare (bool, optional) – If True, compares the solutions across multiple solves

show(descriptive=False)[source]#

Pretty print constraints

bar(font_size: float = 16, fig_size: tuple[float, float] = (12, 6), linewidth: float = 0.7, color: str = 'blue', grid_alpha: float = 0.3, usetex: bool = True, str_idx_lim: int = 10)[source]#

Draws the variable as a bar chart

line(font_size: float = 16, fig_size: tuple[float, float] = (12, 6), linewidth: float = 0.7, color: str = 'blue', grid_alpha: float = 0.3, usetex: bool = True, str_idx_lim: int = 10)[source]#

Draws the variable as a line chart

class FuncOfSamples(F: F, program: Prg)[source]#

Bases: object

Some Function of Samples

This is used to bind a function of variables to a given parameter (set)

opt(maximize=False)[source]#

Optimize the function

Parameters:

max (bool, optional) – if maximization, defaults to False