VeraGridEngine.Utils package

Subpackages

Submodules

VeraGridEngine.Utils.emt_boundary_update_wrapper module

class VeraGridEngine.Utils.emt_boundary_update_wrapper.BoundaryUpdateWrapper[source]

Bases: object

Lightweight interface for EMT boundary updates and forced events.

The class lives in VeraGridEngine.Utils so EMT templates, procedural logic and solver modules can import it statically without pulling one heavy solver or simulation package __init__ into the import graph.

get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the earliest forced event time in (t_prev, t_target].

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

Forced event time or None.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update the runtime parameter vector in place.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None.

VeraGridEngine.Utils.procedural_logic module

class VeraGridEngine.Utils.procedural_logic.AnalogFlipFlopLogic(output_var_name: str, input_expr: Expr | Comparison, set_expr: Expr | Comparison, reset_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Store an analog value when a set/reset latch enters the high state.

bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime output slot and reset the analog latch state.

Parameters:

problem – Bound EMT problem.

Returns:

None

held_value
initialized
input_expr
logic_tpe = 'analog_flipflop'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) AnalogFlipFlopLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped analog flip-flop logic.

reset_expr
set_expr
state
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Apply analog set/reset semantics and update the held value.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.BlockProceduralLogicUpdater(problem: EmtProblemTemplate, logic_entries: List[ProceduralLogicBase])[source]

Bases: BoundaryUpdateWrapper

Boundary updater that delegates runtime decisions to block-attached procedural logic entries.

get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the earliest forced event requested by any procedural logic entry.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

Earliest event in the interval, if any.

logic_entries
problem
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Forward one runtime update to all procedural logic entries.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.DelayedThresholdLatchLogic(monitored_var_name: str, mode_var_name: str, threshold: float, delay: float, reset_delay: float | None = None, name: str = '')[source]

Bases: ProceduralLogicBase

Comparator + timer + latch procedural logic for runtime modes.

The logic watches one state variable, arms a timer when a threshold is crossed, applies a mode change after a delay, and optionally resets after a second delay.

bind(problem: EmtProblemTemplate) None[source]

Resolve the monitored state and runtime mode indices.

Parameters:

problem – Bound EMT problem.

Returns:

None

delay
get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the next exact trip or reset event inside one solver step.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

First pending event in the interval, if any.

get_trace_arrays() Tuple[ndarray, ndarray, ndarray, ndarray, ndarray, ndarray][source]

Return the internal trace arrays as dense numpy arrays.

Returns:

Tuple with times, measurements, comparator, timer, latch, and mode traces.

last_t_prev: float | None
logic_tpe = 'delayed_threshold_latch'
mode_idx
mode_var_name
monitored_idx
monitored_var_name
pending_reset_time: float | None
pending_trip_time: float | None
pickup_time: float | None
remap(var_mapping: Dict[Expr | str, Expr]) DelayedThresholdLatchLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped delayed-threshold latch logic.

reset_applied_solver_time: float | None
reset_applied_time: float | None
reset_delay
threshold
trace_comparator: List[float]
trace_latched: List[float]
trace_measure: List[float]
trace_mode: List[float]
trace_t: List[float]
trace_timer_armed: List[float]
trip_applied_solver_time: float | None
trip_applied_time: float | None
tripped
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Advance the delayed-threshold latch logic and tracing state.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.FixedSampleLogic(output_var_name: str, condition_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Retain the initial truth value of one condition in a runtime mode variable.

bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime output slot for this logic entry.

Parameters:

problem – Bound EMT problem.

Returns:

None

condition_expr
initialized
logic_tpe = 'fixed_sample'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) FixedSampleLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped fixed-sample logic.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Sample the condition once and keep it fixed afterwards.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.FlipFlopLogic(output_var_name: str, set_expr: Expr | Comparison, reset_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Store a binary set/reset latch in a runtime mode variable.

bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime output slot for the latch state.

Parameters:

problem – Bound EMT problem.

Returns:

None

initialized
logic_tpe = 'flipflop'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) FlipFlopLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped flip-flop logic.

