Bondgraph causality inference

This commit is contained in:
2026-07-23 16:02:14 +02:00
parent 65d6012c7f
commit 8e7c463567
5 changed files with 401 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
"""Flat bond-graph network types used by analysis algorithms."""
from __future__ import annotations
from dataclasses import dataclass, field
from bedit_core.models import (
BondConnection,
BondPort,
Component,
ComponentID,
ConnectionID,
PortID,
)
ComponentPath = tuple[ComponentID, ...]
@dataclass(eq=False)
class NetworkPort:
"""A bond port together with its owning component and hierarchical path."""
component_path: ComponentPath
component: Component
port_id: PortID
port: BondPort
@dataclass
class NetworkBond:
"""A bond connection whose endpoints are resolved to flattened ports."""
component_path: ComponentPath
connection_id: ConnectionID
connection: BondConnection
source: NetworkPort
target: NetworkPort
@dataclass
class BondGraphNetwork:
"""All components, bond ports, and bonds in a component hierarchy."""
root: Component
components: list[Component] = field(default_factory=list)
ports: list[NetworkPort] = field(default_factory=list)
bonds: list[NetworkBond] = field(default_factory=list)
def bonds_for(self, port: NetworkPort) -> list[NetworkBond]:
"""Return all bonds incident to ``port``."""
return [
bond
for bond in self.bonds
if bond.source is port or bond.target is port
]
@property
def connections(self) -> list[NetworkBond]:
"""Alias for ``bonds`` for callers using connection terminology."""
return self.bonds