Skip to content

Commit 93b9f9c

Browse files
authored
Autodoc typehints (#350)
* Add autodoc typehints module * Remove doc typehints in favour of signature * Remove numpydoc comment
1 parent 2994e40 commit 93b9f9c

34 files changed

+832
-829
lines changed

docs/source/conf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@
2424
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2525
# ones.
2626
extensions = [
27-
"numpydoc",
2827
"sphinx.ext.autodoc",
2928
"sphinx.ext.intersphinx",
29+
"sphinx.ext.napoleon",
3030
"sphinx.ext.mathjax",
3131
"sphinx.ext.viewcode",
3232
"sphinxcontrib.contentui",
3333
"sphinx_copybutton",
34+
"sphinx_autodoc_typehints",
3435
]
3536

36-
numpydoc_validation_checks = {"all", "EX01", "SA01", "ES01"}
37+
always_use_bars_union = True
38+
napoleon_include_special_with_doc = True
39+
napoleon_use_param = True
40+
41+
numpydoc_validation_checks = {"all", "EX01", "SA01", "ES01", "PR04"}
3742
numpydoc_validation_exclude = {
3843
r"\.__weakref__$",
3944
r"\.__repr__$",
@@ -190,6 +195,7 @@
190195

191196
# Warnings to ignore when using the -n (nitpicky) option
192197
# We should ignore any python built-in exception, for instance
198+
nitpicky = True
193199
nitpick_ignore = [
194200
("py:class", "Logger"),
195201
("py:class", "numpy.float64"),

janus_core/calculations/base.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,43 @@ class BaseCalculation(FileNameMixin):
3939
4040
Parameters
4141
----------
42-
calc_name : str
42+
calc_name
4343
Name of calculation being run, used for name of logger. Default is "base".
44-
struct : MaybeSequence[Atoms] | None
44+
struct
4545
ASE Atoms structure(s) to simulate. Required if `struct_path` is None.
4646
Default is None.
47-
struct_path : PathLike | None
47+
struct_path
4848
Path of structure to simulate. Required if `struct` is None.
4949
Default is None.
50-
arch : Architectures
50+
arch
5151
MLIP architecture to use for calculations. Default is "mace_mp".
52-
device : Devices
52+
device
5353
Device to run model on. Default is "cpu".
54-
model_path : PathLike | None
54+
model_path
5555
Path to MLIP model. Default is `None`.
56-
read_kwargs : ASEReadArgs
56+
read_kwargs
5757
Keyword arguments to pass to ase.io.read. Default is {}.
58-
sequence_allowed : bool
58+
sequence_allowed
5959
Whether a sequence of Atoms objects is allowed. Default is True.
60-
calc_kwargs : dict[str, Any] | None
60+
calc_kwargs
6161
Keyword arguments to pass to the selected calculator. Default is {}.
62-
set_calc : bool | None
62+
set_calc
6363
Whether to set (new) calculators for structures. Default is None.
64-
attach_logger : bool | None
64+
attach_logger
6565
Whether to attach a logger. Default is True if "filename" is passed in
6666
log_kwargs, else False.
67-
log_kwargs : dict[str, Any] | None
67+
log_kwargs
6868
Keyword arguments to pass to `config_logger`. Default is {}.
69-
track_carbon : bool | None
69+
track_carbon
7070
Whether to track carbon emissions of calculation. Requires attach_logger.
7171
Default is True if attach_logger is True, else False.
72-
tracker_kwargs : dict[str, Any] | None
72+
tracker_kwargs
7373
Keyword arguments to pass to `config_tracker`. Default is {}.
74-
file_prefix : PathLike | None
74+
file_prefix
7575
Prefix for output filenames. Default is None.
76-
additional_prefix : str | None
76+
additional_prefix
7777
Component to add to default file_prefix (joined by hyphens). Default is None.
78-
param_prefix : str | None
78+
param_prefix
7979
Additional parameters to add to default file_prefix. Default is None.
8080
8181
Attributes
@@ -112,44 +112,44 @@ def __init__(
112112
113113
Parameters
114114
----------
115-
calc_name : str
115+
calc_name
116116
Name of calculation being run, used for name of logger. Default is "base".
117-
struct : MaybeSequence[Atoms] | None
117+
struct
118118
ASE Atoms structure(s) to simulate. Required if `struct_path` is None.
119119
Default is None.
120-
struct_path : PathLike | None
120+
struct_path
121121
Path of structure to simulate. Required if `struct` is None. Default is
122122
None.
123-
arch : Architectures
123+
arch
124124
MLIP architecture to use for calculations. Default is "mace_mp".
125-
device : Devices
125+
device
126126
Device to run MLIP model on. Default is "cpu".
127-
model_path : PathLike | None
127+
model_path
128128
Path to MLIP model. Default is `None`.
129-
read_kwargs : ASEReadArgs | None
129+
read_kwargs
130130
Keyword arguments to pass to ase.io.read. Default is {}.
131-
sequence_allowed : bool
131+
sequence_allowed
132132
Whether a sequence of Atoms objects is allowed. Default is True.
133-
calc_kwargs : dict[str, Any] | None
133+
calc_kwargs
134134
Keyword arguments to pass to the selected calculator. Default is {}.
135-
set_calc : bool | None
135+
set_calc
136136
Whether to set (new) calculators for structures. Default is None.
137-
attach_logger : bool | None
137+
attach_logger
138138
Whether to attach a logger. Default is True if "filename" is passed in
139139
log_kwargs, else False.
140-
log_kwargs : dict[str, Any] | None
140+
log_kwargs
141141
Keyword arguments to pass to `config_logger`. Default is {}.
142-
track_carbon : bool | None
142+
track_carbon
143143
Whether to track carbon emissions of calculation. Requires attach_logger.
144144
Default is True if attach_logger is True, else False.
145-
tracker_kwargs : dict[str, Any] | None
145+
tracker_kwargs
146146
Keyword arguments to pass to `config_tracker`. Default is {}.
147-
file_prefix : PathLike | None
147+
file_prefix
148148
Prefix for output filenames. Default is None.
149-
additional_prefix : str | None
149+
additional_prefix
150150
Component to add to default file_prefix (joined by hyphens). Default is
151151
None.
152-
param_prefix : str | None
152+
param_prefix
153153
Additional parameters to add to default file_prefix. Default is None.
154154
"""
155155
read_kwargs, calc_kwargs, log_kwargs, tracker_kwargs = none_to_dict(
@@ -232,7 +232,7 @@ def _set_info_units(
232232
233233
Parameters
234234
----------
235-
keys : Sequence
235+
keys
236236
Keys for which to add units to structure info. Default is
237237
("energy", "forces", "stress").
238238
"""

janus_core/calculations/descriptors.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,44 @@ class Descriptors(BaseCalculation):
2828
2929
Parameters
3030
----------
31-
struct : MaybeSequence[Atoms] | None
31+
struct
3232
ASE Atoms structure(s) to calculate descriptors for. Required if `struct_path`
3333
is None. Default is None.
34-
struct_path : PathLike | None
34+
struct_path
3535
Path of structure to calculate descriptors for. Required if `struct` is None.
3636
Default is None.
37-
arch : Architectures
37+
arch
3838
MLIP architecture to use for calculations. Default is "mace_mp".
39-
device : Devices
39+
device
4040
Device to run MLIP model on. Default is "cpu".
41-
model_path : PathLike | None
41+
model_path
4242
Path to MLIP model. Default is `None`.
43-
read_kwargs : ASEReadArgs | None
43+
read_kwargs
4444
Keyword arguments to pass to ase.io.read. By default,
4545
read_kwargs["index"] is -1.
46-
calc_kwargs : dict[str, Any] | None
46+
calc_kwargs
4747
Keyword arguments to pass to the selected calculator. Default is {}.
48-
set_calc : bool | None
48+
set_calc
4949
Whether to set (new) calculators for structures. Default is None.
50-
attach_logger : bool | None
50+
attach_logger
5151
Whether to attach a logger. Default is True if "filename" is passed in
5252
log_kwargs, else False.
53-
log_kwargs : dict[str, Any] | None
53+
log_kwargs
5454
Keyword arguments to pass to `config_logger`. Default is {}.
55-
track_carbon : bool | None
55+
track_carbon
5656
Whether to track carbon emissions of calculation. Default is True if
5757
attach_logger is True, else False.
58-
tracker_kwargs : dict[str, Any] | None
58+
tracker_kwargs
5959
Keyword arguments to pass to `config_tracker`. Default is {}.
60-
invariants_only : bool
60+
invariants_only
6161
Whether only the invariant descriptors should be returned. Default is True.
62-
calc_per_element : bool
62+
calc_per_element
6363
Whether to calculate mean descriptors for each element. Default is False.
64-
calc_per_atom : bool
64+
calc_per_atom
6565
Whether to calculate descriptors for each atom. Default is False.
66-
write_results : bool
66+
write_results
6767
True to write out structure with results of calculations. Default is False.
68-
write_kwargs : ASEWriteArgs | None
68+
write_kwargs
6969
Keyword arguments to pass to ase.io.write if saving structure with
7070
results of calculations. Default is {}.
7171
@@ -100,44 +100,44 @@ def __init__(
100100
101101
Parameters
102102
----------
103-
struct : MaybeSequence[Atoms] | None
103+
struct
104104
ASE Atoms structure(s) to calculate descriptors for. Required if
105105
`struct_path` is None. Default is None.
106-
struct_path : PathLike | None
106+
struct_path
107107
Path of structure to calculate descriptors for. Required if `struct` is
108108
None. Default is None.
109-
arch : Architectures
109+
arch
110110
MLIP architecture to use for calculations. Default is "mace_mp".
111-
device : Devices
111+
device
112112
Device to run MLIP model on. Default is "cpu".
113-
model_path : PathLike | None
113+
model_path
114114
Path to MLIP model. Default is `None`.
115-
read_kwargs : ASEReadArgs | None
115+
read_kwargs
116116
Keyword arguments to pass to ase.io.read. By default,
117117
read_kwargs["index"] is -1.
118-
calc_kwargs : dict[str, Any] | None
118+
calc_kwargs
119119
Keyword arguments to pass to the selected calculator. Default is {}.
120-
set_calc : bool | None
120+
set_calc
121121
Whether to set (new) calculators for structures. Default is None.
122-
attach_logger : bool | None
122+
attach_logger
123123
Whether to attach a logger. Default is True if "filename" is passed in
124124
log_kwargs, else False.
125-
log_kwargs : dict[str, Any] | None
125+
log_kwargs
126126
Keyword arguments to pass to `config_logger`. Default is {}.
127-
track_carbon : bool | None
127+
track_carbon
128128
Whether to track carbon emissions of calculation. Requires attach_logger.
129129
Default is True if attach_logger is True, else False.
130-
tracker_kwargs : dict[str, Any] | None
130+
tracker_kwargs
131131
Keyword arguments to pass to `config_tracker`. Default is {}.
132-
invariants_only : bool
132+
invariants_only
133133
Whether only the invariant descriptors should be returned. Default is True.
134-
calc_per_element : bool
134+
calc_per_element
135135
Whether to calculate mean descriptors for each element. Default is False.
136-
calc_per_atom : bool
136+
calc_per_atom
137137
Whether to calculate descriptors for each atom. Default is False.
138-
write_results : bool
138+
write_results
139139
True to write out structure with results of calculations. Default is False.
140-
write_kwargs : ASEWriteArgs | None
140+
write_kwargs
141141
Keyword arguments to pass to ase.io.write if saving structure with
142142
results of calculations. Default is {}.
143143
"""
@@ -229,7 +229,7 @@ def _calc_descriptors(self, struct: Atoms) -> None:
229229
230230
Parameters
231231
----------
232-
struct : Atoms
232+
struct
233233
Structure to calculate descriptors for.
234234
"""
235235
if "arch" in struct.calc.parameters:

0 commit comments

Comments
 (0)