Skip to content

Commit ebc89f7

Browse files
committed
update doc
1 parent da59f05 commit ebc89f7

File tree

13 files changed

+232
-148
lines changed

13 files changed

+232
-148
lines changed

doc/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def main():
202202
"command", nargs="?", default="html", help=f"command to run: {joined}"
203203
)
204204
argparser.add_argument(
205-
"--num-jobs", default="auto", help="number of jobs used by sphinx-build"
205+
"--num-jobs", default="1", help="number of jobs used by sphinx-build"
206206
)
207207
argparser.add_argument(
208208
"--python-path", type=str, default=os.path.dirname(DOC_PATH), help="path"

doc/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ jinja2
33
sphinx
44
numpydoc
55
sphinx_copybutton
6+
sphinx-autodoc-typehints
67
matplotlib
78
sphinx_design
89
nbsphinx
9-
sphinxemoji
10+
sphinxemoji>=0.3.2
1011
pydata-sphinx-theme
1112
jupytext
1213
myst-nb

doc/source/api_reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ All classes and functions exposed in pyscfad.* namespace are public.
2626
tdscf
2727
tools
2828
util
29+
ml

doc/source/api_reference/ml.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. _ml:
2+
3+
================
4+
Machine learning
5+
================
6+
7+
The :mod:`pyscfad.ml` subpackage implements methods used in machine learning tasks.
8+
9+
.. autosummary::
10+
:toctree: api/
11+
:recursive:
12+
13+
pyscfad.ml

doc/source/conf.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@
1010
import warnings
1111
import inspect
1212

13+
# Workaround to avoid expanding type aliases. Copied from jax
14+
from typing import ForwardRef
15+
def _do_not_evaluate(
16+
self, globalns, *args, _evaluate=ForwardRef._evaluate, **kwargs,
17+
):
18+
if globalns.get('__name__', '').startswith('pyscfad'):
19+
return self
20+
return _evaluate(self, globalns, *args, **kwargs)
21+
ForwardRef._evaluate = _do_not_evaluate
22+
1323
project = "pyscfad"
14-
copyright = "2021-2025, Xing Zhang"
24+
copyright = "2021-2026, Xing Zhang"
1525
author = "Xing Zhang"
1626

1727
import pyscfad
@@ -27,11 +37,13 @@
2737
# "IPython.sphinxext.ipython_directive",
2838
# "IPython.sphinxext.ipython_console_highlighting",
2939
"matplotlib.sphinxext.plot_directive",
30-
"numpydoc",
40+
# "numpydoc",
3141
"sphinx_copybutton",
3242
"sphinx_design",
3343
"sphinx.ext.autodoc",
3444
"sphinx.ext.autosummary",
45+
"sphinx.ext.napoleon", # if using Google/NumPy docstrings
46+
#"sphinx_autodoc_typehints",
3547
"sphinx.ext.coverage",
3648
"sphinx.ext.doctest",
3749
"sphinx.ext.extlinks",
@@ -56,11 +68,22 @@
5668
]
5769

5870
autosummary_generate = True
59-
autodoc_typehints = "none"
6071

61-
numpydoc_show_class_members = False
62-
numpydoc_show_inherited_class_members = False
63-
numpydoc_attributes_as_param_list = False
72+
napolean_use_rtype = False
73+
autodoc_typehints_format = "short"
74+
75+
autodoc_typehints = "description"
76+
autodoc_typehints_description_target = "all"
77+
autodoc_type_aliases = {
78+
'ArrayLike': 'pyscfad.typing.ArrayLike',
79+
}
80+
81+
#always_document_param_types = True
82+
#set_type_checking_flag = True
83+
84+
#numpydoc_show_class_members = False
85+
#numpydoc_show_inherited_class_members = False
86+
#numpydoc_attributes_as_param_list = False
6487

6588
pygments_style = "sphinx"
6689

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ authors = [
1515
]
1616

