Skip to content

Commit 13746f4

Browse files
committed
make metrics-table sortable with svelte-zoo action
fix code in svelte.config.js for referencing figures in markdown with @fig:label syntax add ruff config and move existing linter config from setup.cfg to pyproject.toml replace isort black flake8 pyupgrade autoflake pydocstyle pre-commit hooks with ruff update site deps
1 parent db34c09 commit 13746f4

20 files changed

+535
-418
lines changed

.pre-commit-config.yaml

+7-28
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,17 @@ default_stages: [commit]
66
default_install_hook_types: [pre-commit, commit-msg]
77

88
repos:
9-
- repo: https://github.com/PyCQA/isort
10-
rev: 5.12.0
9+
- repo: https://github.com/charliermarsh/ruff-pre-commit
10+
rev: v0.0.249
1111
hooks:
12-
- id: isort
12+
- id: ruff
13+
args: [--fix]
1314

1415
- repo: https://github.com/psf/black
1516
rev: 23.1.0
1617
hooks:
1718
- id: black
1819

19-
- repo: https://github.com/pycqa/flake8
20-
rev: 6.0.0
21-
hooks:
22-
- id: flake8
23-
additional_dependencies: [flake8-bugbear]
24-
25-
- repo: https://github.com/asottile/pyupgrade
26-
rev: v3.3.1
27-
hooks:
28-
- id: pyupgrade
29-
args: [--py39-plus]
30-
3120
- repo: https://github.com/janosh/format-ipy-cells
3221
rev: v0.1.10
3322
hooks:
@@ -45,7 +34,7 @@ repos:
4534
- id: trailing-whitespace
4635

4736
- repo: https://github.com/pre-commit/mirrors-mypy
48-
rev: v0.991
37+
rev: v1.0.1
4938
hooks:
5039
- id: mypy
5140
additional_dependencies: [types-pyyaml, types-requests]
@@ -57,11 +46,7 @@ repos:
5746
stages: [commit, commit-msg]
5847
exclude_types: [csv, json, svg]
5948
exclude: ^(.+references.yaml|site/src/figs/.+)$
60-
61-
- repo: https://github.com/PyCQA/autoflake
62-
rev: v2.0.1
63-
hooks:
64-
- id: autoflake
49+
args: [--ignore-words-list, "nd,te,fpr"]
6550

6651
- repo: https://github.com/pre-commit/mirrors-prettier
6752
rev: v3.0.0-alpha.4
@@ -75,7 +60,7 @@ repos:
7560
exclude: ^(site/src/figs/.+\.svelte|data/wbm/20.+\..+|site/src/routes/.+\.(yml|yaml|json))$
7661

7762
- repo: https://github.com/pre-commit/mirrors-eslint
78-
rev: v8.33.0
63+
rev: v8.34.0
7964
hooks:
8065
- id: eslint
8166
types: [file]
@@ -88,9 +73,3 @@ repos:
8873
- eslint-plugin-svelte3
8974
- "@typescript-eslint/eslint-plugin"
9075
- "@typescript-eslint/parser"
91-
92-
- repo: https://github.com/PyCQA/pydocstyle
93-
rev: 6.3.0
94-
hooks:
95-
- id: pydocstyle
96-
exclude: tests

data/wbm/fetch_process_wbm_dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def increment_wbm_material_id(wbm_id: str) -> str:
322322

323323
df_summary.index = df_summary.index.map(increment_wbm_material_id) # format IDs
324324
# drop materials with id='None' and missing initial structures
325-
df_summary = df_summary.drop(index=nan_init_structs_ids + ["None"])
325+
df_summary = df_summary.drop(index=[*nan_init_structs_ids, "None"])
326326

327327
# the 8403 material IDs in step 3 with final number larger than any of the ones in
328328
# bad_struct_ids are now misaligned between df_summary and df_wbm

