VeraGridEngine.Simulations.Stochastic package

Submodules

VeraGridEngine.Simulations.Stochastic.latin_hypercube_sampling module

This code was originally published by the following individuals for use with Scilab:

Copyright (C) 2012 - 2013 - Michael Baudin Copyright (C) 2012 - Maria Christopoulou Copyright (C) 2010 - 2011 - INRIA - Michael Baudin Copyright (C) 2009 - Yann Collette Copyright (C) 2009 - CEA - Jean-Marc Martinez

website: forge.scilab.org/index.php/p/scidoe/sourcetree/master/macros

Much thanks goes to these individuals. It has been converted to Python by Abraham Lee.

VeraGridEngine.Simulations.Stochastic.latin_hypercube_sampling.lhs(n: int, samples: ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[int, int], dtype[float64]] | None = None, criterion: str = 'center', iterations: int = 5)[source]

Generate a latin-hypercube design

Parameters

nint

The number of factors to generate samples for

samplesint

The number of samples to generate for each factor (Default: n)

criterionstr

Allowable values are β€œcenter” or β€œc”, β€œmaximin” or β€œm”, β€œcentermaximin” or β€œcm”, and β€œcorrelation” or β€œcorr”. If no value given, the design is simply randomized.

iterationsint

The number of iterations in the maximin and correlations algorithms (Default: 5).

Returns

H2d-array

An n-by-samples design matrix that has been normalized so factor values are uniformly spaced between zero and one.

Example

A 3-factor design (defaults to 3 samples):

>>> lhs(3)
array([[ 0.40069325,  0.08118402,  0.69763298],
       [ 0.19524568,  0.41383587,  0.29947106],
       [ 0.85341601,  0.75460699,  0.360024  ]])

A 4-factor design with 6 samples:

>>> lhs(4, samples=6)
array([[ 0.27226812,  0.02811327,  0.62792445,  0.91988196],
       [ 0.76945538,  0.43501682,  0.01107457,  0.09583358],
       [ 0.45702981,  0.76073773,  0.90245401,  0.18773015],
       [ 0.99342115,  0.85814198,  0.16996665,  0.65069309],
       [ 0.63092013,  0.22148567,  0.33616859,  0.36332478],
       [ 0.05276917,  0.5819198 ,  0.67194243,  0.78703262]])

A 2-factor design with 5 centered samples:

>>> lhs(2, samples=5, criterion='center')
array([[ 0.3,  0.5],
       [ 0.7,  0.9],
       [ 0.1,  0.3],
       [ 0.9,  0.1],
       [ 0.5,  0.7]])

A 3-factor design with 4 samples where the minimum distance between all samples has been maximized:

>>> lhs(3, samples=4, criterion='maximin')
array([[ 0.02642564,  0.55576963,  0.50261649],
       [ 0.51606589,  0.88933259,  0.34040838],
       [ 0.98431735,  0.0380364 ,  0.01621717],
       [ 0.40414671,  0.33339132,  0.84845707]])

A 4-factor design with 5 samples where the samples are as uncorrelated as possible (within 10 iterations):

>>> lhs(4, samples=5, criterion='correlate', iterations=10)

VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_driver module

class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_driver.StochasticPowerFlowDriver(grid: MultiCircuit, options: PowerFlowOptions, mc_tol=0.001, batch_size=100, sampling_points=10000, opf_time_series_results=None, simulation_type: StochasticPowerFlowType = StochasticPowerFlowType.LatinHypercube)[source]

Bases: DriverTemplate

batch_size
cancel()[source]

Cancel the simulation :return:

get_steps()[source]

Get time steps list of strings

max_sampling_points
mc_tol
name = 'Stochastic Power Flow'
opf_time_series_results
options
pool
returned_results
run() None[source]

Run the monte carlo simulation.

Returns:

None.

run_single_thread_mc(use_lhs: bool = False) StochasticPowerFlowResults | None[source]

Run the stochastic sampling loop in the current thread.

Parameters:

use_lhs – Whether Latin Hypercube sampling must be used.

Returns:

StochasticPowerFlowResults when the study can be executed, otherwise None.

simulation_type
tpe = 'Stochastic Power Flow'
update_progress_mt(res)[source]
class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_driver.StochasticPowerFlowType(value)[source]

Bases: Enum

LatinHypercube = 'Latin Hypercube'
MonteCarlo = 'Monte Carlo'

VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_input module

class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_input.StochasticPowerFlowInput[source]

Bases: object

Scdf_fixed: list[CDF]
get(n_samples: int = 0, use_latin_hypercube: bool = False) ndarray[tuple[Any, ...], dtype[complex128]][source]

Generate stochastic samples for the grid injections.

Parameters:
  • n_samples – number of samples

  • use_latin_hypercube – use Latin Hypercube to sample

Returns:

CxMat (p.u.)

get_at(x: ndarray) ndarray[tuple[Any, ...], dtype[complex128]][source]

Get samples at x :param x: values in [0, 1] to sample the CDF :return: CxVec

has_profile_samples() bool[source]

Check whether the input contains at least one time-series sample.

Returns:

True when stochastic samples can be generated.

n: int
regression_model: KNeighborsRegressor | None

VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_results module

class VeraGridEngine.Simulations.Stochastic.stochastic_power_flow_results.StochasticPowerFlowResults(n, m, p, bus_names, branch_names, bus_types)[source]

Bases: ResultsTemplate

CLASS_DATA_VARIABLES = {'S_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'Sbr_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'V_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'branch_names': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'bus_names': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'bus_types': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'error_series': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'l_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'l_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loading': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loading_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loss_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'loss_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'losses': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'losses_points': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'points_number': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 's_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 's_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'sbranch': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'v_avg_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'v_std_conv': <VeraGridEngine.Simulations.results_template.ResultsProperty object>, 'voltage': <VeraGridEngine.Simulations.results_template.ResultsProperty object>}
CLASS_RESULTS_DECLARATIONS = (<VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>)
LOCAL_RESULTS_DECLARATIONS = (<VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>, <VeraGridEngine.Simulations.results_template.ResultsProperty object>)
S_points
Sbr_points
V_points
append_batch(mcres)[source]

Append a batch (a StochasticPowerFlowResults object) to this object @param mcres: StochasticPowerFlowResults object @return:

branch_names
bus_names
bus_types
compile()[source]

Compiles the final Monte Carlo values by running an online mean and @return:

error_series
get_index_loading_cdf(max_val=1.0)[source]

Find the elements where the CDF is greater or equal to a value :param max_val: value to compare :return: indices, associated probability

get_voltage_sum()[source]

Return the voltage summation @return:

l_avg_conv
l_std_conv
loading
loading_points
loss_avg_conv
loss_std_conv
losses
losses_points
mdl(result_type: ResultTypes) ResultsTable[source]

Plot the results :param result_type: :return:

points_number
query_voltage(power_array)[source]

Fantastic function that allows to query the voltage from the sampled points without having to run power Sf Args:

power_array: power Injections vector

Returns: Interpolated voltages vector

s_avg_conv
s_std_conv
sbranch
v_avg_conv
v_std_conv
voltage

Module contents