reset_expr
set_expr
state
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Apply set/reset semantics and write the resulting latch state.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.GradientLimiterLogic(output_var_name: str, source_expr: Expr | Comparison | float | int | bool, lower_rate_expr: Expr | Comparison | float | int | bool, upper_rate_expr: Expr | Comparison | float | int | bool, name: str = '')[source]

Bases: ProceduralLogicBase

Clamp the rate of change of one procedural value between lower and upper slopes.

bind(problem: EmtProblemTemplate) None[source]

Bind the logic to a concrete EMT problem.

Parameters:

problem – EMT problem owning the block and variable maps.

Returns:

None

held_value
initialized
last_time: float | None
logic_tpe = 'gradient_limiter'
lower_rate_expr
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) GradientLimiterLogic[source]

Clone one logic entry under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped procedural logic entry.

source_expr
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update mode or event parameters before the Newton step.

Parameters:
  • t – Current solver time.

  • x – Current accepted state.

  • params – Runtime parameter vector to mutate in place.

Returns:

None

upper_rate_expr
class VeraGridEngine.Utils.procedural_logic.HardSaturationLogic(output_var_name: str, u_expr: Expr | Comparison, u_min_expr: Expr | Comparison, u_max_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Sample one input and apply hard saturation to a runtime mode variable.

bind(problem: EmtProblemTemplate) None[source]

Bind the logic to a concrete EMT problem.

Parameters:

problem – EMT problem owning the block and variable maps.

Returns:

None

logic_tpe = 'hard_saturation'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) HardSaturationLogic[source]

Clone one logic entry under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped procedural logic entry.

u_expr
u_max_expr
u_min_expr
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update mode or event parameters before the Newton step.

Parameters:
  • t – Current solver time.

  • x – Current accepted state.

  • params – Runtime parameter vector to mutate in place.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.MovingAverageLogic(output_var_name: str, source_expr: Expr | Comparison | float | int | bool, delay_expr: Expr | Comparison | float | int | bool, window_expr: Expr | Comparison | float | int | bool, name: str = '')[source]

Bases: ProceduralLogicBase

Buffer-based moving average with optional delay before the averaging window.

bind(problem: EmtProblemTemplate) None[source]

Bind the logic to a concrete EMT problem.

Parameters:

problem – EMT problem owning the block and variable maps.

Returns:

None

delay_expr
history: List[Tuple[float, float]]
logic_tpe = 'moving_average'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) MovingAverageLogic[source]

Clone one logic entry under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped procedural logic entry.

source_expr
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update mode or event parameters before the Newton step.

Parameters:
  • t – Current solver time.

  • x – Current accepted state.

  • params – Runtime parameter vector to mutate in place.

Returns:

None

