Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chiang-yuan committed Sep 22, 2024
1 parent 2f4823d commit 5c17a80
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 73 deletions.
72 changes: 40 additions & 32 deletions serve/leaderboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
from pathlib import Path

import pandas as pd
Expand All @@ -6,26 +7,29 @@
from mlip_arena.models import REGISTRY as MODELS
from mlip_arena.tasks import REGISTRY as TASKS

import importlib

DATA_DIR = Path("mlip_arena/tasks/diatomics")

dfs = [pd.read_json(DATA_DIR / MODELS[model].get("family") / "homonuclear-diatomics.json") for model in MODELS]
dfs = [
pd.read_json(DATA_DIR / MODELS[model].get("family") / "homonuclear-diatomics.json")
for model in MODELS
]
df = pd.concat(dfs, ignore_index=True)


table = pd.DataFrame(columns=[
"Model",
"Element Coverage",
# "No. of reversed forces",
# "Energy-consistent forces",
"Prediction",
"NVT",
"NPT",
"Code",
"Paper",
"First Release",
])
table = pd.DataFrame(
columns=[
"Model",
"Element Coverage",
# "No. of reversed forces",
# "Energy-consistent forces",
"Prediction",
"NVT",
"NPT",
"Code",
"Paper",
"First Release",
]
)

for model in MODELS:
rows = df[df["method"] == model]
Expand All @@ -48,22 +52,27 @@


s = table.style.background_gradient(
cmap="PuRd",
subset=["Element Coverage"],
vmin=0, vmax=120
cmap="PuRd", subset=["Element Coverage"], vmin=0, vmax=120
)

st.warning("MLIP Arena is currently in **pre-alpha**. The results are not stable. Please interpret them with care.", icon="⚠️")
st.info("Contributions are welcome. For more information, visit https://github.com/atomind-ai/mlip-arena.", icon="🤗")
st.warning(
"MLIP Arena is currently in **pre-alpha**. The results are not stable. Please interpret them with care.",
icon="⚠️",
)
st.info(
"Contributions are welcome. For more information, visit https://github.com/atomind-ai/mlip-arena.",
icon="🤗",
)

st.markdown(
"""
"""
<h1 style='text-align: center;'>⚔️ MLIP Arena Leaderboard ⚔️</h1>
MLIP Arena is a platform for benchmarking foundation machine learning interatomic potentials (MLIPs), mainly for disclosing the learned physics and chemistry of the models and their performance on molecular dynamics (MD) simulations.
The benchmarks are designed to evaluate the readiness and reliability of open-source, open-weight models to reproduce the qualitatively or quantitatively correct physics.
""", unsafe_allow_html=True)

""",
unsafe_allow_html=True,
)