1717
dependencies = [
18-
"jax>=0.7.1,<0.9",
18+
"jax>=0.7.1,<0.10",
1919
"pyscfadlib>=0.2.0",
2020
"pyscf>=2.3",
2121
"pyscf-properties",
@@ -33,7 +33,7 @@ classifiers = [
3333

3434
[project.optional-dependencies]
3535
cuda12 = [
36-
"jax[cuda12]>=0.7.1,<0.9",
36+
"jax[cuda12]>=0.7.1,<0.10",
3737
"pyscfad-cuda12-plugin[with_cuda]>=0.2.0",
3838
]
3939

pyscfad/gto/mole_lite.py

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
"""
15+
Lightweight ``mole`` module.
16+
"""
1417

1518
from __future__ import annotations
16-
from typing import Any
1719
from collections.abc import Callable
1820
import contextlib
1921

@@ -46,13 +48,12 @@
4648
is_au,
4749
)
4850

51+
from pyscfad.typing import ArrayLike, Array
4952
from pyscfad import numpy as np
5053
from pyscfad import ops
5154
from pyscfad.gto.mole import energy_nuc
5255
from pyscfad.gto import moleintor_lite
5356

54-
Array = Any
55-
5657
def _format_basis(basis, uniq_symbols):
5758
if isinstance(basis, dict):
5859
for k, v in basis.items():
@@ -85,44 +86,32 @@ def _format_symbols(symbols):
8586
symbols = [symbols,]
8687
return tuple(_atom_symbol(symb) for symb in symbols)
8788

88-
class Mole(MoleBase):
89-
"""Molecular information.
90-
91-
Parameters
92-
----------
93-
symbols : tuple of str
94-
Atomic symbols (mutually exclusive with ``numbers``).
95-
coords : array
96-
Atomic coordinates (in Bohr).
97-
basis : dict or str
98-
A string indicating the Gaussian basis set to use, or
99-
a dictionary including the basis set parameters
100-
(exponents and contraction coefficients).
101-
numbers : tuple of ints
102-
Atomic numbers (mutually exclusive with ``symbols``).
103-
charge : int
104-
Total charge.
105-
spin : int
106-
2S (number of alpha electrons minus number of beta electrons).
107-
cart : bool
108-
Whether to use Cartesian Gaussian basis.
109-
verbose : int
110-
Printing level.
111-
trace_coords : bool
112-
Whether to trace atomic coordinates for gradient calculations.
113-
trace_basis : bool
114-
Whether to trace basis set parameters for gradient calculations.
115-
116-
Notes
117-
-----
118-
The molecular composition (i.e., ``symbols`` or ``numbers``)
119-
must be static as input. For dynamic molecular composition,
120-
refer to :class:`pyscfad.ml.gto.MolePad`.
89+
class MoleLite(MoleBase):
90+
"""Molecular information (lightweight version).
91+
92+
Parameters:
93+
symbols: Atomic symbols (mutually exclusive with ``numbers``).
94+
coords: Atomic coordinates (in Bohr).
95+
basis: A string indicating the Gaussian basis set to use, or
96+
a dictionary including the basis set parameters
97+
(exponents and contraction coefficients).
98+
numbers: Atomic numbers (mutually exclusive with ``symbols``).
99+
charge: Total charge.
100+
spin: 2S (number of alpha electrons minus number of beta electrons).
101+
cart: Whether to use Cartesian Gaussian basis.
102+
verbose: Printing level.
103+
trace_coords: Whether to trace atomic coordinates for gradient calculations.
104+
trace_basis: Whether to trace basis set parameters for gradient calculations.
105+
106+
Notes:
107+
The molecular composition (i.e., ``symbols`` or ``numbers``)
108+
must be static as input. For dynamic molecular composition,
109+
refer to :class:`~pyscfad.ml.gto.mole_pad.MolePad`.
121110
"""
122111
def __init__(
123112
self,
124113
symbols: tuple[str, ...] | None = None,
125-
coords: Array | None = None,
114+
coords: ArrayLike | None = None,
126115
basis: dict | str | None = None,
127116
numbers: tuple[int, ...] | None = None,
128117
charge: int = 0,
@@ -171,7 +160,12 @@ def atom_pure_symbol(
171160
def atom_coords(
172161
self,
173162
unit: str = "Bohr",
174-
):
163+
) -> Array:
164+
"""Atom coordinates.
165+
166+
Parameters:
167+
unit: Units of returned coordinates, can be ``Bohr`` or ``Angstrom``.
168+
"""
175169
if not is_au(unit):
176170
return self.coords * BOHR
177171
else:
@@ -180,7 +174,7 @@ def atom_coords(
180174
def copy(
181175
self,
182176
deep: bool = True,
183-
) -> Mole:
177+
) -> MoleLite:
184178
import copy
185179
newmol = self.view(self.__class__)
186180
if not deep:
@@ -193,7 +187,10 @@ def copy(
193187
newmol._env = np.copy(self._env)
194188
return newmol
195189

196-
def build(self, *args, **kwargs):
190+
def build(self, *args, **kwargs) -> MoleLite:
191+
"""Placeholder for post-init processing.
192+
Can be used for caching one-time computed quantities.
193+
"""
197194
return self
198195

199196
def intor(
@@ -202,10 +199,32 @@ def intor(
202199
comp: int | None = None,
203200
hermi: int = 0,
204201
aosym: str = "s1",
205-
out: Array | None = None,
202+
out: ArrayLike | None = None,
206203
shls_slice: tuple[int, ...] | None = None,
207-
grids: Array | None = None,
204+
grids: ArrayLike | None = None,
208205
) -> Array:
206+
"""Integral generator.
207+
208+
Parameters:
209+
intor_name: Name of the integral.
210+
comp: Components of the integrals, e.g. ``int1e_ovlp_dr10`` has 3 components.
211+
hermi: Hermitian symmetry of 1e integrals, can be
212+
`0` (no symmetry), `1` (hermitian), and `2` (anti-hermitian).
213+
aosym: Permutation symmetry of 2e integrals, can be
214+
`s1`, `s2`, `s4`, and `s8`.
215+
out: Not used.
216+
shls_slice: Label the start-stop shells for each index in the integral.
217+
For example, the 8-element tuple for the 2e integral
218+
tensor ``(ij|kl) = intor('int2e')`` are specified as
219+
``(i0, i1, j0, j1, k0, k1, l0, l1)``.
220+
grids: Not used.
221+
222+
Returns:
223+
Computed integral as an array.
224+
225+
See also:
226+
:func:`pyscf.gto.Mole.intor`
227+
"""
209228
del out, grids
210229

211230
intor_name = self._add_suffix(intor_name)
@@ -230,8 +249,8 @@ def intor(
230249

231250
def set_common_origin(
232251
self,
233-
coord: Array,
234-
) -> Mole:
252+
coord: ArrayLike,
253+
) -> MoleLite:
235254
if self._env is None:
236255
raise RuntimeError("{self}._env is not initialized, "
237256
"possibly because basis is not set.")
@@ -245,15 +264,15 @@ def set_common_origin(
245264

246265
def with_common_origin(
247266
self,
248-
coord: Array,
267+
coord: ArrayLike,
249268
):
250269
coord0 = np.copy(self._env[PTR_COMMON_ORIG:PTR_COMMON_ORIG+3])
251270
return self._TemporaryMoleContext(self.set_common_origin, (coord,), (coord0,))
252271

253272
def set_rinv_origin(
254273
self,
255-
coord: Array,
256-
) -> Mole:
274+
coord: ArrayLike,
275+
) -> MoleLite:
257276
if self._env is None:
258277
raise RuntimeError("{self}._env is not initialized, "
259278
"possibly because basis is not set.")
@@ -267,7 +286,7 @@ def set_rinv_origin(
267286

268287
def with_rinv_origin(
269288
self,
270-
coord: Array,
289+
coord: ArrayLike,
271290
):
272291
coord0 = np.copy(self._env[PTR_RINV_ORIG:PTR_RINV_ORIG+3])
273292
return self._TemporaryMoleContext(self.set_rinv_origin, (coord,), (coord0,))
@@ -291,7 +310,9 @@ def from_pyscf(
291310
mol: MoleBase,
292311
trace_coords: bool = False,
293312
trace_basis: bool = False,
294-
) -> Mole:
313+
) -> MoleLite:
314+
"""Initialize from :class:`pyscf.gto.Mole` object.
315+
"""
295316
if not mol._built:
296317
raise KeyError(f"{mol} not built")
297318
if mol.ecp or mol.pseudo:
@@ -327,6 +348,8 @@ def to_pyscf(
327348
output: str | None = None,
328349
max_memory: int | None = None,
329350
) -> MoleBase:
351+
"""Convert to :class:`pyscf.gto.Mole` object.
352+
"""
330353
coords = ops.to_numpy(self.coords)
331354
atom = [[a, tuple(x.tolist())] for a, x in zip(self.symbols, coords)]
332355

@@ -353,14 +376,13 @@ def to_pyscf(
353376

354377
energy_nuc = energy_nuc
355378

356-
MoleLite = Mole
357379

358380
def gaussian_int(
359381
n: int | numpy.ndarray,
360-
alpha: Array,
382+
alpha: ArrayLike,
361383
) -> Array:
362384
r"""Gaussian integral.
363-
Computes :math:`\int_0^\infty x^n exp(-alpha x^2) dx`.
385+
Computes :math:`\int_0^\infty x^n exp(-\alpha x^2) dx`.
364386
"""
365387
from pyscfad.scipy.special import gamma
366388
n1 = (n + 1) * .5
@@ -369,7 +391,7 @@ def gaussian_int(
369391
@with_doc(pyscf.gto.mole.gto_norm.__doc__)
370392
def gto_norm(
371393
l: int | numpy.ndarray,
372-
expnt: Array,
394+
expnt: ArrayLike,
373395
) -> Array:
374396
assert numpy.all(l >= 0)
375397
return 1. / np.sqrt(gaussian_int(l*2+2, 2*expnt))
@@ -432,7 +454,7 @@ def make_bas_env(
432454
return _bas, _env
433455

434456
def make_env(
435-
mol: Mole,
457+
mol: MoleLite,
436458
) -> tuple[numpy.ndarray, numpy.ndarray, Array]:
437459
"""Make ``_atm``, ``_bas``, and ``_env`` for
438460
interfacing with libcint.

pyscfad/ml/gto/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
15-
from .basis_array import make_basis_array, BasisArray
16-
from .mole_pad import MolePad
14+
"""
15+
Molecular sturcture and Gaussian type orbital integrals
16+
"""
17+
from pyscfad.ml.gto.basis_array import make_basis_array, BasisArray
18+
from pyscfad.ml.gto.mole_pad import MolePad

0 commit comments

Comments
 (0)