Skip to content

Commit ae020a7

Browse files
committed
add tests/test_models.py
link to pypi pages from site's model page with requirement lists
1 parent 98a4289 commit ae020a7

File tree

6 files changed

+90
-9
lines changed

6 files changed

+90
-9
lines changed

data/wbm/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ materialscloud:2021.68 includes a readme file with a description of the dataset,
7070

7171
[wbm paper]: https://nature.com/articles/s41524-020-00481-6
7272

73-
## Data Plots
73+
## 📊   Data Plots
7474

7575
<caption>Heatmap of elemental prevalence in WBM dataset.</caption>
7676
<slot name="wbm-elements-log">

models/wrenformer/metadata.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ model_version: 0.0.4 # the aviary version
33
matbench_discovery_version: 1.0
44
date_added: 2022-11-26
55
authors:
6-
- name: Rhys Goodall
7-
affiliation: University of Cambridge
8-
orcid: https://orcid.org/0000-0002-6589-1700
96
- name: Janosh Riebesell
107
affiliation: University of Cambridge, Lawrence Berkeley National Laboratory
118
129
orcid: https://orcid.org/0000-0001-5233-3462
10+
- name: Rhys Goodall
11+
affiliation: University of Cambridge
12+
orcid: https://orcid.org/0000-0002-6589-1700
13+
- name: Rokas
14+
affiliation: University of Cambridge
15+
url: https://hardingscholars.fund.cam.ac.uk/rokas-elijosius-2021-cohort
16+
1317
repo: https://github.com/janosh/matbench-discovery
1418
doi: https://doi.org/10.1126/sciadv.abn4117
1519
preprint: https://arxiv.org/abs/2106.11132

site/src/app.css

+7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ body {
1818
font-family: -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
1919
color: var(--text-color);
2020
line-height: 1.5;
21+
margin: 0;
22+
}
23+
body > div {
24+
display: flex;
25+
min-height: 100vh;
26+
flex-direction: column;
2127
}
2228
main {
2329
padding: calc(1ex + 2vw);
30+
flex: 1;
2431
}
2532
button {
2633
color: var(--text-color);

site/src/routes/about-the-test-set/+page.svelte

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import elem_counts from './2022-12-30-wbm-element-counts.json'
88
99
let log_color_scale = false
10-
const heatmap_values = Object.values(elem_counts)
10+
const heatmap_values: number[] = Object.values(elem_counts)
1111
const color_map = {
1212
200: `blue`,
1313
35_000: `green`,
@@ -30,6 +30,11 @@
3030
{#if active_element?.name}
3131
<strong>
3232
{active_element?.name}: {pretty_num(elem_counts[active_element?.symbol])}
33+
<!-- compute percent of total -->
34+
{#if elem_counts[active_element?.symbol] > 0}
35+
{@const total = heatmap_values.reduce((a, b) => a + b, 0)}
36+
({pretty_num((elem_counts[active_element?.symbol] / total) * 100)}%)
37+
{/if}
3338
</strong>
3439
{/if}
3540
</TableInset>

site/src/routes/models/+page.svelte

+9-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@
4747
<ul>
4848
{#each Object.entries(meta.requirements) as [name, version]}
4949
<li>
50-
{name}: {version}
50+
{#if ![`aviary`].includes(name)}
51+
{@const href = `https://pypi.org/project/${name}/${version}`}
52+
{name}: <a {href}>{version}</a>
53+
{:else}
54+
{name}: {version}
55+
{/if}
5156
</li>
5257
{/each}
5358
</ul>
5459
</section>
60+
<!-- TODO add table with performance metrics (F1, Acc, Recall, Precision) for each model -->
5561
</li>
5662
{/each}
5763
</ol>
@@ -67,16 +73,15 @@
6773
padding: 3pt 9pt 5pt;
6874
}
6975
ol > li > h2 {
70-
display: inline;
76+
margin: 5pt 0 1ex;
7177
}
7278
ul {
7379
list-style-type: disc;
7480
}
7581
nav {
7682
font-weight: 250;
77-
display: inline-flex;
83+
display: flex;
7884
gap: 5pt 1em;
79-
margin: 0 1em;
8085
flex-wrap: wrap;
8186
}
8287
nav > span {

tests/test_models.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import os
2+
from datetime import date
3+
from glob import glob
4+
5+
import yaml
6+
7+
from matbench_discovery import ROOT
8+
9+
MODEL_DIRS = glob(f"{ROOT}/models/*/")
10+
11+
12+
def test_model_dirs_have_metadata() -> None:
13+
required = (
14+
"authors",
15+
"date_added",
16+
"matbench_discovery_version",
17+
"model_name",
18+
"model_version",
19+
"repo",
20+
)
21+
for model_dir in MODEL_DIRS:
22+
md_file = f"{model_dir}metadata.yml"
23+
assert os.path.isfile(md_file), f"Missing metadata file: {md_file}"
24+
25+
# make sure all required keys are non-empty
26+
with open(md_file) as yml_file:
27+
metadata = yaml.full_load(yml_file)
28+
29+
for key in required:
30+
assert metadata.get(key), f"Empty {key=} in {md_file}"
31+
32+
authors, date_added, mbd_version, model_name, model_version, repo = (
33+
metadata[key] for key in required
34+
)
35+
36+
# make sure all keys are valid
37+
assert (
38+
3 < len(model_name) < 50
39+
), f"Invalid {model_name=} not between 3 and 50 characters"
40+
assert (
41+
1 < len(model_version) < 15
42+
), f"Invalid {model_version=} not between 1 and 15 characters"
43+
# TODO increase max version when releasing new versions
44+
assert (
45+
1 <= mbd_version <= 1
46+
), f"Invalid matbench-discovery version: {mbd_version}"
47+
assert isinstance(date_added, date), f"Invalid {date_added=} not a string"
48+
assert (
49+
isinstance(authors, list) and 1 < len(authors) < 30
50+
), "authors not list or not between 1 and 30 authors"
51+
assert repo.startswith(
52+
"https://"
53+
), f"Invalid {repo=} not starting with https://"
54+
55+
56+
def test_model_dirs_have_test_scripts() -> None:
57+
for model_dir in MODEL_DIRS:
58+
test_scripts = glob(f"{model_dir}*test_*.py")
59+
test_nbs = glob(f"{model_dir}*test_*.ipynb")
60+
assert len(test_scripts + test_nbs) > 0, f"Missing test file in {model_dir}"

0 commit comments

Comments
 (0)