matbench_discovery/energy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def get_e_form_per_atom(
8787
entry: Entry | dict[str, float | str | Composition]: pymatgen Entry (PDEntry,
8888
ComputedEntry or ComputedStructureEntry) or dict with energy and composition
8989
keys to compute formation energy of.
90-
elemental_ref_entries (dict[str, float], optional): Must be a covering set (for
90+
elemental_ref_energies (dict[str, float], optional): Must be a covering set (for
9191
entry) of terminal reference energies, i.e. eV/atom of the lowest energy
9292
elemental phase for each element. Defaults to MP elemental reference
9393
energies as collected on 2022-09-19 get_elemental_ref_entries(). This was

matbench_discovery/metrics.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def stable_metrics(
5555
each_pred: Sequence[float],
5656
stability_threshold: float = 0,
5757
) -> dict[str, float]:
58-
"""
59-
Get a dictionary of stability prediction metrics. Mostly binary classification
58+
"""Get a dictionary of stability prediction metrics. Mostly binary classification
6059
metrics, but also MAE, RMSE and R2.
6160
6261
Args:

matbench_discovery/plots.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,14 @@ def rolling_mae_vs_hull_dist(
314314
e_above_hull_errors (pd.DataFrame | dict[str, pd.Series]): Error in
315315
model-predicted distance to convex hull, i.e. actual hull distance minus
316316
predicted hull distance (in eV / atom).
317+
df_rolling_err (pd.DataFrame, optional): Cached rolling MAE(s) as returned by
318+
previous call to this function. Defaults to None.
319+
df_err_std (pd.DataFrame, optional): Cached standard error in the mean of the
320+
rolling MAE(s) as returned by prev. call to this function. Defaults to None.
317321
window (float, optional): Rolling MAE averaging window. Defaults to 0.02 (20
318-
meV/atom) bin_width (float, optional): Density of line points (more points the
319-
smaller).
320-
Defaults to 0.002.
322+
meV/atom)
323+
bin_width (float, optional): Density of line points (more points the
324+
smaller). Defaults to 0.002.
321325
x_lim (tuple[float, float], optional): x-axis range. Defaults to (-0.2, 0.3).
322326
y_lim (tuple[float, float], optional): y-axis range. Defaults to (0.0, 0.14).
323327
backend ('matplotlib' | 'plotly'], optional): Which plotting engine to use.
@@ -326,13 +330,17 @@ def rolling_mae_vs_hull_dist(
326330
just_plot_line (bool, optional): If True, plot only the rolling MAE, no shapes
327331
and annotations. Also won't plot the standard error in the mean. Defaults
328332
to False.
333+
just_plot_lines (bool, optional): If True, plot only the rolling MAE, no shapes
334+
and annotations. Also won't plot the standard error in the mean. Defaults
335+
to False.
329336
with_sem (bool, optional): If True, plot the standard error of the mean as
330337
shaded area around the rolling MAE. Defaults to True.
331338
show_dft_acc (bool, optional): If True, change color of the triangle of peril's tip
332339
and annotate it with 'Corrected GGA Accuracy' at rolling MAE of 25 meV/atom.
333340
Defaults to False.
334341
show_dummy_mae (bool, optional): If True, plot a line at the dummy MAE of always
335342
predicting the target mean.
343+
**kwargs: Additional keyword arguments to pass to df.plot().
336344
337345
Returns:
338346
tuple[plt.Axes | go.Figure, pd.DataFrame, pd.DataFrame]: matplotlib Axes or

matbench_discovery/structure.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99

1010
def perturb_structure(struct: Structure, gamma: float = 1.5) -> Structure:
11-
"""Perturb the atomic coordinates of a pymatgen structure
11+
"""Perturb the atomic coordinates of a pymatgen structure.
1212
1313
Args:
1414
struct (Structure): pymatgen structure to be perturbed
15+
gamma (float, optional): Weibull distribution parameter. Defaults to 1.5.
1516
1617
Returns:
1718
Structure: Perturbed structure

models/voronoi/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
"""
2-
Recreate the featurizer used by Ward et al. in
3-
https://journals.aps.org/prb/abstract/10.1103/PhysRevB.96.024104
1+
"""Recreate the featurizer used by Ward et al. in
2+
https://journals.aps.org/prb/abstract/10.1103/PhysRevB.96.024104.
43
"""
54

65
import matminer.featurizers.composition as fc
@@ -30,7 +29,7 @@
3029
fs.StructuralHeterogeneity(),
3130
]
3231
featurizer = MultipleFeaturizer(
33-
structure_features + [*map(fs.StructureComposition, composition_features)]
32+
[*structure_features, *map(fs.StructureComposition, composition_features)]
3433
)
3534

3635

pyproject.toml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[tool.black]
2+
line-length = 95
3+
4+
[tool.ruff]
5+
target-version = "py39"
6+
line-length = 95
7+
select = [
8+
"B", # flake8-bugbear
9+
"C4", # flake8-comprehensions
10+
"D", # pydocstyle
11+
"E", # pycodestyle
12+
"F", # pyflakes
13+
"I", # isort
14+
"PLE", # pylint error
15+
"PLW", # pylint warning
16+
"Q", # flake8-quotes
17+
"RUF", # Ruff-specific rules
18+
"SIM", # flake8-simplify
19+
"TID", # tidy imports
20+
"UP", # pyupgrade
21+
"W", # pycodestyle
22+
"YTT", # flake8-2020
23+
]
24+
ignore = [
25+
"C408", # Unnecessary dict call - rewrite as a literal
26+
"D100", # Missing docstring in public module
27+
"D104", # Missing docstring in public package
28+
"D105", # Missing docstring in magic method
29+
"D107", # Missing docstring in __init__
30+
"D205", # 1 blank line required between summary line and description
31+
"E731", # Do not assign a lambda expression, use a def
32+
]
33+
pydocstyle.convention = "google"
34+
isort.known-third-party = ["wandb"]
35+
36+
[tool.ruff.per-file-ignores]
37+
"tests/*" = ["D"]
38+
39+
[tool.mypy]
40+
check_untyped_defs = true
41+
disallow_untyped_defs = true
42+
disallow_any_generics = true
43+
disallow_incomplete_defs = true
44+
warn_redundant_casts = true
45+
warn_unused_ignores = true
46+
allow_redefinition = true
47+
no_namespace_packages = true
48+
no_implicit_optional = false
49+
50+
[tool.pytest.ini_options]
51+
testpaths = ["tests"]
52+
addopts = "-p no:warnings"

scripts/compile_metrics.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,14 @@
148148

149149
# %% export model metrics as styled HTML table
150150
# insert svelte {...props} forwarding to the table element
151-
html_table = styler.to_html().replace("<table", "<table {...$$props}")
151+
insert = """
152+
<script>
153+
import { sortable } from 'svelte-zoo/actions'
154+
</script>
155+
156+
<table use:sortable {...$$props}
157+
"""
158+
html_table = styler.to_html().replace("<table", insert)
152159
with open(f"{FIGS}/metrics-table.svelte", "w") as file:
153160
file.write(html_table)
154161

scripts/make_api_docs.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
# Tweak lazydocs's markdown output:
2323
for path in glob(f"{out_path}/*.md"):
24-
text = open(path).read()
24+
with open(path) as file:
25+
text = file.read()
2526

2627
# remove bold tags since they break inline code
2728
text = text.replace("<b>", "").replace("</b>", "")
@@ -31,4 +32,5 @@
3132
'src="https://img.shields.io/badge/-source-cccccc?style=flat-square"',
3233
'src="https://img.shields.io/badge/source-blue?style=flat" alt="source link"',
3334
)
34-
open(path, "w").write(text)
35+
with open(path, "w") as file:
36+
file.write(text)

site/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"devDependencies": {
2020
"@iconify/svelte": "^3.1.0",
2121
"@rollup/plugin-yaml": "^4.0.1",
22-
"@sveltejs/adapter-static": "^1.0.6",
23-
"@sveltejs/kit": "^1.6.0",
22+
"@sveltejs/adapter-static": "^2.0.1",
23+
"@sveltejs/kit": "^1.8.3",
2424
"@sveltejs/vite-plugin-svelte": "^2.0.2",
25-
"@typescript-eslint/eslint-plugin": "^5.52.0",
26-
"@typescript-eslint/parser": "^5.52.0",
25+
"@typescript-eslint/eslint-plugin": "^5.53.0",
26+
"@typescript-eslint/parser": "^5.53.0",
2727
"elementari": "^0.1.0",
2828
"eslint": "^8.34.0",
2929
"eslint-plugin-svelte3": "^4.0.0",
@@ -41,11 +41,11 @@
4141
"svelte-multiselect": "^8.3.0",
4242
"svelte-preprocess": "^5.0.1",
4343
"svelte-toc": "^0.5.2",
44-
"svelte-zoo": "^0.2.6",
44+
"svelte-zoo": "^0.3.4",
4545
"svelte2tsx": "^0.6.1",
4646
"tslib": "^2.5.0",
4747
"typescript": "^4.9.5",
48-
"vite": "^4.1.1"
48+
"vite": "^4.1.3"
4949
},
5050
"keywords": [
5151
"materials discovery",

0 commit comments

Comments
 (0)