C1a: code only, no comments, no Markdown
Remove 64 Python docstrings and 39 comments, and trim prose from three noqa pragmas. The submodule had zero tracked Markdown files. Move published route descriptions into decorator arguments and the Correction schema description into ConfigDict. Drop internal docstrings, including the OAuth callback excluded from OpenAPI. Published route descriptions are unchanged in the before-and-after comparison of the nine application routers. The full application OpenAPI check requires fastapi-users, which is missing from the shared environment.
This commit is contained in:
+42
-21
@@ -1,6 +1,3 @@
|
||||
"""Model governance: versions and their reports (MLflow), promotion, and the training and
|
||||
scoring runs (Dagster). The API starts runs and reads the registry; it never trains."""
|
||||
|
||||
import mimetypes
|
||||
import zipfile
|
||||
from datetime import date
|
||||
@@ -22,7 +19,7 @@ router = APIRouter(prefix="/models", tags=["models"])
|
||||
|
||||
class Version(BaseModel):
|
||||
version: int
|
||||
created: int # ms since the epoch
|
||||
created: int
|
||||
aliases: list[str]
|
||||
metrics: dict[str, float]
|
||||
params: dict[str, str]
|
||||
@@ -110,10 +107,14 @@ def versions(domain: Domain, name: str) -> list[Version]:
|
||||
@router.get("/{domain}/{name}/versions/{version}/reports/{report}",
|
||||
responses={200: {"content": {"application/json": {}, "application/octet-stream": {}},
|
||||
"description": "the report as stored"}},
|
||||
response_class=Response) # fmt: skip
|
||||
response_class=Response,
|
||||
description=(
|
||||
"A version's report: the generated ones as JSON (what the "
|
||||
'governance page draws), the\n'
|
||||
'clinical validation as the file the clinical team uploaded.'
|
||||
),
|
||||
) # fmt: skip
|
||||
def read_report(domain: Domain, name: str, version: int, report: str) -> Response:
|
||||
"""A version's report: the generated ones as JSON (what the governance page draws), the
|
||||
clinical validation as the file the clinical team uploaded."""
|
||||
found = registry.report(f"{domain.value}.{name}", version, report)
|
||||
if found is None:
|
||||
raise HTTPException(404, detail=f"{domain.value}.{name} v{version} has no {report}")
|
||||
@@ -123,20 +124,31 @@ def read_report(domain: Domain, name: str, version: int, report: str) -> Respons
|
||||
headers={"Content-Disposition": f'inline; filename="{filename}"'}) # fmt: skip
|
||||
|
||||
|
||||
@router.post("/{domain}/{name}/versions/{version}/reports/clinical_validation")
|
||||
@router.post(
|
||||
"/{domain}/{name}/versions/{version}/reports/clinical_validation",
|
||||
description=(
|
||||
"The clinical team's validation of a version: the third report, "
|
||||
"which promotion needs\n"
|
||||
"unless the site left it out of PROMOTION_REPORTS."
|
||||
),
|
||||
)
|
||||
def add_clinical_validation(domain: Domain, name: str, version: int, file: UploadFile) -> dict:
|
||||
"""The clinical team's validation of a version: the third report, which promotion needs
|
||||
unless the site left it out of PROMOTION_REPORTS."""
|
||||
registry.add_report(f"{domain.value}.{name}", version, "clinical_validation",
|
||||
file.filename or "report", file.file.read()) # fmt: skip
|
||||
return {"reports": sorted(registry.reports(f"{domain.value}.{name}", version))}
|
||||
|
||||
|
||||
@router.post("/{domain}/{name}/versions/{version}/promote")
|
||||
@router.post(
|
||||
"/{domain}/{name}/versions/{version}/promote",
|
||||
description=(
|
||||
"The version risk batches come from from now on; refused (409) "
|
||||
"without the reports\n"
|
||||
"the site requires (PROMOTION_REPORTS; default: technical "
|
||||
"validation, interpretability\n"
|
||||
"and clinical validation)."
|
||||
),
|
||||
)
|
||||
def promote(domain: Domain, name: str, version: int) -> dict:
|
||||
"""The version risk batches come from from now on; refused (409) without the reports
|
||||
the site requires (PROMOTION_REPORTS; default: technical validation, interpretability
|
||||
and clinical validation)."""
|
||||
try:
|
||||
registry.promote(f"{domain.value}.{name}", version)
|
||||
except registry.UnknownVersion as e:
|
||||
@@ -234,10 +246,12 @@ class Analyze(BaseModel):
|
||||
execution: Execution | None = None
|
||||
|
||||
|
||||
@router.post("/{domain}/train")
|
||||
@router.post(
|
||||
"/{domain}/train",
|
||||
description="Starts training a new version of every model of the domain; follow it at /runs.",
|
||||
)
|
||||
def train(domain: Domain, request: Training,
|
||||
client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: # fmt: skip
|
||||
"""Starts training a new version of every model of the domain; follow it at /runs."""
|
||||
if request.source is not None and domain != Domain.TEA:
|
||||
raise HTTPException(422, f"{domain.value} models take no training source")
|
||||
config: dict = {"domain": domain.value, "execution": execution_config(request.execution)}
|
||||
@@ -250,19 +264,26 @@ def train(domain: Domain, request: Training,
|
||||
return submit(client, "train", "train_models", config, domain=domain.value)
|
||||
|
||||
|
||||
@router.post("/{domain}/analyze")
|
||||
@router.post(
|
||||
"/{domain}/analyze",
|
||||
description=(
|
||||
"Starts analysing the studies the domain's models read whole "
|
||||
"(TEA: its EEGs); follow\n"
|
||||
"it at /runs."
|
||||
),
|
||||
)
|
||||
def analyze(
|
||||
domain: Domain,
|
||||
request: Analyze = Analyze(), # noqa: B008
|
||||
client: DagsterGraphQLClient = Depends(dagster),
|
||||
) -> dict[str, str]:
|
||||
"""Starts analysing the studies the domain's models read whole (TEA: its EEGs); follow
|
||||
it at /runs."""
|
||||
config = {"domain": domain.value, "execution": execution_config(request.execution)}
|
||||
return submit(client, "analyze", "analyze_studies", config, domain=domain.value)
|
||||
|
||||
|
||||
@router.post("/{domain}/score")
|
||||
@router.post(
|
||||
"/{domain}/score",
|
||||
description="Starts a risk batch from each model's champion; follow it at /runs.",
|
||||
)
|
||||
def score(domain: Domain, client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]:
|
||||
"""Starts a risk batch from each model's champion; follow it at /runs."""
|
||||
return submit(client, "score", "score_models", {"domain": domain.value}, domain=domain.value)
|
||||
|
||||
Reference in New Issue
Block a user