window_expr
class VeraGridEngine.Utils.procedural_logic.PickupDropoffLogic(output_var_name: str, bool_expr: Expr | Comparison, pickup_delay_expr: Expr | Comparison, drop_delay_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Implement a delayed pickup/dropoff relay with retained binary state.

bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime output slot and clear the relay timers.

Parameters:

problem – Bound EMT problem.

Returns:

None

bool_expr
drop_delay_expr
drop_started_at: float | None
get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the next exact pickup or dropoff event inside one step.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

First pending relay event in the interval, if any.

initialized
logic_tpe = 'pickup_dropoff'
output_idx
output_var_name
pending_drop_time: float | None
pending_pickup_time: float | None
pickup_delay_expr
pickup_started_at: float | None
remap(var_mapping: Dict[Expr | str, Expr]) PickupDropoffLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped pickup/dropoff logic.

state
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Advance the relay timers and binary state.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.ProceduralLogicBase(name: str = '')[source]

Bases: object

Base class for procedural logic objects attached to symbolic blocks.

Procedural logic is evaluated outside the compiled residual kernels and is intended to drive runtime modes, retained flags, timers, or event scheduling in a structured way.

bind(problem: EmtProblemTemplate) None[source]

Bind the logic to a concrete EMT problem.

Parameters:

problem – EMT problem owning the block and variable maps.

Returns:

None

get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the next exact event time inside the interval if known.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

Event time or None.

logic_tpe = 'base'
name
remap(var_mapping: Dict[Expr | str, Expr]) ProceduralLogicBase[source]

Clone one logic entry under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped procedural logic entry.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update mode or event parameters before the Newton step.

Parameters:
  • t – Current solver time.

  • x – Current accepted state.

  • params – Runtime parameter vector to mutate in place.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.ResetOnRisingEdgeLogic(target_var_name: str, reset_expr: Expr | Comparison, value_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Apply one value reset on the rising edge of a procedural condition.

bind(problem: EmtProblemTemplate) None[source]

Resolve whether the reset target is a state variable or a runtime parameter.

Parameters:

problem – Bound EMT problem.

Returns:

None

initialized
last_reset_high
logic_tpe = 'reset_on_rising_edge'
remap(var_mapping: Dict[Expr | str, Expr]) ResetOnRisingEdgeLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped reset logic.

reset_expr
target_param_idx
target_state_idx
target_var_name
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Apply the reset value only on the rising edge of the reset condition.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

value_expr
class VeraGridEngine.Utils.procedural_logic.SampledValueLogic(output_var_name: str, source_expr: Expr | Comparison, name: str = '')[source]

Bases: ProceduralLogicBase

Sample one expression at each accepted step and store it in a runtime mode variable.

bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime output slot for this sampled value.

Parameters:

problem – Bound EMT problem.

Returns:

None

logic_tpe = 'sampled_value'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) SampledValueLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped sampled-value logic.

source_expr
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Refresh the sampled value using the accepted state.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.StartupHandoverLogic(mode_var_name: str, enable_time_var_name: str, name: str = '')[source]

Bases: ProceduralLogicBase

One-shot startup handover for hybrid EMT converter models.

The logic keeps one retained runtime mode at 0 during the averaged-startup interval and flips it to 1 exactly at t_enable. This lets the DAE stay continuous before the handover while still forcing an exact solver split when the switched bridge becomes electrically active.

bind(problem: EmtProblemTemplate) None[source]

Resolve the retained mode and enable-time runtime indices.

Parameters:

problem – Bound EMT problem.

Returns:

None.

enable_time_idx
enable_time_var_name
get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the exact startup-handover time when it falls inside one solver step.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

Exact handover time or None.

logic_tpe = 'startup_handover'
mode_idx
mode_var_name
remap(var_mapping: Dict[Expr | str, Expr]) StartupHandoverLogic[source]

Clone the logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped startup-handover logic.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update the retained startup mode from the current solver time.

Parameters:
  • t – Current solver time.

  • x – Accepted state vector.

  • params – Runtime parameter vector.

Returns:

None.

class VeraGridEngine.Utils.procedural_logic.ThreePhaseCarrierPwmLogic(mod_a_var_name: str, mod_b_var_name: str, mod_c_var_name: str, gate_a_mode_var_name: str, gate_b_mode_var_name: str, gate_c_mode_var_name: str, omega_sw_var_name: str, carrier_phase_var_name: str, name: str = '')[source]

Bases: ProceduralLogicBase

Regular-sampled three-phase carrier PWM logic.

The logic samples the modulation references at each carrier half-period, computes the exact gate transitions inside that interval, and stores the gate values as retained runtime modes. The symbolic DAE therefore sees piecewise- constant gate parameters instead of symbolic comparator expressions.

bind(problem: EmtProblemTemplate) None[source]

Resolve the variable indices and initialize the first PWM interval.

Parameters:

problem – Bound EMT problem.

Returns:

None.

carrier_phase_idx
carrier_phase_var_name
current_gate
gate_a_idx
gate_a_mode_var_name
gate_b_idx
gate_b_mode_var_name
gate_c_idx
gate_c_mode_var_name
get_next_forced_event_time(t_prev: float, t_target: float) float | None[source]

Return the next PWM gate transition or carrier-boundary event.

Parameters:
  • t_prev – Previous solver time.

  • t_target – Nominal target time.

Returns:

Earliest event in the interval, if any.

initialized
interval_end_time: float | None
logic_tpe = 'three_phase_carrier_pwm'
mod_a_idx
mod_a_var_name
mod_b_idx
mod_b_var_name
mod_c_idx
mod_c_var_name
omega_sw_idx
omega_sw_var_name
pending_transition_gate
pending_transition_time
remap(var_mapping: Dict[Expr | str, Expr]) ThreePhaseCarrierPwmLogic[source]

Clone the PWM logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped PWM logic.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Advance the PWM gate states from the accepted modulation references.

Parameters:
  • t – Current solver time.

  • x – Accepted EMT state vector.

  • params – Runtime parameter vector.

Returns:

None.

class VeraGridEngine.Utils.procedural_logic.TimeDelayLogic(output_var_name: str, source_expr: Expr | Comparison | float | int | bool, delay_expr: Expr | Comparison | float | int | bool, name: str = '')[source]

Bases: ProceduralLogicBase

Sample one input and expose its delayed value through a runtime mode variable.

bind(problem: EmtProblemTemplate) None[source]

Bind the logic to a concrete EMT problem.

Parameters:

problem – EMT problem owning the block and variable maps.

Returns:

None

delay_expr
history: List[Tuple[float, float]]
logic_tpe = 'time_delay'
output_idx
output_var_name
remap(var_mapping: Dict[Expr | str, Expr]) TimeDelayLogic[source]

Clone one logic entry under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped procedural logic entry.

source_expr
update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update mode or event parameters before the Newton step.

Parameters:
  • t – Current solver time.

  • x – Current accepted state.

  • params – Runtime parameter vector to mutate in place.

Returns:

None

class VeraGridEngine.Utils.procedural_logic.ValveStateLogic(mode_var_name: str, valve_type_var_name: str, gate_var_name: str, antiparallel_var_name: str, voltage_eps_var_name: str, current_eps_var_name: str, valve_voltage_var_name: str, valve_current_var_name: str, name: str = '')[source]

Bases: ProceduralLogicBase

Retained conduction-state logic for generic EMT valve blocks.

The logic updates a single retained runtime mode that encodes the active path:

  • +1: forward conduction

  • 0: blocked state

  • -1: reverse conduction through the antiparallel path

antiparallel_idx
antiparallel_var_name
bind(problem: EmtProblemTemplate) None[source]

Resolve the runtime and algebraic indices required by the valve logic.

Parameters:

problem – Bound EMT problem.

Returns:

None.

current_eps_idx
current_eps_var_name
gate_idx
gate_var_name
logic_tpe = 'valve_state'
mode_idx
mode_var_name
remap(var_mapping: Dict[Expr | str, Expr]) ValveStateLogic[source]

Clone the valve logic under a variable remapping.

Parameters:

var_mapping – Variable substitution map.

Returns:

Remapped valve logic.

update(t: float, x: ndarray[tuple[Any, ...], dtype[float64]], params: ndarray[tuple[Any, ...], dtype[float64]]) None[source]

Update the retained conduction-path mode from the accepted EMT state.

Parameters:
  • t – Current solver time.

  • x – Accepted EMT state vector.

  • params – Flat runtime parameter vector.

Returns:

None.

valve_current_idx
valve_current_var_name
valve_type_idx
valve_type_var_name
valve_voltage_idx
valve_voltage_var_name
voltage_eps_idx
voltage_eps_var_name
VeraGridEngine.Utils.procedural_logic.aflipflop(x: Expr | Comparison, boolset: Expr | Comparison, boolreset: Expr | Comparison, output: Var | str, name: str = '') AnalogFlipFlopLogic[source]

Build the procedural equivalent of PowerFactory aflipflop.

Parameters:
  • x – Analog expression to store while the internal state is high.

  • boolset – Set condition.

  • boolreset – Reset condition.

  • output – Runtime mode variable receiving the held analog value.

  • name – Optional logic name.

Returns:

Analog flip-flop procedural logic entry.

VeraGridEngine.Utils.procedural_logic.bool_and(*args: Expr | Comparison | float | int) Expr[source]

Build the boolean AND of one or more procedural expressions.

Parameters:

args – Boolean-like expressions encoded as 0/1 values.

Returns:

Expression equal to 1.0 only when all inputs are true.

VeraGridEngine.Utils.procedural_logic.bool_eor(left: Expr | Comparison | float | int, right: Expr | Comparison | float | int) Expr[source]

Build the exclusive-OR of two procedural expressions.

Parameters:
  • left – Left boolean-like expression.

  • right – Right boolean-like expression.

Returns:

Expression equal to 1.0 only when exactly one input is true.

VeraGridEngine.Utils.procedural_logic.bool_nand(*args: Expr | Comparison | float | int) Expr[source]

Build the boolean NAND of one or more procedural expressions.

Parameters:

args – Boolean-like expressions encoded as 0/1 values.

Returns:

Expression equal to the negated AND of the inputs.

VeraGridEngine.Utils.procedural_logic.bool_nor(*args: Expr | Comparison | float | int) Expr[source]

Build the boolean NOR of one or more procedural expressions.

Parameters:

args – Boolean-like expressions encoded as 0/1 values.

Returns:

Expression equal to the negated OR of the inputs.

VeraGridEngine.Utils.procedural_logic.bool_not(arg: Expr | Comparison | float | int) Expr[source]

Build the boolean NOT of one procedural expression.

Parameters:

arg – Boolean-like expression encoded as 0/1.

Returns:

Expression equal to 1.0 when the input is false.

VeraGridEngine.Utils.procedural_logic.bool_or(*args: Expr | Comparison | float | int) Expr[source]

Build the boolean OR of one or more procedural expressions.

Parameters:

args – Boolean-like expressions encoded as 0/1 values.

Returns:

Expression equal to 1.0 when at least one input is true.

VeraGridEngine.Utils.procedural_logic.build_boundary_updater_from_block(problem: EmtProblemTemplate) BlockProceduralLogicUpdater | None[source]

Build a boundary updater from the full procedural logic attached to problem.sys_block.

Parameters:

problem – EMT problem containing the root block.

Returns:

Boundary updater or None.

VeraGridEngine.Utils.procedural_logic.build_procedural_logic_entry(data: Dict[str, Any]) ProceduralLogicBase[source]

Deserialize one procedural logic entry.

Parameters:

data – Serialized logic config.

Returns:

Procedural logic object.

VeraGridEngine.Utils.procedural_logic.clone_procedural_logic_entries(entries: List[ProceduralLogicBase], var_mapping: Dict[Expr | str, Expr]) List[ProceduralLogicBase][source]

Clone procedural logic entries under a variable remapping.

Parameters:
  • entries – Source procedural logic entries.

  • var_mapping – Mapping from old variables/names to remapped expressions.

Returns:

Remapped procedural logic entries.

VeraGridEngine.Utils.procedural_logic.delay(input_expr: Expr | Comparison | float | int | bool, T: Expr | Comparison | float | int | bool, output: Var | str, name: str = '') TimeDelayLogic[source]

Build the procedural equivalent of PowerFactory delay.

Parameters:
  • input_expr – Source expression to be delayed.

  • T – Delay in seconds.

  • output – Runtime mode variable receiving the delayed value.

  • name – Optional logic name.

Returns:

Time-delay procedural logic entry.

VeraGridEngine.Utils.procedural_logic.fixed_sample(output: Var | str, when: Expr | Comparison, name: str = '') FixedSampleLogic[source]

Build a fixed-sample selector that stores a boolean condition at initialization.

Parameters:
  • output – Runtime mode variable receiving the retained value.

  • when – Condition sampled at initialization time.

  • name – Optional logic name.

Returns:

Fixed-sample procedural logic entry.

VeraGridEngine.Utils.procedural_logic.flipflop(boolset: Expr | Comparison, boolreset: Expr | Comparison, output: Var | str, name: str = '') FlipFlopLogic[source]

Build the procedural equivalent of PowerFactory flipflop.

Parameters:
  • boolset – Set condition.

  • boolreset – Reset condition.

  • output – Runtime mode variable storing the logical state.

  • name – Optional logic name.

Returns:

Flip-flop procedural logic entry.

VeraGridEngine.Utils.procedural_logic.gradlim_const(input_expr: Expr | Comparison | float | int | bool, gradmin: Expr | Comparison | float | int | bool, gradmax: Expr | Comparison | float | int | bool, output: Var | str, name: str = '') GradientLimiterLogic[source]

Build the procedural equivalent of PowerFactory gradlim_const.

Parameters:
  • input_expr – Source expression to be rate-limited.

  • gradmin – Lower slope limit.

  • gradmax – Upper slope limit.

  • output – Runtime mode variable receiving the limited value.

  • name – Optional logic name.

Returns:

Gradient-limiter procedural logic entry.

VeraGridEngine.Utils.procedural_logic.hard_saturation(output: Var | str, u: Expr | Comparison, u_min: Expr | Comparison, u_max: Expr | Comparison, name: str = '') HardSaturationLogic[source]

Build one procedural hard-saturation entry updated outside Newton residuals.

Parameters:
  • output – Runtime mode variable receiving saturated value.

  • u – Unsaturated input expression.

  • u_min – Lower saturation bound.

  • u_max – Upper saturation bound.

  • name – Optional logic name.

Returns:

Hard-saturation procedural logic entry.

VeraGridEngine.Utils.procedural_logic.ifelse(boolexpr: Expr | Comparison | float | int, when_true: Expr | Comparison | float | int, when_false: Expr | Comparison | float | int) Expr[source]

Reject equation-level ifelse usage in the public procedural API.

Parameters:
  • boolexpr – Switching condition.

  • when_true – Value chosen for the true branch.

  • when_false – Value chosen for the false branch.

Returns:

Never returns because public equation-level selection is blocked.

VeraGridEngine.Utils.procedural_logic.lastvalue(input_expr: Expr | Comparison, output: Var | str, name: str = '') SampledValueLogic[source]

Build the procedural equivalent of PowerFactory lastvalue.

Parameters:
  • input_expr – Source expression to be sampled.

  • output – Runtime mode variable receiving the sampled value.

  • name – Optional logic name.

Returns:

Sampled-value procedural logic entry.

VeraGridEngine.Utils.procedural_logic.movingavg(input_expr: Expr | Comparison | float | int | bool, Tdel: Expr | Comparison | float | int | bool, Tlength: Expr | Comparison | float | int | bool, output: Var | str, name: str = '') MovingAverageLogic[source]

Build the procedural equivalent of PowerFactory movingavg.

Parameters:
  • input_expr – Source expression to be averaged.

  • Tdel – Delay before the averaging window.

  • Tlength – Averaging window length in seconds.

  • output – Runtime mode variable receiving the averaged value.

  • name – Optional logic name.

Returns:

Moving-average procedural logic entry.

VeraGridEngine.Utils.procedural_logic.picdro(boolexpr: Expr | Comparison, Tpick: Expr | Comparison, Tdrop: Expr | Comparison, output: Var | str, name: str = '') PickupDropoffLogic[source]

Build the procedural equivalent of PowerFactory picdro.

Parameters:
  • boolexpr – Relay driving condition.

  • Tpick – Pickup delay.

  • Tdrop – Dropoff delay.

  • output – Runtime mode variable storing the relay state.

  • name – Optional logic name.

Returns:

Pickup/dropoff procedural logic entry.

VeraGridEngine.Utils.procedural_logic.picdro_const(boolexpr: Expr | Comparison, Tpick: Expr | Comparison, Tdrop: Expr | Comparison, output: Var | str, name: str = '') PickupDropoffLogic[source]

Build the procedural equivalent of PowerFactory picdro_const.

Parameters:
  • boolexpr – Relay driving condition.

  • Tpick – Pickup delay.

  • Tdrop – Dropoff delay.

  • output – Runtime mode variable storing the relay state.

  • name – Optional logic name.

Returns:

Pickup/dropoff procedural logic entry.

VeraGridEngine.Utils.procedural_logic.pickup_dropoff(output: Var | str, boolexpr: Expr | Comparison, Tpick: Expr | Comparison, Tdrop: Expr | Comparison, name: str = '') PickupDropoffLogic[source]

Build a pickup/dropoff relay-style procedural logic entry.

Parameters:
  • output – Runtime mode variable storing the relay state.

  • boolexpr – Pickup/reset driving condition.

  • Tpick – Pickup delay.

  • Tdrop – Dropoff delay.

  • name – Optional logic name.

Returns:

Pickup/dropoff procedural logic entry.

VeraGridEngine.Utils.procedural_logic.procedural_logic_entry_to_dict(entry: ProceduralLogicBase) Dict[str, Any][source]

Serialize one procedural logic entry.

Parameters:

entry – Procedural logic entry.

Returns:

Serialized logic dictionary.

VeraGridEngine.Utils.procedural_logic.procedural_logic_from_dict(entries: List[Dict[str, Any]]) List[ProceduralLogicBase][source]

Deserialize a list of procedural logic entries.

Parameters:

entries – Serialized entries.

Returns:

Procedural logic objects.

VeraGridEngine.Utils.procedural_logic.procedural_logic_to_dict(entries: List[ProceduralLogicBase]) List[Dict[str, Any]][source]

Serialize a list of procedural logic entries.

Parameters:

entries – Logic entries.

Returns:

Serialized representation.

VeraGridEngine.Utils.procedural_logic.reset(var: Var | str, rst: Expr | Comparison, val: Expr | Comparison, name: str = '') ResetOnRisingEdgeLogic[source]

Build the procedural equivalent of PowerFactory reset.

Parameters:
  • var – Target runtime/state variable name.

  • rst – Reset trigger condition.

  • val – Value applied on the rising edge.

  • name – Optional logic name.

Returns:

Reset-on-rising-edge procedural logic entry.

VeraGridEngine.Utils.procedural_logic.sampled_value(output: Var | str, source: Expr | Comparison, name: str = '') SampledValueLogic[source]

Build a sampled runtime value updated outside the Newton residual.

Parameters:
  • output – Runtime mode variable receiving the sampled value.

  • source – Source expression to be evaluated at the accepted sample time.

  • name – Optional logic name.

Returns:

Sampled-value procedural logic entry.

VeraGridEngine.Utils.procedural_logic.select(boolexpr: Expr | Comparison | float | int, when_true: Expr | Comparison | float | int, when_false: Expr | Comparison | float | int) Expr[source]

Reject equation-level select usage in the public procedural API.

Parameters:
  • boolexpr – Switching condition.

  • when_true – Value chosen for the true branch.

  • when_false – Value chosen for the false branch.

Returns:

Never returns because public equation-level selection is blocked.

VeraGridEngine.Utils.procedural_logic.selfix(boolexpr: Expr | Comparison, output: Var | str, name: str = '') FixedSampleLogic[source]

Build the procedural equivalent of PowerFactory selfix.

Parameters:
  • boolexpr – Condition sampled at initialization time.

  • output – Runtime mode variable receiving the retained value.

  • name – Optional logic name.

Returns:

Fixed-sample procedural logic entry.

VeraGridEngine.Utils.procedural_logic.selfix_const(boolexpr: Expr | Comparison, output: Var | str, name: str = '') FixedSampleLogic[source]

Build the procedural equivalent of PowerFactory selfix_const.

Parameters:
  • boolexpr – Condition sampled at initialization time.

  • output – Runtime mode variable receiving the retained value.

  • name – Optional logic name.

Returns:

Fixed-sample procedural logic entry.

VeraGridEngine.Utils.procedural_logic.startup_handover(mode: Var | str, t_enable: Var | str, name: str = '') StartupHandoverLogic[source]

Build one exact-time startup-handover logic entry.

Parameters:
  • mode – Retained mode variable that becomes 1 after the handover time.

  • t_enable – Runtime parameter storing the switching-enable time.

  • name – Optional logic name.

Returns:

Startup-handover procedural logic entry.

VeraGridEngine.Utils.progress_bar module

VeraGridEngine.Utils.progress_bar.print_progress_bar(iteration: int, total: int, length=40, txt='')[source]

Simple text progress bar :param iteration: current iteration (1 based) :param total: total progress :param length: length of the bar in characters :param txt: text to print at the end of the progress bar

VeraGridEngine.Utils.rms_models_types module

VeraGridEngine.Utils.rms_models_types.build_equivalence_classes_dict(grid: MultiCircuit) Tuple[Dict[int, List[int]], Dict[int, List[List[int]]], Dict[int, List[int]]][source]

this functions receives the grid and return a dictionary with clases of equivalence of the dynamic models and a dictionary with clases of equivalence of their variables. :param grid: :type grid: :return: Tuple of:

  • Dict with new uid as keys and lists of equivalent block uids as values

  • Dict with representative uid as keys and lists of lists of equivalent variable uids as values

  • Dict with representative uid as keys and lists of all block uids composing that model (including children)

Return type:

VeraGridEngine.Utils.scores module

class VeraGridEngine.Utils.scores.TechnoEconomicScores[source]

Bases: object

InvestmentScores

arr() ndarray[tuple[Any, ...], dtype[float64]][source]

Return multidimensional metrics for the optimization :return: array of 2 values

capex_score: float
property financial_score: float

Get the financial score: CAPEX + OPEX :return: float

losses_score: float
opex_score: float
overload_score: float
property tech_score
voltage_angle_score: float
voltage_module_score: float
VeraGridEngine.Utils.scores.get_overload_score(loading: ndarray[tuple[Any, ...], dtype[complex128]], branches_cost: ndarray[tuple[Any, ...], dtype[float64]], threshold=1.0) float[source]

Compute overload score by multiplying the loadings above 100% by the associated branch cost. :param loading: load results :param branches_cost: all branch elements from studied grid :param threshold: threshold for overload :return: sum of all costs associated to branch overloads

VeraGridEngine.Utils.scores.get_voltage_module_score(voltage: ndarray[tuple[Any, ...], dtype[complex128]], vm_cost: ndarray[tuple[Any, ...], dtype[float64]], vm_max: ndarray[tuple[Any, ...], dtype[float64]], vm_min: ndarray[tuple[Any, ...], dtype[float64]]) float[source]

Compute voltage module score by multiplying the voltages outside limits by the associated bus costs. :param voltage: voltage results :param vm_cost: Vm cost array :param vm_max: maximum voltage :param vm_min: minimum voltage :return: sum of all costs associated to voltage module deviation

VeraGridEngine.Utils.scores.get_voltage_phase_score(voltage: ndarray[tuple[Any, ...], dtype[complex128]], va_cost: ndarray[tuple[Any, ...], dtype[float64]], va_max: ndarray[tuple[Any, ...], dtype[float64]], va_min: ndarray[tuple[Any, ...], dtype[float64]]) float[source]

Compute voltage phase score by multiplying the phases outside limits by the associated bus costs. :param voltage: voltage results :param va_cost: array of bus angles costs :param va_max: maximum voltage angles :param va_min: minimum voltage angles :return: sum of all costs associated to voltage module deviation

VeraGridEngine.Utils.zip_file_mgmt module

VeraGridEngine.Utils.zip_file_mgmt.open_data_frame_from_zip(file_name_zip, file_name)[source]

Open the csv files from a zip file :param file_name_zip: name of the zip file :param file_name: name of the file within the zip file :return: DataFrame

Module contents