The evaluator package (symenergy.evaluator)¶
The evaluator class (symenergy.evaluator.evaluator.Evaluator)¶
Evaluator class initialization¶
-
class
symenergy.evaluator.evaluator.
Evaluator
(model: symenergy.core.model.Model, x_vals: dict, drop_non_optimum=False, tolerance=1e-09)[source]¶ Evaluates model results for selected parameter values.
Parameters: - model (
symenergy.core.model.Model
) – SymEnergy model instance - x_vals (dict) – dictionary
{parameter_instance_0: iterable_of_values}
- drop_non_optimum (bool) – if False, also keeps constraint combinations associated with non-optimal constraints
- tolerance (float) – absolute tolerance for constraint evaluation to allow for numerical inaccuracies
Example
>>> import numpy as np >>> from symenergy.core.model import Model >>> from symenergy.evaluator.evaluator import Evaluator >>> m = Model(curtailment=True) >>> m.add_slot(name='day', load=4500, vre=4500) >>> m.add_plant(name='n', vc0=10, vc1=1, capacity=3500) >>> m.add_plant(name='g', vc0=90, vc1=10) >>> m.generate_solve() >>> x_vals = {m.vre_scale: np.linspace(0, 1, 51), m.comps['n'].C: [0, 1000, 3000]} >>> ev = Evaluator(m, x_vals=x_vals)
The attribute
ev.df_x_vals
is a table with all parameter value combinations:>>> ev.df_x_vals vre_scale_none C_n_none 0 0.00 0 1 0.00 1000 2 0.00 3000 3 0.02 0 4 0.02 1000 ...
The methods
symenergy.evaluator.evaluator.Evaluator.get_evaluated_lambdas_parallel()
andsymenergy.evaluator.evaluator.Evaluator.expand_to_x_vals_parallel()
are used to perform the actual evaluation.
- model (
Method get_evaluated_lambdas_parallel
¶
-
Evaluator.
get_evaluated_lambdas_parallel
(skip_multipliers=True)[source]¶ For each model variable and constraint combination, generate a function evaluated by all constant parameter values, but not by the varied values of the
x_vals
table. This results in a DataFrame attributedf_lam_func
, which is subsequently used (symenergy.evaluator.evaluator.Evaluator.expand_to_x_vals_parallel()
) to generate the numerical values for variables and multipliers.Continuing the example from
symenergy.evaluator.evaluator.Evaluator
:>>> import inspect >>> ev.cache_lambd.delete() >>> ev.get_evaluated_lambdas_parallel() >>> func = (ev.df_lam_func.set_index(['idx', 'func']) .loc[(4, 'g_p_day')] .lambd_func) >>> print(inspect.getsource(func)) def _ef0ba06865119477ac40bc0b40038a25(vre_scale_none,C_n_none): return(-C_n_none - 4500*vre_scale_none + 4500)
In the example above the generated example function thus depends on the parameters with names
vre_scale_none
andC_n_none
(the model VRE scale and the power plant capacity, as specified through thex_vals
attribute).Note: The DataFrame
ev.df_lam_func
is typically only used internally. Instead, access the tablesModel.df_comb
to obtain the result expressions for the model variablesEvaluator.df_exp
to obtain the fully evaluated numerical solutions
Method expand_to_x_vals_parallel
¶
-
Evaluator.
expand_to_x_vals_parallel
()[source]¶ Generates generates a table indexed by:
- model variable/multiplier (column
func
) - constraint combination (columns
idx
) - varied parameters (columns specified by the list
Evaluator.x_name
)
with all numerically evaluated values of functions and multipliers.
Other key columns are:
lambd
numerical valueis_optimum
: boolean; if Evaluator was initialized withdrop_non_optimum=True
, all non-optimal rows are droppedmask_valid
: indicates whether the constraint combination yields valid results under the corresponding parameter values; see documentation section Theoretical discussion of the minimal example for explanations on infeasible constraint combinations by parameter values.
Continuing the example from
symenergy.evaluator.evaluator.Evaluator.get_evaluated_lambdas_parallel()
:>>> ev.expand_to_x_vals_parallel() >>> (ev.df_exp.query('is_optimum') .set_index(['func', 'idx'] + ev.x_name)[ ['lambd', 'is_optimum', 'mask_valid']]).head() lambd is_optimum mask_valid func idx vre_scale_none C_n_none curt_p_day 1 1.0 0 0.0 True True g_p_day 1 1.0 0 0.0 True True n_p_day 1 1.0 0 0.0 True True pi_supply_day 1 1.0 0 0.0 True True curt_p_day 2 0.0 0 0.0 True True ...
Note: Under some circumstances the serial evaluation is overall faster than the parallel approach. Serial evaluation is obtained by setting the SymEnergy multiprocessing nworkers parameter to
None
:>>> from symenergy.auxiliary.parallelization import multiproc_params >>> multiproc_params('nworkers') = None
- model variable/multiplier (column
Plotting classes (symenergy.evaluator.plotting)¶
The Evaluator sub-package provides a convenient way to generate interactive energy balance plot arrays in dependence on selected parameters.:q