From 88805d12869b49a10c55adf3fb3528ed78e83756 Mon Sep 17 00:00:00 2001 From: agent-a6e6ec231c5f7801 Date: Sun, 19 Apr 2026 22:23:55 +0200 Subject: [PATCH] build(agent): new-agents#a6e6ec iteration --- README.md | 3 +++ catopt_grid/bridge.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 4d6a4cd..f1a49c7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,9 @@ Architecture scaffolding: Bridge and Adapters - catopt_grid.adapters: starter adapters (rover_planner, habitat_module) that illustrate mapping local problems to the canonical IR and seed cross-domain interoperability. - This scaffolding is intentionally minimal and designed to evolve into a production-grade interop surface without altering core solver behavior. +Interop helper +- lp_to_ir(lp): Convert a local problem instance to a vendor-agnostic IRObject for cross-domain exchange. Accepts various LocalProblem shapes (core.LocalProblem, admm_lite.LocalProblem) and returns an IRObject carrying dimension/id and lightweight metadata. + Roadmap - Bridge and adapters: evolve to a production-ready interoperability surface with a robust Graph-of-Contracts, versioned schemas, and recoverable delta-sync semantics. - Governance: implement per-message privacy budgets, audit logs, and a DID-based identity layer for secure messaging. diff --git a/catopt_grid/bridge.py b/catopt_grid/bridge.py index ff55f3a..9255201 100644 --- a/catopt_grid/bridge.py +++ b/catopt_grid/bridge.py @@ -87,4 +87,35 @@ __all__ = [ "IRObject", "IRMorphism", "GraphOfContracts", + "lp_to_ir", ] + + +def lp_to_ir(lp: object) -> IRObject: + """Convert a local problem instance to a vendor-agnostic IR Object. + + This helper is intentionally permissive to accommodate multiple LocalProblem + shapes that exist in this repo (e.g., core.LocalProblem and admm_lite.LocalProblem). + It extracts common attributes when present and falls back to sensible defaults. + """ + # Fallback defaults + default_id = getattr(lp, "id", None) or getattr(lp, "name", None) or "lp" + # Dimension could be named differently across implementations + dim = getattr(lp, "dimension", None) + if dim is None: + dim = getattr(lp, "n", None) + try: + dim_int = int(dim) + except Exception: + dim_int = 0 + + # Collect a small amount of metadata if available + meta: Dict[str, object] = {} + if hasattr(lp, "data"): + meta["data"] = getattr(lp, "data") + if hasattr(lp, "lb"): + meta["lb"] = getattr(lp, "lb") + if hasattr(lp, "ub"): + meta["ub"] = getattr(lp, "ub") + + return IRObject(id=str(default_id), dimension=dim_int, metadata=meta)