Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions ml_peg/app/base_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class BaseApp(ABC):
Parameters
----------
name
Name for application tab.
title
Title for application.
Name of application test.
description
Description of benchmark.
table_path
Expand All @@ -33,7 +31,6 @@ class BaseApp(ABC):
def __init__(
self,
name: str,
title: str,
description: str,
table_path: Path,
extra_components: list[Component],
Expand All @@ -44,9 +41,7 @@ def __init__(
Parameters
----------
name
Name for application test.
title
Title for benchmark.
Name of application test.
description
Description of benchmark.
table_path
Expand All @@ -55,7 +50,6 @@ def __init__(
List of other Dash components to add to app.
"""
self.name = name
self.title = title
self.description = description
self.table_path = table_path
self.extra_components = extra_components
Expand All @@ -75,7 +69,7 @@ def build_layout(self) -> Div:
"""
# Define all components/placeholders
return build_test_layout(
title=self.title,
name=self.name,
description=self.description,
table=self.table,
extra_components=self.extra_components,
Expand Down
33 changes: 22 additions & 11 deletions ml_peg/app/build_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from __future__ import annotations

from importlib import import_module
from pathlib import Path
import warnings

from dash import Dash, Input, Output, callback
from dash.dash_table import DataTable
from dash.dcc import Store, Tab, Tabs
from dash.html import H1, Div
from dash.html import H1, H3, Div
from yaml import safe_load

from ml_peg import app
from ml_peg.analysis.utils.utils import calc_ranks, calc_scores, get_table_style
from ml_peg.app import APP_ROOT
from ml_peg.app.utils.build_components import build_weight_components


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

# Build all layouts, and register all callbacks to main app.
for test in tests:
try:
# Import tab application layout/callbacks
# Import test layout/callbacks
test_name = test.parent.name
category_name = test.parent.parent.name
test_module = import_module(
Expand All @@ -64,7 +64,7 @@ def get_all_tests(
)
continue

# Register tab callbacks
# Register test callbacks
try:
test_app.register_callbacks()
except FileNotFoundError as err:
Expand Down Expand Up @@ -94,19 +94,29 @@ def build_category(

Returns
-------
...
...
tuple[dict[str, list[Div]], dict[str, DataTable]]
Dictionary of category layouts, and dictionary of category summary tables.
"""
# Take all tables in category, build new table, and set layout
category_layouts = {}
category_tables = {}

for category in all_layouts:
# Get category name and description
try:
with open(APP_ROOT / category / f"{category}.yml") as file:
category_info = safe_load(file)
category_title = category_info.get("title", category)
category_descrip = category_info.get("description", "")
except FileNotFoundError:
category_title = category
category_descrip = ""

# Build summary table
summary_table = build_summary_table(
all_tables[category], table_id=f"{category}-summary-table"
)
category_tables[category] = summary_table
category_tables[category_title] = summary_table

# Build weight components for summary table
weight_components = build_weight_components(
Expand All @@ -117,9 +127,10 @@ def build_category(
)

# Build full layout with summary table, weight controls, and test layouts
category_layouts[category] = Div(
category_layouts[category_title] = Div(
[
H1(category),
H1(category_title),
H3(category_descrip),
summary_table,
weight_components,
Div([all_layouts[category][test] for test in all_layouts[category]]),
Expand Down
7 changes: 2 additions & 5 deletions ml_peg/app/nebs/li_diffusion/app_li_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from pathlib import Path

from dash import Dash
from dash.html import Div

Expand All @@ -16,7 +14,7 @@
from ml_peg.app.utils.load import read_plot
from ml_peg.calcs.models.models import MODELS

BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
BENCHMARK_NAME = "Li diffusion"
DATA_PATH = APP_ROOT / "data" / "nebs" / "li_diffusion"


Expand Down Expand Up @@ -75,8 +73,7 @@ def get_app() -> LiDiffusionApp:
Benchmark layout and callback registration.
"""
return LiDiffusionApp(
name="NEBs",
title="NEBs",
name=BENCHMARK_NAME,
description=("Performance in predicting energy barriers for Li diffision."),
table_path=DATA_PATH / "li_diffusion_metrics_table.json",
extra_components=[
Expand Down
2 changes: 2 additions & 0 deletions ml_peg/app/nebs/nebs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: NEBs
description: Nudged Elastic Band comparisons
5 changes: 1 addition & 4 deletions ml_peg/app/surfaces/OC157/app_OC157.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from pathlib import Path

from dash import Dash
from dash.html import Div
import numpy as np
Expand All @@ -17,7 +15,7 @@
from ml_peg.app.utils.load import read_plot
from ml_peg.calcs.models.models import MODELS

BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
BENCHMARK_NAME = "OC157"
DATA_PATH = APP_ROOT / "data" / "surfaces" / "OC157"


Expand Down Expand Up @@ -68,7 +66,6 @@ def get_app() -> OC157App:
"""
return OC157App(
name=BENCHMARK_NAME,
title="OC157",
description=(
"Performance in predicting relative energies between 3 structures for 157 "
"molecule-surface combinations."
Expand Down
5 changes: 1 addition & 4 deletions ml_peg/app/surfaces/S24/app_S24.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from pathlib import Path

from dash import Dash
from dash.html import Div

Expand All @@ -16,7 +14,7 @@
from ml_peg.app.utils.load import read_plot
from ml_peg.calcs.models.models import MODELS

BENCHMARK_NAME = Path(__file__).name.removeprefix("app_").removesuffix(".py")
BENCHMARK_NAME = "S24"
DATA_PATH = APP_ROOT / "data" / "surfaces" / "S24"


Expand Down Expand Up @@ -63,7 +61,6 @@ def get_app() -> S24App:
"""
return S24App(
name=BENCHMARK_NAME,
title="S24",
description=(
"Performance in predicting adsorption energies for 24 "
"molecule-surface combinations."
Expand Down
2 changes: 2 additions & 0 deletions ml_peg/app/surfaces/surfaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Surfaces
description: Energy interactions at surfaces
8 changes: 4 additions & 4 deletions ml_peg/app/utils/build_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def build_weight_components(


def build_test_layout(
title: str,
name: str,
description: str,
table: DataTable,
extra_components: list[Component] | None = None,
Expand All @@ -145,8 +145,8 @@ def build_test_layout(

Parameters
----------
title
Title of test.
name
Name of test.
description
Description of test.
table
Expand All @@ -160,7 +160,7 @@ def build_test_layout(
Layout for test layout.
"""
layout_contents = [
H2(title, style={"color": "black"}),
H2(name, style={"color": "black"}),
H3(description),
Div(table),
]
Expand Down