first commit
Browse files- Dockerfile +25 -0
- app.py +72 -0
- evaluation.py +42 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
+
|
3 |
+
RUN apt-get update && apt-get install -y \
|
4 |
+
build-essential \
|
5 |
+
cmake \
|
6 |
+
libnetcdf-dev \
|
7 |
+
&& rm -rf /var/lib/apt/lists/*
|
8 |
+
|
9 |
+
RUN useradd -m -u 1000 user
|
10 |
+
USER user
|
11 |
+
|
12 |
+
ENV HOME=/home/user \
|
13 |
+
PATH=/home/user/.local/bin:$PATH
|
14 |
+
|
15 |
+
WORKDIR $HOME/app
|
16 |
+
|
17 |
+
RUN pip install --no-cache-dir --upgrade pip
|
18 |
+
COPY --chown=user . $HOME/app
|
19 |
+
|
20 |
+
RUN pip install -r requirements.txt
|
21 |
+
|
22 |
+
EXPOSE 7860
|
23 |
+
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
24 |
+
|
25 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import plotly.graph_objects as go
|
3 |
+
from huggingface_hub import hf_hub_download
|
4 |
+
from datasets import load_dataset
|
5 |
+
import pathlib
|
6 |
+
import json
|
7 |
+
import pandas as pd
|
8 |
+
from evaluation import load_boundary, load_boundaries
|
9 |
+
from constellaration import forward_model, initial_guess
|
10 |
+
from constellaration.boozer import boozer
|
11 |
+
from constellaration.utils import (
|
12 |
+
file_exporter,
|
13 |
+
visualization,
|
14 |
+
visualization_utils,
|
15 |
+
)
|
16 |
+
|
17 |
+
|
18 |
+
organization = 'proxima-fusion'
|
19 |
+
results_repo = f'{organization}/constellaration-bench-results'
|
20 |
+
|
21 |
+
def read_result_from_hub(filename):
|
22 |
+
local_path = hf_hub_download(
|
23 |
+
repo_id=results_repo,
|
24 |
+
repo_type="dataset",
|
25 |
+
filename=filename,
|
26 |
+
)
|
27 |
+
return local_path
|
28 |
+
|
29 |
+
def make_visual(boundary):
|
30 |
+
vis = visualization.plot_surface(boundary)
|
31 |
+
return vis
|
32 |
+
|
33 |
+
def gradio_interface() -> gr.Blocks:
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("""
|
36 |
+
# Welcome to the ConStellaration Boundary Explorer!
|
37 |
+
|
38 |
+
### Here, you can visualize submissions to the ConStellaration Leaderboard, generate and visualize new random boundaries, or upload and visualize your own!
|
39 |
+
""")
|
40 |
+
|
41 |
+
ds = load_dataset(results_repo, split='train')
|
42 |
+
full_df = pd.DataFrame(ds)
|
43 |
+
filenames = full_df['result_filename'].to_list()
|
44 |
+
with gr.Row():
|
45 |
+
with gr.Column():
|
46 |
+
dropdown = gr.Dropdown(choices=filenames, label="Choose a leaderboard entry", value=filenames[0])
|
47 |
+
rld_btn = gr.Button(value="Reload")
|
48 |
+
|
49 |
+
with gr.Column():
|
50 |
+
plot = gr.Plot()
|
51 |
+
|
52 |
+
def get_boundary_vis(selected_file):
|
53 |
+
|
54 |
+
row = full_df[full_df['result_filename'] == selected_file].iloc[0]
|
55 |
+
|
56 |
+
if row['problem_type'] == 'mhd_stable':
|
57 |
+
raise gr.Error("Sorry this isn't implemented for mhd_stable submissions yet!")
|
58 |
+
else:
|
59 |
+
boundary = load_boundary(row['boundary_json'])
|
60 |
+
|
61 |
+
vis = make_visual(boundary)
|
62 |
+
return vis
|
63 |
+
|
64 |
+
demo.load(get_boundary_vis, dropdown, plot)
|
65 |
+
rld_btn.click(get_boundary_vis, dropdown, plot)
|
66 |
+
|
67 |
+
|
68 |
+
return demo
|
69 |
+
|
70 |
+
|
71 |
+
if __name__ == "__main__":
|
72 |
+
gradio_interface().launch()
|
evaluation.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from pathlib import Path
|
3 |
+
|
4 |
+
from constellaration import problems
|
5 |
+
from constellaration.geometry import surface_rz_fourier
|
6 |
+
|
7 |
+
PROBLEM_TYPES = ["geometrical", "simple_to_build", "mhd_stable"]
|
8 |
+
|
9 |
+
def load_boundary(data: str) -> surface_rz_fourier.SurfaceRZFourier:
|
10 |
+
return surface_rz_fourier.SurfaceRZFourier.model_validate_json(data)
|
11 |
+
|
12 |
+
def load_boundaries(data: str) -> list[surface_rz_fourier.SurfaceRZFourier]:
|
13 |
+
data_json = json.loads(data)
|
14 |
+
return [
|
15 |
+
surface_rz_fourier.SurfaceRZFourier.model_validate_json(b) for b in data_json
|
16 |
+
]
|
17 |
+
|
18 |
+
def evaluate_problem(
|
19 |
+
problem_type: str, input_file: str
|
20 |
+
) -> problems.EvaluationSingleObjective | problems.EvaluationMultiObjective:
|
21 |
+
with Path(input_file).open("r") as f:
|
22 |
+
raw = f.read()
|
23 |
+
data_dict = json.loads(raw)
|
24 |
+
data = data_dict['boundary_json']
|
25 |
+
|
26 |
+
print("Starting evaluation.")
|
27 |
+
|
28 |
+
match problem_type:
|
29 |
+
case "geometrical":
|
30 |
+
boundary = load_boundary(data)
|
31 |
+
result = problems.GeometricalProblem().evaluate(boundary)
|
32 |
+
case "simple_to_build":
|
33 |
+
boundary = load_boundary(data)
|
34 |
+
result = problems.SimpleToBuildQIStellarator().evaluate(boundary)
|
35 |
+
case "mhd_stable":
|
36 |
+
boundaries = load_boundaries(data)
|
37 |
+
result = problems.MHDStableQIStellarator().evaluate(boundaries)
|
38 |
+
case _:
|
39 |
+
raise ValueError(f"Unknown problem type: {problem_type}")
|
40 |
+
|
41 |
+
print("Finished evaluation.")
|
42 |
+
return result
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
constellaration==0.2.1
|
2 |
+
gradio
|
3 |
+
datasets
|
4 |
+
huggingface_hub
|
5 |
+
gradio-leaderboard
|
6 |
+
plotly
|