from typing import Dict, Any def to_canonical(local_problem: Dict[str, Any]) -> Dict[str, Any]: """ Minimal bridge: map a LocalProblem into a canonical representation. In a full MVP this would be a richer translation; here we preserve shape. """ # Expect input like: {"id": "...", "objective": ..., "variables": {...}, "domain": "..."} canonical = { "LocalProblem": { "id": local_problem.get("id"), "domain": local_problem.get("domain", "unknown"), "objective": local_problem.get("objective"), "variables": local_problem.get("variables", {}), } } return canonical def from_canonical(canonical: Dict[str, Any]) -> Dict[str, Any]: """ Inverse mapping from canonical representation back to a LocalProblem-like dict. """ lp = canonical.get("LocalProblem", {}) # Flatten for compatibility with simple local problem consumer return { "id": lp.get("id"), "domain": lp.get("domain", "unknown"), "objective": lp.get("objective"), "variables": lp.get("variables", {}), } class CatOptBridge: """Backward-compatible bridge facade for CatOpt-Graph canonical mapping. This class exposes the canonical mapping methods expected by the tests (static methods to_canonical / from_canonical) and delegates to the module-level implementations for the actual logic. """ @staticmethod def to_canonical(local_problem: Dict[str, Any]) -> Dict[str, Any]: return to_canonical(local_problem) @staticmethod def from_canonical(canonical: Dict[str, Any]) -> Dict[str, Any]: return from_canonical(canonical)