API reference#

Warning

This reference is work in progress.

fledge.api#

Application programming interface (API) module for high-level interface functions to run FLEDGE.

fledge.api.run_nominal_operation_problem(scenario_name, recreate_database=True, print_results=False, store_results=True, results_path=None)#

Set up and solve a nominal operation problem for the given scenario.

Parameters:
  • scenario_name (str) –

  • recreate_database (bool) –

  • print_results (bool) –

  • store_results (bool) –

  • results_path (str | None) –

Return type:

Results

fledge.api.run_optimal_operation_problem(scenario_name, recreate_database=True, print_results=False, store_results=True, results_path=None)#

Set up and solve an optimal operation problem for the given scenario.

Parameters:
  • scenario_name (str) –

  • recreate_database (bool) –

  • print_results (bool) –

  • store_results (bool) –

  • results_path (str | None) –

Return type:

Results

fledge.problems#

Problems module for mathematical optimization and simulation problem type definitions.

class fledge.problems.Results(**kwargs)#

Bases: ElectricGridOperationResults, ThermalGridOperationResults, DERModelSetOperationResults, ElectricGridDLMPResults, ThermalGridDLMPResults

class fledge.problems.NominalOperationProblem#

Bases: object

Nominal operation problem object, consisting of the corresponding electric / thermal grid models, reference power flow solutions and DER model set for the given scenario.

  • The nominal operation problem (alias: simulation problem, power flow problem) represents the simulation problem of the DERs and grids considering the nominal operation schedule for all DERs.

  • The problem formulation is able to consider combined as well as individual operation of thermal and electric grids.

class fledge.problems.OptimalOperationProblem#

Bases: object

Optimal operation problem object, consisting of an optimization problem as well as the corresponding electric / thermal grid models, reference power flow solutions, linear grid models and DER model set for the given scenario.

  • The optimal operation problem (alias: optimal dispatch problem, optimal power flow problem) formulates the optimization problem for minimizing the objective functions of DERs and grid operators subject to the model constraints of all DERs and grids.

  • The problem formulation is able to consider combined as well as individual operation of thermal and electric grids.

fledge.electric_grid_models#

Electric grid models module.

class fledge.electric_grid_models.ElectricGridModel(electric_grid_data)#

Bases: object

Electric grid model object.

Note

This abstract class only defines the expected variables of linear electric grid model objects, but does not implement any functionality.

