Co-simulation - Xmod

@abstractmethod def get_state(self) -> Dict: """For checkpoint/rollback.""" pass

I'll write it as a with a small demo. """ xmod co-simulation — a lightweight modular co-simulation framework. Models exchange data via ports and advance with their own solvers. Master coordinates time steps and data exchange. """ import numpy as np from dataclasses import dataclass from typing import Dict, List, Callable from abc import ABC, abstractmethod ---------------------------------------------------------------------- Core xmod types ---------------------------------------------------------------------- @dataclass class XModPort: """Defines a data port for a model.""" name: str shape: tuple = () dtype: type = float xmod co-simulation

def connect(self, from_model: str, from_port: str, to_model: str, to_port: str): self.connections.append((from_model, from_port, to_model, to_port)) Master coordinates time steps and data exchange

def step(self, t: float, dt: float, inputs: Dict[str, np.ndarray]) -> XModStep: F_ext = inputs.get("F_ext", np.array([0.0]))[0] # Simple semi-implicit Euler a = (F_ext - self.k * self.x - self.c * self.v) / self.m self.v += a * dt self.x += self.v * dt return XModStep( outputs={"x": np.array([self.x]), "v": np.array([self.v])}, new_time=t + dt ) Callable from abc import ABC