Skip to content

Commit b7a1aed

Browse files
committed
Add category name and simplify test names (#57)
1 parent fef100d commit b7a1aed

File tree

8 files changed

+37
-37
lines changed

8 files changed

+37
-37
lines changed

ml_peg/app/base_app.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class BaseApp(ABC):
1919
Parameters
2020
----------
2121
name
22-
Name for application tab.
23-
title
24-
Title for application.
22+
Name of application test.
2523
description
2624
Description of benchmark.
2725
table_path
@@ -33,7 +31,6 @@ class BaseApp(ABC):
3331
def __init__(
3432
self,
3533
name: str,
36-
title: str,
3734
description: str,
3835
table_path: Path,
3936
extra_components: list[Component],
@@ -44,9 +41,7 @@ def __init__(
4441
Parameters
4542
----------
4643
name
47-
Name for application test.
48-
title
49-
Title for benchmark.
44+
Name of application test.
5045
description
5146
Description of benchmark.
5247
table_path
@@ -55,7 +50,6 @@ def __init__(
5550
List of other Dash components to add to app.
5651
"""
5752
self.name = name
58-
self.title = title
5953
self.description = description
6054
self.table_path = table_path
6155
self.extra_components = extra_components
@@ -75,7 +69,7 @@ def build_layout(self) -> Div:
7569
"""
7670
# Define all components/placeholders
7771
return build_test_layout(
78-
title=self.title,
72+
name=self.name,
7973
description=self.description,
8074
table=self.table,
8175
extra_components=self.extra_components,

ml_peg/app/build_app.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
from __future__ import annotations
44

55
from importlib import import_module
6-
from pathlib import Path
76
import warnings
87

98
from dash import Dash, Input, Output, callback
109
from dash.dash_table import DataTable
1110
from dash.dcc import Store, Tab, Tabs
12-
from dash.html import H1, Div
11+
from dash.html import H1, H3, Div
12+
from yaml import safe_load
1313

14-
from ml_peg import app
1514
from ml_peg.analysis.utils.utils import calc_ranks, calc_scores, get_table_style
15+
from ml_peg.app import APP_ROOT
1616
from ml_peg.app.utils.build_components import build_weight_components
1717

1818

@@ -35,14 +35,14 @@ def get_all_tests(
3535
# Find Python files e.g. app_OC157.py in mlip_tesing.app module.
3636
# We will get the category from the parent's parent directory
3737
# E.g. ml_peg/app/surfaces/OC157/app_OC157.py -> surfaces
38-
tests = Path(app.__file__).parent.glob(f"{category}/*/app*.py")
38+
tests = APP_ROOT.glob(f"{category}/*/app*.py")
3939
layouts = {}
4040
tables = {}
4141

4242
# Build all layouts, and register all callbacks to main app.
4343
for test in tests:
4444
try:
45-
# Import tab application layout/callbacks
45+
# Import test layout/callbacks
4646
test_name = test.parent.name
4747
category_name = test.parent.parent.name
4848
test_module = import_module(
@@ -64,7 +64,7 @@ def get_all_tests(
6464
)
6565
continue
6666

67-
# Register tab callbacks
67+
# Register test callbacks
6868
try:
6969
test_app.register_callbacks()
7070
except FileNotFoundError as err:
@@ -94,19 +94,29 @@ def build_category(
9494
9595
Returns
9696
-------
97-
...
98-
...
97+
tuple[dict[str, list[Div]], dict[str, DataTable]]
98+
Dictionary of category layouts, and dictionary of category summary tables.
9999
"""
100100
# Take all tables in category, build new table, and set layout
101101
category_layouts = {}
102102
category_tables = {}
103103

104104
for category in all_layouts:
105+
# Get category name and description
106+
try:
107+
with open(APP_ROOT / category / f"{category}.yml") as file:
108+
category_info = safe_load(file)
109+
category_title = category_info.get("title", category)
110+
category_descrip = category_info.get("description", "")
111+
except FileNotFoundError:
112+
category_title = category
113+
category_descrip = ""
114+
105115
# Build summary table
106116
summary_table = build_summary_table(
107117
all_tables[category], table_id=f"{category}-summary-table"
108118
)
109-
category_tables[category] = summary_table
119+
category_tables[category_title] = summary_table
110120

111121
# Build weight components for summary table
112122
weight_components = build_weight_components(
@@ -117,9 +127,10 @@ def build_category(
117127
)
118128

119129
# Build full layout with summary table, weight controls, and test layouts
120-
category_layouts[category] = Div(
130+
category_layouts[category_title] = Div(
121131
[
122-
H1(category),
132+
H1(category_title),
133+
H3(category_descrip),
123134
summary_table,
124135
weight_components,
125136
Div([all_layouts[category][test] for test in all_layouts[category]]),

ml_peg/app/nebs/li_diffusion/app_li_diffusion.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
from pathlib import Path
6-
75
from dash import Dash
86
from dash.html import Div
97

@@ -16,7 +14,7 @@
1614
from ml_peg.app.utils.load import read_plot
1715
from ml_peg.calcs.models.models import MODELS
1816

19-
BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
17+
BENCHMARK_NAME = "Li diffusion"
2018
DATA_PATH = APP_ROOT / "data" / "nebs" / "li_diffusion"
2119

2220

@@ -75,8 +73,7 @@ def get_app() -> LiDiffusionApp:
7573
Benchmark layout and callback registration.
7674
"""
7775
return LiDiffusionApp(
78-
name="NEBs",
79-
title="NEBs",
76+
name=BENCHMARK_NAME,
8077
description=("Performance in predicting energy barriers for Li diffision."),
8178
table_path=DATA_PATH / "li_diffusion_metrics_table.json",
8279
extra_components=[

ml_peg/app/nebs/nebs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: NEBs
2+
description: Nudged Elastic Band comparisons

ml_peg/app/surfaces/OC157/app_OC157.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
from pathlib import Path
6-
75
from dash import Dash
86
from dash.html import Div
97
import numpy as np
@@ -17,7 +15,7 @@
1715
from ml_peg.app.utils.load import read_plot
1816
from ml_peg.calcs.models.models import MODELS
1917

20-
BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
18+
BENCHMARK_NAME = "OC157"
2119
DATA_PATH = APP_ROOT / "data" / "surfaces" / "OC157"
2220

2321

@@ -68,7 +66,6 @@ def get_app() -> OC157App:
6866
"""
6967
return OC157App(
7068
name=BENCHMARK_NAME,
71-
title="OC157",
7269
description=(
7370
"Performance in predicting relative energies between 3 structures for 157 "
7471
"molecule-surface combinations."

ml_peg/app/surfaces/S24/app_S24.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
from pathlib import Path
6-
75
from dash import Dash
86
from dash.html import Div
97

@@ -16,7 +14,7 @@
1614
from ml_peg.app.utils.load import read_plot
1715
from ml_peg.calcs.models.models import MODELS
1816

19-
BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
17+
BENCHMARK_NAME = "S24"
2018
DATA_PATH = APP_ROOT / "data" / "surfaces" / "S24"
2119

2220

@@ -63,7 +61,6 @@ def get_app() -> S24App:
6361
"""
6462
return S24App(
6563
name=BENCHMARK_NAME,
66-
title="S24",
6764
description=(
6865
"Performance in predicting adsorption energies for 24 "
6966
"molecule-surface combinations."

ml_peg/app/surfaces/surfaces.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: Surfaces
2+
description: Energy interactions at surfaces

ml_peg/app/utils/build_components.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def build_weight_components(
135135

136136

137137
def build_test_layout(
138-
title: str,
138+
name: str,
139139
description: str,
140140
table: DataTable,
141141
extra_components: list[Component] | None = None,
@@ -145,8 +145,8 @@ def build_test_layout(
145145
146146
Parameters
147147
----------
148-
title
149-
Title of test.
148+
name
149+
Name of test.
150150
description
151151
Description of test.
152152
table
@@ -160,7 +160,7 @@ def build_test_layout(
160160
Layout for test layout.
161161
"""
162162
layout_contents = [
163-
H2(title, style={"color": "black"}),
163+
H2(name, style={"color": "black"}),
164164
H3(description),
165165
Div(table),
166166
]

0 commit comments

Comments
 (0)