Skip to content

← Back to middlelevel

MiddleLevelDataStorageBasis

Source: Distributed_Design_Optimizer/middlelevel/MiddleLevelDataStorageBasis.py

Middle-level data storage basis module.

This module provides the base class for storing middle-level coupling data in distributed optimization.

Classes

MiddleLevelDataStorageBasis

Inherits from: MiddleLevelDataStorageInterface

Base class for middle level data storage.

Provides thread-safe storage for coupling data exchanged between subsystems in distributed optimization.

Attributes:

_id: List of parent and child subsystem identifiers.
_couplingdata: List of middle level coupling objects.
_DataLock: Lock for thread-safe access.

Methods

init(self, idparent: str, idchild: str, multiprocessing_lock: object) → None

Initialize the middle level data storage.

Args:

idparent: Identifier of the parent subsystem.
idchild: Identifier of the child subsystem.
multiprocessing_lock: Manager-created lock for multiprocessing.

set_Coupling(self, coupling: CouplingParametersInterface) → None

📐 Pseudocode: Copy coupling parameters to interface storage (Line 11) → Augmented Lagrangian Coordination; Copy coupling data to interface storage (Line 9) → Consensus Augmented Lagrangian Coordination; Copy multipliers and coupling data to interface storage (Line 10) → Sensitivity Based Distributed Programming; Acquire lock on MiddleLevelDataStorage (Line 6), Determine storage slot from ID pair (Line 7) → SubSystemBasis.CopyToMiddleLevel

Store coupling variables from a subsystem.

Acquires the data lock, identifies which slot (parent or child) corresponds to the coupling parameter's neighbor ID, and copies the coupling data into the shared storage.

Args:

coupling: Coupling parameters to store.

get_StoredCoupling(self, id: str) → MiddleLevelCouplingInterface | None

📐 Pseudocode: Copy coupling parameters from interface storage (Line 9) → Augmented Lagrangian Coordination; Copy from interface, prepare auxiliary update (Lines 11, 12) → Consensus Augmented Lagrangian Coordination; Copy multipliers and coupling data from interface storage (Line 6) → Sensitivity Based Distributed Programming; Acquire lock and read coupling data (Line 5) → SubSystemBasis.CopyFromMiddleLevel

Return the stored coupling data for a given subsystem ID (under lock).

NOTE ON ASYMMETRY WITH set_Coupling: set_Coupling(coupling) takes a CouplingParametersInterface and internally calls coupling.CopyToMiddleLevelCoupling(slot) to push data INTO the storage. The mirror operation — pulling data OUT — cannot use the same pattern (i.e. coupling.CopyFromMiddleLevelCoupling called inside this method) because of multiprocessing proxies: when called through a BaseProxy, arguments are pickled to the manager process. Any mutation of the argument happens on the deserialized copy in the manager and is discarded — the caller's original object is never modified. Only return values are sent back across process boundaries. Therefore this method RETURNS the stored data so the caller can apply it locally.

Args:

id: Identifier of the neighbor subsystem whose data to retrieve.

Returns:

The stored MiddleLevelCouplingInterface for the given subsystem,
or None if the coupling data for that slot is None.

get_ID(self) → List[str]

📐 Pseudocode: Get MiddleLevelDataStorage ID pair (Line 3) → SubSystemBasis.CopyFromMiddleLevel; Match CouplingParameters ID against storage ID pair (Line 4) → SubSystemBasis.CopyToMiddleLevel

Get the identifiers of the connected subsystems.

Returns:

List containing parent and child subsystem identifiers.

get_CouplingData(self) → List[MiddleLevelCouplingInterface]

Get all coupling data stored in this middle level.

Returns:

List of middle level coupling objects.

update_state(self, other_storage: Union[MiddleLevelDataStorageInterface, MiddleLevelDataStorageProxy]) → None

Update the state of this MiddleLevelDataStorageBasis from another instance.

This method is necessary for multiprocessing. When subsystems are executed in parallel processes via Parallel.py, the original objects need to be updated with results from the executed copies. This method preserves the memory address of the object's attributes while updating their values.

Args:

other_storage: The source instance containing updated values to copy from.

Note on copy operations: - _id (List[str]): Updated in-place via update_state_listprimitive() to preserve memory address. str elements are immutable, no copy.copy() needed for each element. - _couplingdata (List[MiddleLevelCouplingInterface]): Updated via nested update_state() calls to preserve memory addresses of contained objects. - _DataLock: NOT updated - shared lock resource must remain unchanged.