T3: training form and train request carry the training source (site or folder)
This commit is contained in:
@@ -16,24 +16,25 @@ def test_tea_training_config_schema():
|
|||||||
assert (config["domain"], config["name"]) == ("tea", "example")
|
assert (config["domain"], config["name"]) == ("tea", "example")
|
||||||
schema = config["json_schema"]
|
schema = config["json_schema"]
|
||||||
assert schema["title"] == "TrainingForm"
|
assert schema["title"] == "TrainingForm"
|
||||||
assert set(schema["properties"]) == {"as_of", "execution", "reference"}
|
assert set(schema["properties"]) == {"as_of", "execution", "source"}
|
||||||
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
assert schema["properties"]["as_of"]["title"] == "Datos hasta"
|
||||||
assert set(schema["$defs"]) == {"Execution", "Reference"}
|
assert set(schema["$defs"]) == {"Execution", "TrainingSource"}
|
||||||
execution = schema["$defs"]["Execution"]
|
execution = schema["$defs"]["Execution"]
|
||||||
assert execution["title"] == "Ejecución"
|
assert execution["title"] == "Ejecución"
|
||||||
assert execution["properties"]["mode"]["title"] == "Modo"
|
assert execution["properties"]["mode"]["title"] == "Modo"
|
||||||
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
assert execution["properties"]["scheduler"]["title"] == "Planificador Dask"
|
||||||
reference = schema["$defs"]["Reference"]["properties"]
|
source = schema["$defs"]["TrainingSource"]
|
||||||
assert reference["name"]["title"] == "Cohorte de referencia"
|
assert source["title"] == "Datos de entrenamiento"
|
||||||
assert reference["line_hz"]["title"] == "Frecuencia de la red eléctrica (Hz)"
|
assert source["properties"]["kind"]["enum"] == ["site", "folder"]
|
||||||
assert reference["line_hz"]["enum"] == [50, 60]
|
assert source["properties"]["folder"]["title"] == "Carpeta"
|
||||||
|
assert source["properties"]["line_hz"]["enum"] == [50, 60]
|
||||||
assert config["defaults"] == {
|
assert config["defaults"] == {
|
||||||
"execution": {"mode": "sync", "scheduler": None},
|
"execution": {"mode": "sync", "scheduler": None},
|
||||||
"reference": {"line_hz": 50},
|
"source": {"kind": "site", "line_hz": 50},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_other_domains_have_no_reference():
|
def test_other_domains_have_no_training_source():
|
||||||
for domain in ("cacu", "cama"):
|
for domain in ("cacu", "cama"):
|
||||||
config = training_config(Domain(domain), "example").model_dump()
|
config = training_config(Domain(domain), "example").model_dump()
|
||||||
assert (config["domain"], config["name"]) == (domain, "example")
|
assert (config["domain"], config["name"]) == (domain, "example")
|
||||||
@@ -43,12 +44,18 @@ def test_other_domains_have_no_reference():
|
|||||||
assert config["defaults"] == {"execution": {"mode": "sync", "scheduler": None}}
|
assert config["defaults"] == {"execution": {"mode": "sync", "scheduler": None}}
|
||||||
|
|
||||||
|
|
||||||
def test_train_validates_the_reference():
|
def test_train_validates_the_training_source():
|
||||||
with pytest.raises(HTTPException) as rejected:
|
with pytest.raises(HTTPException) as rejected:
|
||||||
train(Domain.CACU, Training(reference={"name": "nope"}))
|
train(Domain.CACU, Training(source={"kind": "site"}))
|
||||||
assert rejected.value.status_code == 422
|
assert rejected.value.status_code == 422
|
||||||
assert rejected.value.detail == "cacu models take no reference cohort"
|
assert rejected.value.detail == "cacu models take no training source"
|
||||||
|
|
||||||
for reference in ({"name": "../x"}, {"name": "nope", "line_hz": 55}):
|
for source in (
|
||||||
|
{"kind": "folder"},
|
||||||
|
{"kind": "folder", "folder": "../x"},
|
||||||
|
{"kind": "folder", "folder": "hel", "line_hz": 55},
|
||||||
|
{"kind": "other"},
|
||||||
|
):
|
||||||
with pytest.raises(ValidationError):
|
with pytest.raises(ValidationError):
|
||||||
Training(reference=reference)
|
Training(source=source)
|
||||||
|
assert Training(source={"kind": "folder", "folder": "hel"}).source.line_hz == 50
|
||||||
|
|||||||
+9
-9
@@ -16,7 +16,7 @@ from core import tea
|
|||||||
from core.domains import Domain, InputSpec
|
from core.domains import Domain, InputSpec
|
||||||
from core.models import title
|
from core.models import title
|
||||||
from persistance import bundle, cluster, inputs, registry
|
from persistance import bundle, cluster, inputs, registry
|
||||||
from persistance.cluster import Execution, Reference
|
from persistance.cluster import Execution, TrainingSource
|
||||||
from webapi.runs import dagster, execution_config, submit
|
from webapi.runs import dagster, execution_config, submit
|
||||||
|
|
||||||
router = APIRouter(prefix="/models", tags=["models"])
|
router = APIRouter(prefix="/models", tags=["models"])
|
||||||
@@ -237,7 +237,7 @@ class TrainingForm(BaseModel):
|
|||||||
None, title="Datos hasta", description="Fecha de corte de los datos (por omisión, hoy)"
|
None, title="Datos hasta", description="Fecha de corte de los datos (por omisión, hoy)"
|
||||||
)
|
)
|
||||||
execution: Execution | None = None
|
execution: Execution | None = None
|
||||||
reference: Reference | None = None
|
source: TrainingSource | None = None
|
||||||
|
|
||||||
|
|
||||||
class Training(TrainingForm):
|
class Training(TrainingForm):
|
||||||
@@ -256,10 +256,10 @@ def training_config(domain: Domain, name: str) -> TrainingConfig:
|
|||||||
json_schema = TrainingForm.model_json_schema()
|
json_schema = TrainingForm.model_json_schema()
|
||||||
defaults = {"execution": {"mode": cluster.default_mode(), "scheduler": None}}
|
defaults = {"execution": {"mode": cluster.default_mode(), "scheduler": None}}
|
||||||
if domain == Domain.TEA:
|
if domain == Domain.TEA:
|
||||||
defaults["reference"] = {"line_hz": 50}
|
defaults["source"] = {"kind": "site", "line_hz": 50}
|
||||||
else:
|
else:
|
||||||
del json_schema["properties"]["reference"]
|
del json_schema["properties"]["source"]
|
||||||
del json_schema["$defs"]["Reference"]
|
del json_schema["$defs"]["TrainingSource"]
|
||||||
return TrainingConfig(
|
return TrainingConfig(
|
||||||
domain=domain.value, name=name, json_schema=json_schema, defaults=defaults
|
domain=domain.value, name=name, json_schema=json_schema, defaults=defaults
|
||||||
)
|
)
|
||||||
@@ -273,15 +273,15 @@ class Analyze(BaseModel):
|
|||||||
def train(domain: Domain, request: Training,
|
def train(domain: Domain, request: Training,
|
||||||
client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: # fmt: skip
|
client: DagsterGraphQLClient = Depends(dagster)) -> dict[str, str]: # fmt: skip
|
||||||
"""Starts training a new version of every model of the domain; follow it at /runs."""
|
"""Starts training a new version of every model of the domain; follow it at /runs."""
|
||||||
if request.reference is not None and domain != Domain.TEA:
|
if request.source is not None and domain != Domain.TEA:
|
||||||
raise HTTPException(422, f"{domain.value} models take no reference cohort")
|
raise HTTPException(422, f"{domain.value} models take no training source")
|
||||||
config: dict = {"domain": domain.value, "execution": execution_config(request.execution)}
|
config: dict = {"domain": domain.value, "execution": execution_config(request.execution)}
|
||||||
if request.as_of:
|
if request.as_of:
|
||||||
config["as_of"] = request.as_of.isoformat()
|
config["as_of"] = request.as_of.isoformat()
|
||||||
if request.models:
|
if request.models:
|
||||||
config["models"] = request.models
|
config["models"] = request.models
|
||||||
if request.reference is not None:
|
if request.source is not None:
|
||||||
config["reference"] = request.reference.model_dump()
|
config["source"] = request.source.model_dump()
|
||||||
return submit(client, "train", "train_models", config, domain=domain.value)
|
return submit(client, "train", "train_models", config, domain=domain.value)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user