st.dataframe(
Expand All @@ -85,21 +94,20 @@


for task in TASKS:

if TASKS[task]['rank-page'] is None:
# st.write("Rank for this task is not available yet")
if TASKS[task]["rank-page"] is None:
continue

st.header(task, divider=True)
st.page_link(f"tasks/{TASKS[task]['task-page']}.py", label="Link to task page", icon=":material/link:")

st.page_link(
f"tasks/{TASKS[task]['task-page']}.py",
label="Link to task page",
icon=":material/link:",
)

task_module = importlib.import_module(f"ranks.{TASKS[task]['rank-page']}")

# task_module = importlib.import_module(f".ranks", TASKS[task]["task-page"])

# Call the function from the imported module
if hasattr(task_module, 'render'):
if hasattr(task_module, "render"):
task_module.render()
else:
st.write("Results for the task are not available yet.")
st.write("Results for the task are not available yet.")
86 changes: 45 additions & 41 deletions serve/ranks/homonuclear-diatomics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import streamlit as st

from pathlib import Path

import numpy as np
Expand All @@ -13,7 +11,6 @@

from mlip_arena.models import REGISTRY as MODELS


valid_models = [
model
for model, metadata in MODELS.items()
Expand All @@ -22,26 +19,36 @@

DATA_DIR = Path("mlip_arena/tasks/diatomics")

dfs = [pd.read_json(DATA_DIR / MODELS[model].get("family") / "homonuclear-diatomics.json") for model in valid_models]
dfs = [
pd.read_json(DATA_DIR / MODELS[model].get("family") / "homonuclear-diatomics.json")
for model in valid_models
]
df = pd.concat(dfs, ignore_index=True)

table = pd.DataFrame()

for model in valid_models:

rows = df[df["method"] == model]
metadata = MODELS.get(model, {})

new_row = {
"Model": model,
"Conservation deviation [eV/Å]": rows["conservation-deviation"].mean(),
"Spearman's coeff. (Energy - repulsion)": rows["spearman-repulsion-energy"].mean(),
"Spearman's coeff. (Force - descending)": rows["spearman-descending-force"].mean(),
"Spearman's coeff. (Energy - repulsion)": rows[
"spearman-repulsion-energy"
].mean(),
"Spearman's coeff. (Force - descending)": rows[
"spearman-descending-force"
].mean(),
"Tortuosity": rows["tortuosity"].mean(),
"Energy jump [eV]": rows["energy-jump"].mean(),
"Force flips": rows["force-flip-times"].mean(),
"Spearman's coeff. (Energy - attraction)": rows["spearman-attraction-energy"].mean(),
"Spearman's coeff. (Force - ascending)": rows["spearman-ascending-force"].mean(),
"Spearman's coeff. (Energy - attraction)": rows[
"spearman-attraction-energy"
].mean(),
"Spearman's coeff. (Force - ascending)": rows[
"spearman-ascending-force"
].mean(),
}

table = pd.concat([table, pd.DataFrame([new_row])], ignore_index=True)
Expand All @@ -51,10 +58,14 @@
table.sort_values("Conservation deviation [eV/Å]", ascending=True, inplace=True)
table["Rank"] = np.argsort(table["Conservation deviation [eV/Å]"].to_numpy())

table.sort_values("Spearman's coeff. (Energy - repulsion)", ascending=True, inplace=True)
table.sort_values(
"Spearman's coeff. (Energy - repulsion)", ascending=True, inplace=True
)
table["Rank"] += np.argsort(table["Spearman's coeff. (Energy - repulsion)"].to_numpy())

table.sort_values("Spearman's coeff. (Force - descending)", ascending=True, inplace=True)
table.sort_values(
"Spearman's coeff. (Force - descending)", ascending=True, inplace=True
)
table["Rank"] += np.argsort(table["Spearman's coeff. (Force - descending)"].to_numpy())

table.sort_values("Tortuosity", ascending=True, inplace=True)
Expand Down Expand Up @@ -90,41 +101,34 @@
]
)

s = table.style.background_gradient(
cmap="viridis_r",
subset=["Conservation deviation [eV/Å]"],
gmap=np.log(table["Conservation deviation [eV/Å]"].to_numpy()),
).background_gradient(
cmap="Reds",
subset=["Spearman's coeff. (Energy - repulsion)", "Spearman's coeff. (Force - descending)"],
# vmin=-1, vmax=-0.5
).background_gradient(
cmap="RdPu",
subset=["Tortuosity", "Energy jump [eV]", "Force flips"],
).background_gradient(
cmap="Blues",
subset=["Rank", "Rank aggr."],
s = (
table.style.background_gradient(
cmap="viridis_r",
subset=["Conservation deviation [eV/Å]"],
gmap=np.log(table["Conservation deviation [eV/Å]"].to_numpy()),
)
.background_gradient(
cmap="Reds",
subset=[
"Spearman's coeff. (Energy - repulsion)",
"Spearman's coeff. (Force - descending)",
],
# vmin=-1, vmax=-0.5
)
.background_gradient(
cmap="RdPu",
subset=["Tortuosity", "Energy jump [eV]", "Force flips"],
)
.background_gradient(
cmap="Blues",
subset=["Rank", "Rank aggr."],
)
)
# s = table.style.highlight_min(
# subset=["Conservation deviation", "Spearman's corr. coeff. (Energy - repulsion)"],
# color="lightgreen",
# )
# table.append(new_row, ignore_index=True)



def render():


st.dataframe(
s,
use_container_width=True,
)

# pass

# def plot():
# pass

# if __name__ == '__main__':
# pass
# return table

0 comments on commit 5c17a80

Please sign in to comment.