Variables:
  • timesteps (pd.Index) – Index set of time steps of the current scenario. This is needed for optimization problem definitions within linear electric grid models (see LinearElectricGridModel).

  • phases (pd.Index) – Index set of the phases.

  • node_names (pd.Index) – Index set of the node names.

  • node_types (pd.Index) – Index set of the node types.

  • line_names (pd.Index) – Index set of the line names.

  • transformer_names (pd.Index) – Index set of the transformer names.

  • branch_names (pd.Index) – Index set of the branch names, i.e., all line names and transformer names.

  • branch_types (pd.Index) – Index set of the branch types.

  • der_names (pd.Index) – Index set of the DER names.

  • der_types (pd.Index) – Index set of the DER types.

  • nodes (pd.Index) – Multi-level / tuple index set of the node types, node names and phases corresponding to the dimension of the node admittance matrices.

  • branches (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases corresponding to the dimension of the branch admittance matrices.

  • lines (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the lines only.

  • transformers (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the transformers only.

  • ders (pd.Index) – Index set of the DER names, corresponding to the dimension of the DER power vector.

  • node_voltage_vector_reference (np.ndarray) – Node voltage reference / no load vector.

  • branch_power_vector_magnitude_reference (np.ndarray) – Branch power reference / rated power vector.

  • der_power_vector_reference (np.ndarray) – DER power reference / nominal power vector.

  • is_single_phase_equivalent (bool) – Singe-phase-equivalent modelling flag. If true, electric grid is modelled as single-phase-equivalent of three-phase balanced system.

Parameters:

electric_grid_data (ElectricGridData) –

static process_line_types_overhead(electric_grid_data)#

Process overhead line type definitions in electric grid data object.

Parameters:

electric_grid_data (ElectricGridData) –

Return type:

ElectricGridData

class fledge.electric_grid_models.ElectricGridModelDefault#

Bases: ElectricGridModel

Electric grid model object consisting of the index sets for node names / branch names / der names / phases / node types / branch types, the nodal admittance / transformation matrices, branch admittance / incidence matrices and DER incidence matrices.

Syntax:
  • ElectricGridModelDefault(electric_grid_data): Instantiate electric grid model for given electric_grid_data.

  • ElectricGridModelDefault(scenario_name): Instantiate electric grid model for given scenario_name. The required electric_grid_data is obtained from the database.

Parameters:
Variables:
  • phases (pd.Index) – Index set of the phases.

  • node_names (pd.Index) – Index set of the node names.

  • node_types (pd.Index) – Index set of the node types.

  • line_names (pd.Index) – Index set of the line names.

  • transformer_names (pd.Index) – Index set of the transformer names.

  • branch_names (pd.Index) – Index set of the branch names, i.e., all line names and transformer names.

  • branch_types (pd.Index) – Index set of the branch types.

  • der_names (pd.Index) – Index set of the DER names.

  • der_types (pd.Index) – Index set of the DER types.

  • nodes (pd.Index) – Multi-level / tuple index set of the node types, node names and phases corresponding to the dimension of the node admittance matrices.

  • branches (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases corresponding to the dimension of the branch admittance matrices.

  • lines (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the lines only.

  • transformers (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the transformers only.

  • ders (pd.Index) – Index set of the DER names, corresponding to the dimension of the DER power vector.

  • node_voltage_vector_reference (np.ndarray) – Node voltage reference / no load vector.

  • branch_power_vector_magnitude_reference (np.ndarray) – Branch power reference / rated power vector.

  • der_power_vector_reference (np.ndarray) – DER power reference / nominal power vector.

  • is_single_phase_equivalent (bool) – Singe-phase-equivalent modelling flag. If true, electric grid is modelled as single-phase-equivalent of three-phase balanced system.

  • node_admittance_matrix (scipy.sparse.spmatrix) – Nodal admittance matrix.

  • node_transformation_matrix (scipy.sparse.spmatrix) – Nodal transformation matrix.

  • branch_admittance_1_matrix (scipy.sparse.spmatrix) – Branch admittance matrix in the ‘from’ direction.

  • branch_admittance_2_matrix (scipy.sparse.spmatrix) – Branch admittance matrix in the ‘to’ direction.

  • branch_incidence_1_matrix (scipy.sparse.spmatrix) – Branch incidence matrix in the ‘from’ direction.

  • branch_incidence_2_matrix (scipy.sparse.spmatrix) – Branch incidence matrix in the ‘to’ direction.

  • der_incidence_wye_matrix (scipy.sparse.spmatrix) – Load incidence matrix for ‘wye’ DERs.

  • der_incidence_delta_matrix (scipy.sparse.spmatrix) – Load incidence matrix for ‘delta’ DERs.

class fledge.electric_grid_models.ElectricGridModelOpenDSS#

Bases: ElectricGridModel

OpenDSS electric grid model object.

  • Instantiate OpenDSS circuit by running generating OpenDSS commands corresponding to given electric_grid_data, utilizing the OpenDSSDirect.py package.

  • The OpenDSS circuit can be accessed with the API of OpenDSSDirect.py: http://dss-extensions.org/OpenDSSDirect.py/opendssdirect.html

  • Due to dependency on OpenDSSDirect.py, creating multiple objects of this type may result in erroneous behavior.

Syntax:
  • ElectricGridModelOpenDSS(electric_grid_data): Initialize OpenDSS circuit model for given electric_grid_data.

  • ElectricGridModelOpenDSS(scenario_name) Initialize OpenDSS circuit model for given scenario_name. The required electric_grid_data is obtained from the database.

Parameters:
Variables:
  • phases (pd.Index) – Index set of the phases.

  • node_names (pd.Index) – Index set of the node names.

  • node_types (pd.Index) – Index set of the node types.

  • line_names (pd.Index) – Index set of the line names.

  • transformer_names (pd.Index) – Index set of the transformer names.

  • branch_names (pd.Index) – Index set of the branch names, i.e., all line names and transformer names.

  • branch_types (pd.Index) – Index set of the branch types.

  • der_names (pd.Index) – Index set of the DER names.

  • der_types (pd.Index) – Index set of the DER types.

  • nodes (pd.Index) – Multi-level / tuple index set of the node types, node names and phases corresponding to the dimension of the node admittance matrices.

  • branches (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases corresponding to the dimension of the branch admittance matrices.

  • lines (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the lines only.

  • transformers (pd.Index) – Multi-level / tuple index set of the branch types, branch names and phases for the transformers only.

  • ders (pd.Index) – Index set of the DER names, corresponding to the dimension of the DER power vector.

  • node_voltage_vector_reference (np.ndarray) – Node voltage reference / no load vector.

  • branch_power_vector_magnitude_reference (np.ndarray) – Branch power reference / rated power vector.

  • der_power_vector_reference (np.ndarray) – DER power reference / nominal power vector.

  • is_single_phase_equivalent (bool) – Singe-phase-equivalent modelling flag. If true, electric grid is modelled as single-phase-equivalent of three-phase balanced system.

  • circuit_name (str) – Circuit name, stored for validation that the correct OpenDSS model is being accessed.

  • electric_grid_data (fledge.data_interface.ElectricGridData) – (fledge.data_interface.ElectricGridData): Electric grid data object, stored for possible reinitialization of the OpenDSS model.

class fledge.electric_grid_models.ElectricGridDEROperationResults(**kwargs)#

Bases: ResultsBase

class fledge.electric_grid_models.ElectricGridOperationResults(**kwargs)#

Bases: ElectricGridDEROperationResults

class fledge.electric_grid_models.ElectricGridDLMPResults(**kwargs)#

Bases: ResultsBase

class fledge.electric_grid_models.PowerFlowSolution#

Bases: object

Power flow solution object consisting of DER power vector and the corresponding solution for nodal voltage vector / branch power vector and total loss (all complex valued).

class fledge.electric_grid_models.PowerFlowSolutionFixedPoint#

Bases: PowerFlowSolution

Fixed point power flow solution object.

static check_solution_conditions(electric_grid_model, node_power_vector_wye_initial_no_source, node_power_vector_delta_initial_no_source, node_power_vector_wye_candidate_no_source, node_power_vector_delta_candidate_no_source, node_voltage_vector_initial_no_source)#
Check conditions for fixed-point solution existence, uniqueness and non-singularity for

given power vector candidate and initial point.

  • Conditions are formulated according to: <https://arxiv.org/pdf/1702.03310.pdf>

  • Note the performance issues of this condition check algorithm due to the requirement for matrix inversions / solving of linear equations.

Parameters:
  • electric_grid_model (ElectricGridModelDefault) –

  • node_power_vector_wye_initial_no_source (numpy.ndarray) –

  • node_power_vector_delta_initial_no_source (numpy.ndarray) –

  • node_power_vector_wye_candidate_no_source (numpy.ndarray) –

  • node_power_vector_delta_candidate_no_source (numpy.ndarray) –

  • node_voltage_vector_initial_no_source (numpy.ndarray) –

Return type:

bool

static get_voltage(electric_grid_model, der_power_vector, outer_iteration_limit=100, outer_solution_algorithm='check_solution', power_candidate_iteration_limit=100, power_candidate_reduction_factor=0.5, voltage_iteration_limit=100, voltage_tolerance=0.01)#

Get nodal voltage vector by solving with the fixed point algorithm.

  • Initial DER power vector / node voltage vector must be a valid solution to te fixed-point equation, e.g., a previous solution from a past operation point.

  • Fixed point equation according to: <https://arxiv.org/pdf/1702.03310.pdf>

Parameters:
Return type:

numpy.ndarray

static get_branch_power(electric_grid_model, node_voltage_vector)#

Get branch power vectors by calculating power flow with given nodal voltage.

  • Returns two branch power vectors, where branch_power_vector_1 represents the “from”-direction and branch_power_vector_2 represents the “to”-direction.

Parameters:
static get_loss(electric_grid_model, node_voltage_vector)#

Get total electric losses with given nodal voltage.

Parameters:
class fledge.electric_grid_models.PowerFlowSolutionZBus#

Bases: PowerFlowSolutionFixedPoint

Implicit Z-bus power flow solution object.

static check_solution_conditions(*args, **kwargs)#
Check conditions for fixed-point solution existence, uniqueness and non-singularity for

given power vector candidate and initial point.

  • Conditions are formulated according to: <https://arxiv.org/pdf/1702.03310.pdf>

  • Note the performance issues of this condition check algorithm due to the requirement for matrix inversions / solving of linear equations.

static get_voltage(electric_grid_model, der_power_vector, voltage_iteration_limit=100, voltage_tolerance=0.01, **kwargs)#

Get nodal voltage vector by solving with the implicit Z-bus method.

Parameters:
Return type:

numpy.ndarray

class fledge.electric_grid_models.PowerFlowSolutionOpenDSS#

Bases: PowerFlowSolution

OpenDSS power flow solution object.

static get_voltage(electric_grid_model)#

Get nodal voltage vector by solving OpenDSS model.

  • OpenDSS model must be readily set up, with the desired power being set for all DERs.

Parameters:

electric_grid_model (ElectricGridModelOpenDSS) –

static get_branch_power()#

Get branch power vectors by solving OpenDSS model.

  • OpenDSS model must be readily set up, with the desired power being set for all DERs.

static get_loss()#

Get total loss by solving OpenDSS model.

  • OpenDSS model must be readily set up, with the desired power being set for all DERs.

class fledge.electric_grid_models.LinearElectricGridModel#

Bases: object

Abstract linear electric model object, consisting of the sensitivity matrices for voltage / voltage magnitude / squared branch power / active loss / reactive loss by changes in nodal wye power / nodal delta power.

Note

This abstract class only defines the expected variables of linear electric grid model objects, but does not implement any functionality.

Variables:
  • electric_grid_model (ElectricGridModelDefault) – Electric grid model object.

  • power_flow_solution (PowerFlowSolution) – Reference power flow solution object.

  • sensitivity_voltage_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active wye power vector.

  • sensitivity_voltage_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive wye power vector.

  • sensitivity_voltage_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active delta power vector.

  • sensitivity_voltage_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive delta power vector.

  • sensitivity_voltage_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER active power vector.

  • sensitivity_voltage_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER reactive power vector.

  • sensitivity_voltage_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active wye power vector.

  • sensitivity_voltage_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive wye power vector.

  • sensitivity_voltage_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active delta power vector.

  • sensitivity_voltage_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive delta power vector.

  • sensitivity_voltage_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER active power vector.

  • sensitivity_voltage_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER reactive power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER active power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER active power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER reactive power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER active power vector.

  • sensitivity_branch_power_1_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER active power vector.

  • sensitivity_branch_power_2_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER reactive power vector.

  • sensitivity_loss_active_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active wye power vector.

  • sensitivity_loss_active_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive wye power vector.

  • sensitivity_loss_active_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active delta power vector.

  • sensitivity_loss_active_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive delta power vector.

  • sensitivity_loss_active_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER active power vector.

  • sensitivity_loss_active_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER reactive power vector.

  • sensitivity_loss_reactive_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active wye power vector.

  • sensitivity_loss_reactive_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive wye power vector.

  • sensitivity_loss_reactive_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active delta power vector.

  • sensitivity_loss_reactive_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive delta power vector.

  • sensitivity_loss_reactive_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER active power vector.

  • sensitivity_loss_reactive_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER reactive power vector.

define_optimization_variables(optimization_problem)#

Define decision variables for given optimization_problem.

Parameters:

optimization_problem (OptimizationProblem) –

define_optimization_constraints(optimization_problem, timestep_index=slice(None, None, None), node_voltage_magnitude_vector_minimum=None, node_voltage_magnitude_vector_maximum=None, branch_power_magnitude_vector_maximum=None)#

Define constraints to express the linear electric grid model equations for given optimization_problem.

Parameters:
  • optimization_problem (OptimizationProblem) –

  • node_voltage_magnitude_vector_minimum (numpy.ndarray | None) –

  • node_voltage_magnitude_vector_maximum (numpy.ndarray | None) –

  • branch_power_magnitude_vector_maximum (numpy.ndarray | None) –

class fledge.electric_grid_models.LinearElectricGridModelGlobal#

Bases: LinearElectricGridModel

Linear electric grid model object based on global approximations, consisting of the sensitivity matrices for voltage / voltage magnitude / squared branch power / active loss / reactive loss by changes in nodal wye power / nodal delta power.

Syntax:
  • LinearElectricGridModelGlobal(electric_grid_model, power_flow_solution): Instantiate linear electric grid model object for given electric_grid_model and power_flow_solution.

  • LinearElectricGridModelGlobal(scenario_name): Instantiate linear electric grid model for given scenario_name. The required electric_grid_model is obtained for given scenario_name and the power_flow_solution is obtained for nominal power conditions.

Parameters:
Variables:
  • electric_grid_model (ElectricGridModelDefault) – Electric grid model object.

  • power_flow_solution (PowerFlowSolution) – Reference power flow solution object.

  • sensitivity_voltage_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active wye power vector.

  • sensitivity_voltage_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive wye power vector.

  • sensitivity_voltage_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active delta power vector.

  • sensitivity_voltage_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive delta power vector.

  • sensitivity_voltage_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER active power vector.

  • sensitivity_voltage_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER reactive power vector.

  • sensitivity_voltage_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active wye power vector.

  • sensitivity_voltage_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive wye power vector.

  • sensitivity_voltage_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active delta power vector.

  • sensitivity_voltage_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive delta power vector.

  • sensitivity_voltage_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER active power vector.

  • sensitivity_voltage_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER reactive power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER active power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER active power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER reactive power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER active power vector.

  • sensitivity_branch_power_1_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER active power vector.

  • sensitivity_branch_power_2_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER reactive power vector.

  • sensitivity_loss_active_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active wye power vector.

  • sensitivity_loss_active_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive wye power vector.

  • sensitivity_loss_active_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active delta power vector.

  • sensitivity_loss_active_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive delta power vector.

  • sensitivity_loss_active_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER active power vector.

  • sensitivity_loss_active_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER reactive power vector.

  • sensitivity_loss_reactive_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active wye power vector.

  • sensitivity_loss_reactive_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive wye power vector.

  • sensitivity_loss_reactive_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active delta power vector.

  • sensitivity_loss_reactive_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive delta power vector.

  • sensitivity_loss_reactive_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER active power vector.

  • sensitivity_loss_reactive_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER reactive power vector.

class fledge.electric_grid_models.LinearElectricGridModelLocal#

Bases: LinearElectricGridModel

Linear electric grid model object based on local approximations, consisting of the sensitivity matrices for voltage / voltage magnitude / squared branch power / active loss / reactive loss by changes in nodal wye power / nodal delta power.

Syntax:
  • LinearElectricGridModelLocal(electric_grid_model, power_flow_solution): Instantiate linear electric grid model object for given electric_grid_model and power_flow_solution.

  • LinearElectricGridModelLocal(scenario_name): Instantiate linear electric grid model for given scenario_name. The required electric_grid_model is obtained for given scenario_name and the power_flow_solution is obtained for nominal power conditions.

Parameters:
Variables:
  • electric_grid_model (ElectricGridModelDefault) – Electric grid model object.

  • power_flow_solution (PowerFlowSolution) – Reference power flow solution object.

  • sensitivity_voltage_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active wye power vector.

  • sensitivity_voltage_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive wye power vector.

  • sensitivity_voltage_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by active delta power vector.

  • sensitivity_voltage_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by reactive delta power vector.

  • sensitivity_voltage_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER active power vector.

  • sensitivity_voltage_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for complex voltage vector by DER reactive power vector.

  • sensitivity_voltage_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active wye power vector.

  • sensitivity_voltage_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive wye power vector.

  • sensitivity_voltage_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by active delta power vector.

  • sensitivity_voltage_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by reactive delta power vector.

  • sensitivity_voltage_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER active power vector.

  • sensitivity_voltage_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for voltage magnitude vector by DER reactive power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER active power vector.

  • sensitivity_branch_power_1_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_magnitude_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER active power vector.

  • sensitivity_branch_power_2_magnitude_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for branch flow power magnitude vector 2 by DER reactive power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active wye power vector.

  • sensitivity_branch_power_1_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive wye power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by active delta power vector.

  • sensitivity_branch_power_1_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 (‘from’ direction) by reactive delta power vector.

  • sensitivity_branch_power_1_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER active power vector.

  • sensitivity_branch_power_1_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 1 by DER reactive power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active wye power vector.

  • sensitivity_branch_power_2_squared_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive wye power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by active delta power vector.

  • sensitivity_branch_power_2_squared_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 (‘to’ direction) by reactive delta power vector.

  • sensitivity_branch_power_2_squared_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER active power vector.

  • sensitivity_branch_power_2_squared_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for squared branch flow power vector 2 by DER reactive power vector.

  • sensitivity_loss_active_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active wye power vector.

  • sensitivity_loss_active_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive wye power vector.

  • sensitivity_loss_active_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by active delta power vector.

  • sensitivity_loss_active_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by reactive delta power vector.

  • sensitivity_loss_active_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER active power vector.

  • sensitivity_loss_active_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for active loss by DER reactive power vector.

  • sensitivity_loss_reactive_by_power_wye_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active wye power vector.

  • sensitivity_loss_reactive_by_power_wye_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive wye power vector.

  • sensitivity_loss_reactive_by_power_delta_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by active delta power vector.

  • sensitivity_loss_reactive_by_power_delta_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by reactive delta power vector.

  • sensitivity_loss_reactive_by_der_power_active (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER active power vector.

  • sensitivity_loss_reactive_by_der_power_reactive (scipy.sparse.spmatrix) – Sensitivity matrix for reactive loss by DER reactive power vector.

fledge.thermal_grid_models#

Thermal grid models module.

class fledge.thermal_grid_models.ThermalGridModel(scenario_name)#

Bases: object

Thermal grid model object.

Parameters:

scenario_name (str) –

class fledge.thermal_grid_models.ThermalPowerFlowSolution#

Bases: object

Thermal grid power flow solution object.

class fledge.thermal_grid_models.ThermalGridOperationResults(**kwargs)#

Bases: ResultsBase

class fledge.thermal_grid_models.ThermalGridDLMPResults(**kwargs)#

Bases: ResultsBase

class fledge.thermal_grid_models.LinearThermalGridModel(thermal_grid_model, thermal_power_flow_solution)#

Bases: object

Linear thermal grid model object.

Parameters:
define_optimization_variables(optimization_problem)#

Define decision variables for given optimization_problem.

Parameters:

optimization_problem (OptimizationProblem) –

define_optimization_constraints(optimization_problem, timestep_index=slice(None, None, None), node_head_vector_minimum=None, branch_flow_vector_maximum=None)#

Define constraints to express the linear thermal grid model equations for given optimization_problem.

Parameters:
  • optimization_problem (OptimizationProblem) –

  • node_head_vector_minimum (numpy.ndarray | None) –

  • branch_flow_vector_maximum (numpy.ndarray | None) –

fledge.der_models#

Distributed energy resource (DER) models.

class fledge.der_models.DERModel(der_data, der_name)#

Bases: object

DER model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.DERModelOperationResults(**kwargs)#

Bases: ResultsBase

class fledge.der_models.FixedDERModel(der_data, der_name)#

Bases: DERModel

Fixed DER model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FixedLoadModel(der_data, der_name)#

Bases: FixedDERModel

Fixed load model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FixedEVChargerModel(der_data, der_name)#

Bases: FixedDERModel

EV charger model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FixedGeneratorModel(der_data, der_name)#

Bases: FixedDERModel

Fixed generator model object, representing a generic generator with fixed nominal output.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleDERModel(der_data, der_name)#

Bases: DERModel

Flexible DER model, e.g., flexible load, object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleLoadModel(der_data, der_name)#

Bases: FlexibleDERModel

Flexible load model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleEVChargerModel(der_data, der_name)#

Bases: FlexibleDERModel

Flexible EV charger model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleGeneratorModel(der_data, der_name)#

Bases: FlexibleDERModel

Fixed generator model object, representing a generic generator with fixed nominal output.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.StorageModel(der_data, der_name)#

Bases: FlexibleDERModel

Energy storage model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleBuildingModel(der_data, der_name)#

Bases: FlexibleDERModel

Flexible load model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.CoolingPlantModel(der_data, der_name)#

Bases: FlexibleDERModel

Cooling plant model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.HeatPumpModel(der_data, der_name)#

Bases: FlexibleDERModel

Heat pump model object.

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.FlexibleCHP(der_data, der_name)#

Bases: FlexibleDERModel

Parameters:
  • der_data (DERData) –

  • der_name (str) –

class fledge.der_models.DERModelSetOperationResults(**kwargs)#

Bases: ElectricGridDEROperationResults

class fledge.der_models.DERModelSet#

Bases: DERModelSetBase

DER model set object.

fledge.der_models.make_der_model(der_name, der_data)#

Factory method for DER models, makes appropriate DER model type for given der_name.

Parameters:
  • der_name (str) –

  • der_data (DERData) –

Return type:

DERModel

fledge.data_interface#

Database interface.

fledge.data_interface.recreate_database(additional_data_paths=[])#

Recreate SQLITE database from SQL schema file and CSV files in the data path / additional data paths.

Parameters:

additional_data_paths (List[str]) –

Return type:

None

fledge.data_interface.connect_database()#

Connect to the database and return connection handle.

Return type:

Connection

class fledge.data_interface.ScenarioData(scenario_name, database_connection=None)#

Bases: object

Scenario data object.

Parameters:

scenario_name (str) –

parse_parameters_column(column)#

Parse parameters into one column of a dataframe.

  • Replace strings that match parameter_name with parameter_value.

  • Other strings are are directly parsed into numbers.

  • If a string doesn’t match any match parameter_name and cannot be parsed, it is replaced with NaN.

  • Expects column to be passed as np.ndarray rather than directly as pd.Series (for performance reasons).

Parameters:

column (numpy.ndarray) –

parse_parameters_dataframe(dataframe, excluded_columns=None)#

Parse parameters into a dataframe.

  • Applies parse_parameters_column for all string columns.

  • Columns in excluded_columns are not parsed. By default this includes _name, _type, connection columns.

Parameters:
  • dataframe (pandas.DataFrame) –

  • excluded_columns (list | None) –

class fledge.data_interface.ElectricGridData(scenario_name, database_connection=None)#

Bases: object

Electric grid data object.

Parameters:

scenario_name (str) –

class fledge.data_interface.ThermalGridData(scenario_name, database_connection=None)#

Bases: object

Thermal grid data object.

Parameters:

scenario_name (str) –

class fledge.data_interface.DERData#

Bases: object

DER data object.

class fledge.data_interface.PriceData#

Bases: object

Price data object.

fledge.utils#

Utility functions module.

class fledge.utils.ObjectBase#

Bases: object

FLEDGE object base class, which extends the Python object base class.

  • Requires all attributes, i.e. parameters or object variables, to be defined with type declaration at the beginning of the class definition. Setting a value to an attribute which has not been defined will raise an error. This is to ensure consistent definition structure of FLEDGE classes.

  • String representation of the object is the concatenation of the string representation of all its attributes. Thus, printing the object will print all its attributes.

Example

Attributes should be defined in the beginning of the class definition as follows:

class ExampleClass(ObjectBase):

    example_attribute1: str
    example_attribute2: pd.DataFrame

In this case, example_attribute1 and example_attribute2 are valid attributes of the class.

copy()#

Return a copy of this object. A new object will be created with a copy of the calling object’s attributes. Modifications to the attributes of the copy will not be reflected in the original object.

class fledge.utils.ResultsBase(**kwargs)#

Bases: ObjectBase

Results object base class.

save(results_path)#

Store results to files at given results path.

  • Each results variable / attribute will be stored as separate file with the attribute name as file name.

  • Pandas Series / DataFrame are stored to CSV.

  • Other objects are stored to pickle binary file (PKL).

Parameters:

results_path (str) –

load(results_path)#

Load results from given path.

Parameters:

results_path (str) –

class fledge.utils.OptimizationProblem#

Bases: object

Optimization problem object for use with CVXPY.

class fledge.utils.StandardForm#

Bases: object

Standard form object for linear program, which is defined as A @ x <= b.

fledge.utils.starmap(function, argument_sequence, keyword_arguments=None)#

Utility function to execute a function for a sequence of arguments, effectively replacing a for-loop. Allows running repeated function calls in-parallel, based on Python’s multiprocessing module.

  • If configuration parameter run_parallel is set to True, execution is passed to starmap of multiprocessing pool, hence running the function calls in parallel.

  • Otherwise, execution is passed to itertools.starmap, which is the non-parallel equivalent.

Parameters:
  • function (Callable) –

  • argument_sequence (Iterable[tuple]) –

  • keyword_arguments (dict | None) –

Return type:

list

fledge.utils.chunk_dict(dict_in, chunk_count=4)#

Divide dictionary into equally sized chunks.

Parameters:
  • dict_in (dict) –

  • chunk_count (int) –

fledge.utils.chunk_list(list_in, chunk_count=4)#

Divide list into equally sized chunks.

Parameters:
  • list_in (Iterable | Sized) –

  • chunk_count (int) –

fledge.utils.log_time(label, log_level='debug', logger_object=<Logger fledge.utils (INFO)>)#

Log start / end message and time duration for given label.

  • When called with given label for the first time, will log start message.

  • When called subsequently with the same / previously used label, will log end message and time duration since logging the start message.

  • The log level for start / end messages can be given as keyword argument, By default, messages are logged as debug messages.

  • The logger object can be given as keyword argument. By default, uses utils.logger as logger.

  • Start message: “Starting label.”

  • End message: “Completed label in duration seconds.”

Parameters:
  • label (str) – Label for the start / end message.

  • log_level (str) –

  • logger_object (Logger) –

Keyword Arguments:
  • log_level (str) – Log level to which the start / end messages are output. Choices: ‘debug’, ‘info’. Default: ‘debug’.

  • logger_object (logging.logger.Logger) – Logger object to which the start / end messages are output. Default: utils.logger.

fledge.utils.get_index(index_set, raise_empty_index_error=True, **levels_values)#

Utility function for obtaining the integer index array for given index set / level / value list combination.

Syntax:
  • get_index(electric_grid_model.nodes, node_type='source', phase=1): Get index array for entries in index set electric_grid_model.nodes with given node_type and phase.

Parameters:
  • index_set (pd.Index) – Index set, e.g., electric_grid_model.nodes.

  • raise_empty_index_error (bool) –

Keyword Arguments:
  • raise_empty_index_error (bool) – If true, raise an exception if obtained index array is empty. This is the default behavior, because it is usually caused by an invalid level / value combination.

  • level (value) – All other keyword arguments are interpreted as level / value combinations, where level must correspond to a level name of the index set.

fledge.utils.get_element_phases_array(element)#

Utility function for obtaining the list of connected phases for given element data.

Parameters:

element (pandas.Series) –

fledge.utils.get_element_phases_string(element)#

Utility function for obtaining the OpenDSS phases string for given element data.

Parameters:

element (pandas.Series) –

fledge.utils.get_timestamp(time=None)#

Generate formatted timestamp string, e.g., for saving results with timestamp.

Parameters:

time (datetime | None) –

Return type:

str

fledge.utils.get_results_path(base_name, scenario_name=None)#

Generate results path, which is a new subfolder in the results directory. The subfolder name is assembled of the given base name, scenario name and current timestamp. The new subfolder is created on disk along with this.

  • Non-alphanumeric characters are removed from base_name and scenario_name.

  • If is a script file path or __file__ is passed as base_name, the base file name without extension will be taken as base name.

Parameters:
  • base_name (str) –

  • scenario_name (str | None) –

Return type:

str

fledge.utils.get_alphanumeric_string(string)#

Create lowercase alphanumeric string from given string, replacing non-alphanumeric characters with underscore.

Parameters:

string (str) –

fledge.utils.launch(path)#

Launch the file at given path with its associated application. If path is a directory, open in file explorer.

fledge.utils.get_building_model(*args, **kwargs)#

Wrapper function for cobmo.building_model.BuildingModel with caching support for better performance.

fledge.utils.write_figure_plotly(figure, results_path, file_format='png')#

Utility function for writing / storing plotly figure to output file. File format can be given with file_format keyword argument, otherwise the default is obtained from config parameter plots/file_format.

  • results_path should be given as file name without file extension, because the file extension is appended automatically based on given file_format.

  • Valid file formats: ‘png’, ‘jpg’, ‘jpeg’, ‘webp’, ‘svg’, ‘pdf’, ‘html’, ‘json’

Parameters:
  • figure (plotly.graph_objects.Figure) –

  • results_path (str) –

fledge.config#

Configuration module.

fledge.config.get_config()#

Load the configuration dictionary.

  • Default configuration is obtained from ./fledge/config_default.yml.

  • Custom configuration is obtained from ./config.yml and overwrites the respective default configuration.

  • ./ denotes the repository base directory.

Return type:

dict

fledge.config.get_logger(name)#

Generate logger with given name.

Parameters:

name (str) –

Return type:

Logger

fledge.config.get_parallel_pool()#

Create multiprocessing / parallel computing pool.

  • Number of parallel processes / workers defaults to number of CPU threads as returned by os.cpu_count().

Return type:

ray.util.multiprocessing.Pool

fledge.config.memoize(name)#

Wrapper for memoize decorator of cache. Invokes memoize with expiry_time from config, but only if caching is enabled for given name in config.