Public API

Exported functions and types of ContGridMod.jl.

Contents

Index

Structs

ContGridModML.StaticSolType

Contains the results of the static training.

  • b::Vector{T} where T<:Real: Vector of the nodal susceptances. The ordering is alternating $b_x$ and $b_y$. The values are ordered in the same order as in the DoF handler cm.dh₁.
  • losses::Matrix{T} where T<:Real: The training losses. The row corresponds to the epoch and the column to the data set.
  • train_pred::Matrix{T} where T<:Real: Prediction of the values for each training data set with the trained values.
  • test_pred::Matrix{T} where T<:Real: Prediction of the values for each test data set with the trained values.
  • t_train::Matrix{T} where T<:Real: Ground truth data for the training data sets.
  • t_test::Matrix{T} where T<:Real: qprojb Ground truth data for the test data sets.
  • train_losses::Vector{T} where T<:Real: Loss values for all training data sets.
  • test_losses::Vector{T} where T<:Real: Loss values for all test data sets.
  • model::ContGridModML.ContModel: The continuous model with the updated susceptances.
  • train_models::Vector{<:ContGridModML.DiscModel}: The discrete models used for training.
  • test_models::Vector{<:ContGridModML.DiscModel}: The discrete models used for testing.
  • n_modes::Int64: The number of eigenmodes of the Laplacian the model is trained on
source
ContGridModML.DynamicSolType

Contains the results of the dynamic training.

  • train_ix::Vector{<:Integer}: Indices of the generators used to create the training ground truth data.
  • test_ix::Vector{<:Integer}: Indices of the generators used to create the training ground truth data.
  • comp_ix::Vector{<:Integer}: Indices of the nodes on which the frequency is compared to calculate the loss function.
  • m::Vector{<:Real}: Vector of the nodal inertia. The values are ordered in the same order as in the DoF handler cm.dh₁.
  • d::Vector{<:Real}: Vector of the nodal damping. The values are ordered in the same order as in the DoF handler cm.dh₁.
  • coeffs::Vector{<:Real}: Coefficients of the modal expansion of the dynamical parameters. The realtion between the nodal values, the coefficients, and the eigenvectors is given by
    n = size(coeffs, 1) ÷ 2
    m = eve[:, 1:n] * coeffs[1:n]
    d = eve[:, 1:n] * coeffs[n+1:end]
  • eve::Matrix{<:Real}: Eigenvectors of the unweighted Laplacian of the grid of the continuous model.
  • losses::Matrix{<:Real}: The training losses. The row corresponds to the epoch and the column to the data set.
  • train_losses::Vector{<:Real}: Loss values for all training data sets.
  • test_losses::Vector{<:Real}: Loss values for all test data sets.
  • model::ContGridModML.ContModel: The continuous model with updated inertia and damping.
  • n_modes::Int64: The number of eigenmodes of the Laplacian the model is trained on
source

Functions

ContGridModML.learn_susceptancesFunction
learn_susceptances(
;
    train_folder,
    test_folder,
    mesh_fn,
    n_epoch,
    n_batch,
    n_modes,
    n_coeffs,
    comp_ix,
    bx_init,
    by_init,
    rng,
    opt,
    bmin,
    δ
) -> ContGridModML.StaticSol{Float64}

Learn the line susceptances.

The parameters are learned by calculating the stable solution for multiple dispatches and comparing them to the results from the discrete model. The comparison points are obtained by using the liear approximation provided by the finite element method.

