vibe-sketcherDocumentation
Source code for vibesketcher.server.aiccm
"""REST routes for experimental AICCM planning (#194).
The table route serves the engine-pinned capability table; the series route
writes a repeat/shell convergence series for one periodic structure of a
document (the document is not changed); the compare route tabulates finished
members and refuses mismatched conventions. Single AICCM inputs keep using
``POST /api/documents/{id}/periodic/{structure}/input`` with ``model: aiccm``.
"""
from __future__ import annotations
from typing import Any
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, ConfigDict, ValidationError
from vibesketcher.server.store import NotFound, Store
[docs]
class AICCMSeriesRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
spec: dict[str, Any]
extensions: list[tuple[int, int, int]] | None = None
shells: list[tuple[int, int, int]] | None = None
[docs]
class AICCMCompareRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
plan: dict[str, Any]
results: list[dict[str, Any]]
[docs]
def router(store: Store) -> APIRouter:
routes = APIRouter(prefix="/api", tags=["aiccm"])
@routes.get("/periodic/aiccm/capabilities")
def aiccm_capabilities() -> dict[str, Any]:
"""The vibe-qc-version-pinned variant x reference x dimension table."""
from vibesketcher.inputs.aiccm import capability_table
return capability_table()
@routes.post("/documents/{identifier}/periodic/{structure}/aiccm/series")
def aiccm_series(
identifier: str, structure: str, request: AICCMSeriesRequest
) -> dict[str, Any]:
"""One input (and convention record) per torus plus the series plan."""
from vibesketcher.inputs.aiccm import plan_series
from vibesketcher.inputs.base import WriterRefusal
from vibesketcher.inputs.vibeqc_periodic import PeriodicJobSpec
try:
entry = store.get(identifier)
except NotFound:
raise HTTPException(404, f"no document {identifier!r}") from None
found = {s.id: s for s in entry.document.periodic_structures}
if structure not in found:
raise HTTPException(404, f"no periodic structure {structure!r}")
try:
spec = PeriodicJobSpec.model_validate({"model": "aiccm", **request.spec})
plan, bundle = plan_series(
found[structure], spec, extensions=request.extensions, shells=request.shells
)
except ValidationError as error:
raise HTTPException(422, {"reasons": [e["msg"] for e in error.errors()]}) from None
except WriterRefusal as error:
raise HTTPException(422, {"reasons": list(error.reasons)}) from None
return {
"plan": plan,
"files": [
{"name": f.name, "content": f.content, "media_type": f.media_type}
for f in bundle.files
],
}
@routes.post("/periodic/aiccm/compare")
def aiccm_compare(request: AICCMCompareRequest) -> dict[str, Any]:
"""Energies per cell across the tori, or 422 naming every mismatch."""
from vibesketcher.inputs.aiccm import compare_series
try:
return compare_series(request.plan, request.results)
except ValueError as error:
raise HTTPException(422, {"reasons": [str(error)]}) from None
return routes