cgeorgiaw HF Staff commited on
Commit
192165c
·
1 Parent(s): 281711d

first commit

Browse files
Files changed (1) hide show
  1. evaluation.py +39 -0
evaluation.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
10
+ def load_boundary(data: str) -> surface_rz_fourier.SurfaceRZFourier:
11
+ return surface_rz_fourier.SurfaceRZFourier.model_validate_json(data)
12
+
13
+
14
+ def load_boubdaries(data: str) -> list[surface_rz_fourier.SurfaceRZFourier]:
15
+ data_json = json.loads(data)
16
+ return [
17
+ surface_rz_fourier.SurfaceRZFourier.model_validate_json(b) for b in data_json
18
+ ]
19
+
20
+
21
+ def evaluate_problem(
22
+ problem_type: str, input_file: str
23
+ ) -> problems.EvaluationSingleObjective | problems.EvaluationMultiObjective:
24
+ with Path(input_file).open("r") as f:
25
+ data = f.read()
26
+
27
+ match problem_type:
28
+ case "geometrical":
29
+ boundary = load_boundary(data)
30
+ result = problems.GeometricalProblem().evaluate(boundary)
31
+ case "simple_to_build":
32
+ boundary = load_boundary(data)
33
+ result = problems.SimpleToBuildQIStellarator().evaluate(boundary)
34
+ case "mhd_stable":
35
+ boundaries = load_boubdaries(data)
36
+ result = problems.MHDStableQIStellarator().evaluate(boundaries)
37
+ case _:
38
+ raise ValueError(f"Unknown problem type: {problem_type}")
39
+ return result