from __future__ import annotations
from fastapi.responses import HTMLResponse
from openenv.core import create_fastapi_app
from fusion_lab.models import StellaratorAction, StellaratorObservation
from server.environment import BUDGET, N_FIELD_PERIODS, StellaratorEnvironment
from server.physics import ASPECT_RATIO_MAX, AVERAGE_TRIANGULARITY_MAX, EDGE_IOTA_OVER_NFP_MIN
app = create_fastapi_app(
env=StellaratorEnvironment,
action_cls=StellaratorAction,
observation_cls=StellaratorObservation,
)
@app.get("/", response_class=HTMLResponse)
def landing_page() -> str:
return """
Fusion Design Lab
Fusion Design Lab
OpenEnv P1 stellarator optimization environment powered by constellaration
Task
Minimize max elongation of a stellarator boundary using 4 geometric knobs, subject to physics constraints.
Constraints
aspect_ratio≤ 4.0
average_triangularity≤ −0.5
abs(edge_iota_over_nfp)≥ 0.3
API Endpoints
- GET
/health — liveness check
- GET
/task — task specification
- POST
/reset — start a new episode
- POST
/step — execute an action
"""
@app.get("/task")
def task_summary() -> dict[str, object]:
return {
"description": (
"Optimize the P1 benchmark with a custom low-dimensional boundary family "
"derived from a rotating-ellipse seed."
),
"constraints": {
"aspect_ratio_max": ASPECT_RATIO_MAX,
"average_triangularity_max": AVERAGE_TRIANGULARITY_MAX,
"abs_edge_iota_over_nfp_min": EDGE_IOTA_OVER_NFP_MIN,
},
"n_field_periods": N_FIELD_PERIODS,
"budget": BUDGET,
"actions": ["run", "submit", "restore_best"],
"parameters": [
"aspect_ratio",
"elongation",
"rotational_transform",
"triangularity_scale",
],
"directions": ["increase", "decrease"],
"magnitudes": ["small", "medium", "large"],
"evaluation_modes": {
"run": "low-fidelity constellaration evaluation",
"submit": "low-fidelity constellaration terminal evaluation",
},
}
def main() -> None:
import uvicorn
uvicorn.run("server.app:app", host="0.0.0.0", port=8000, reload=True)
if __name__ == "__main__":
main()