Arguments

  • train_fn::String = MODULE_FOLDER * "/data/ml/training_": The names of the files containing the training scenarios. The files must be labeled train_fn1.h5, train_fn2.h5, etc.
  • test_fn::String = MODULE_FOLDER * "/data/ml/test_": The names of the files containing the test scenarios. The files must be labeled test.h5, test.h5, etc.
  • grid_fn::String = MODULE_FOLDER * "/data/panta.msh": Name of the file containing the mesh
  • n_train::Int = 48: Number of training data sets
  • n_test::Int = 12: Number of test data sets
  • n_epochs::Int = 10000: Number of epochs
  • n_batches::Int = 3: Number of batches per epoch
  • tf::Real = 0.05: Duration of the heat equation diffusion for the power distribution
  • κ::Real = 0.02: Diffusion constant of the heat equation diffusion for the power distribution
  • σ::Real = 0.01: Standard deviation for the initial Gaussian distribution of the parameters
  • rng::AbstractRNG = Xoshiro(): Random number generator used to draw all random numbers
  • bmin::Real = 0.1: Minimimum value of the suscpetances
  • δ = 0.5: Parameter of the Huber loss function
source
ContGridModML.learn_dynamical_parametersFunction
learn_dynamical_parameters(
;
    dm_fn,
    cm_fn,
    dP,
    n_train,
    n_test,
    dt,
    tf,
    disc_solve_kwargs,
    cont_solve_kwargs,
    lambda_solve_kwargs,
    seed,
    n_points,
    m_init,
    d_init,
    n_coeffs,
    n_modes,
    n_epochs,
    max_function,
    train_ix,
    test_ix,
    n_batches
)

Learn the inertia and damping distribution for the continuous model.

The frequency response of faults at multiple generators are compared on homogeneously spread buses across the grid. The gradient is calculated using an adjoint sensitivity method and the updates to the parameters are calculated using a constraint gradient descent method.

Arguments

  • dm_fn::String = MODULE_FOLDER * "/data/dm.h5": File name of the discrete model
  • cm_fn::String = MODULE_FOLDER * "/data/cm.h5": File name of the continuous model
  • dP::Real = -9.0: Fault size to be simulated
  • n_train::Integer = 12: Amount of faults to consider for training
  • n_test::Integer = 4: Amount of faults to consider for testing
  • dt::Real = 0.01: Step size at which the solutions of the ODEs are saved
  • tf::Real = 25.0: Duration of the simulations
  • disc_solve_kwargs::Dict{Symbol, <:Any} = Dict{Symbol, Any}(): Keyword arguments passed to the ODE solver for the discrete model
  • cont_solve_kwargs::Dict{Symbol, <:Any} = Dict{Symbol, Any}(): Keyword arguments passed to the ODE solver for the continuous model
  • lambda_solve_kwargs::Dict{Symbol, <:Any} = Dict{Symbol, Any}(:saveat => 0.1, :abstol => 1e-3, :reltol => 1e-2): Keyword arguments passed to the ODE solver of the adjoint equations
  • seed::Union{Nothing, Integer} = 1709: Seed for the random number generator to be used to pick the training and test generators
  • σ = 0.05: Standard deviation of the Gaussian used to distribute the fault
  • n_points = 40: Number of points for comparison along the largest dimension
  • n_coeffs = 1: Number of coefficients that are non-zero at the beginning of the training. They correspond to the n_coeffs lowest modes of the Laplacian.
  • n_modes = 20: Number of modes the Laplacian that are used to expand the parameters.
  • n_epochs = 8000: Number of epochs used for the training.
  • max_function::Function = (x) -> 30 * 2^(x / 500): Function that changes the magnitude of the change vector of the parameters wrt the epoch.
  • train_ix::Union{Nothing, Vector{<:Integer}} = nothing: Indices of the generators used for training if they are not supposed to be picked randomly.
  • test_ix::Union{Nothing, Vector{<:Integer}} = nothing: Indices of the generators used for testing if they are not supposed to be picked randomly.
Warning

If the training and test generators are not supposed to be picked randomly, both train_ix and test_ix need to be passed.

source
ContGridModML.load_solFunction
load_sol(
    fn::String
) -> Union{ContGridModML.DynamicSol, ContGridModML.StaticSol}

Load a solution from a HDF5 file.

source