From 2ccf80ad5e8911000e51671d1e154e602a3fd935 Mon Sep 17 00:00:00 2001 From: aitbc Date: Thu, 14 May 2026 23:03:12 +0200 Subject: [PATCH] Fix Coordinator Concrete ML import error for Python 3.13 Coordinator API: - Changed FHEService from module-level instantiation to lazy loading - Added get_fhe_service() function to instantiate on first use - Updated fhe_ml_inference endpoint to use lazy-loaded service - Prevents import-time Concrete ML errors on Python 3.13 Concrete ML requires Python <3.13, but current version is 3.13.5. The FHEService gracefully handles the ImportError, but the module-level instantiation was causing the error during app startup. Lazy loading defers the instantiation until the endpoint is actually called. --- .../zk_applications/routers/ml_zk_proofs.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/coordinator-api/src/app/contexts/zk_applications/routers/ml_zk_proofs.py b/apps/coordinator-api/src/app/contexts/zk_applications/routers/ml_zk_proofs.py index b0e403f4..15742be1 100755 --- a/apps/coordinator-api/src/app/contexts/zk_applications/routers/ml_zk_proofs.py +++ b/apps/coordinator-api/src/app/contexts/zk_applications/routers/ml_zk_proofs.py @@ -10,7 +10,16 @@ from ....services.zk_proofs import ZKProofService router = APIRouter(prefix="/v1/ml-zk", tags=["ml-zk"]) zk_service = ZKProofService() -fhe_service = FHEService() + +# Lazy instantiation of FHEService to avoid import-time errors +_fhe_service: FHEService | None = None + +def get_fhe_service() -> FHEService: + """Get or create FHEService instance""" + global _fhe_service + if _fhe_service is None: + _fhe_service = FHEService() + return _fhe_service @router.post("/prove/training") @@ -105,6 +114,8 @@ async def verify_ml_inference(request: Request, verification_request: dict) -> d async def fhe_ml_inference(request: Request, fhe_request: dict) -> dict[str, Any]: """Perform ML inference on encrypted data""" try: + fhe_service = get_fhe_service() + # Setup FHE context context = fhe_service.generate_fhe_context( scheme=fhe_request.get("scheme", "ckks"), provider=fhe_request.get("provider", "tenseal")