deepmd.dpmodel.descriptor.dpa4_nn.projection#
S2 grid projection helpers for DPA4/SeZM function-space nonlinearities.
This module is the dpmodel port of deepmd.pt.model.descriptor.sezm_nn.projection, restricted to the Lebedev S2 quadrature path used by the core DPA4 configuration (lebedev_quadrature=True). The projectors only handle basis transforms: a projector maps coefficient tensors to a fixed quadrature grid, and maps grid fields back to coefficients with the matching quadrature rule.
Ported names: BaseGridProjector, S2GridProjector (Lebedev branch), resolve_s2_grid_resolution (as-is, both methods — pure arithmetic), and _normalize_s2_grid_resolution.
Skipped names (SO(3) Wigner-D grid machinery; consumed only by SO3GridNet in pt grid_net.py, which backs the node_wise_so3, message_node_so3, and ffn_so3_grid paths — all disabled in the core DPA4 config): SO3GridProjector, resolve_so3_grid, _build_so3_frame_set.
Not ported (guarded): the e3nn product-grid branch of S2GridProjector (grid_method="e3nn", i.e. lebedev_quadrature=False) raises NotImplementedError at construction. Only the Lebedev path reproduces to-grid/from-grid roundtrip identities at machine precision.
The Lebedev projection matrices are assembled at init time with pure numpy: load_lebedev_rule replaces the pt Lebedev loader (same packaged data) and real_spherical_harmonics exactly replaces the e3nn call spherical_harmonics(list(range(lmax+1)), points, normalize=True,
normalization="norm"), so the buffers match the pt float64 buffers to machine precision.
Classes#
Base class for fixed coefficient-to-grid projection matrices. | |
Project SO(3) coefficients to/from a flattened S2 grid (Lebedev only). |
Functions#
| Resolve the default S2 grid resolution. |
| Resolve default grids or validate already-resolved low-level grids. |
Module Contents#
- class deepmd.dpmodel.descriptor.dpa4_nn.projection.BaseGridProjector(*, lmax: int, mmax: int | None, precision: str = DEFAULT_PRECISION, n_frames: int, coefficient_layout: str)[source]#
Bases:
deepmd.dpmodel.NativeOPBase class for fixed coefficient-to-grid projection matrices.
Subclasses build
to_grid_matwith shape(G, J)andfrom_grid_matwith shape(J, G), whereGis the number of grid samples andJis the flattened coefficient axis consumed by the grid net. For ordinary S2 projections,Jis the SO(3) feature coefficient axis:D = (lmax + 1)^2in packed layout, or the retainedD_maxis in m-major layout.- abstractmethod call(*args: Any, **kwargs: Any) Any[source]#
Projectors expose
to_grid/from_grid; there is no forward.
- to_grid(embedding: Any) Any[source]#
Project flattened coefficients
(N, J, C)to grid fields(N, G, C).
- from_grid(grid: Any) Any[source]#
Project grid fields
(N, G, C)back to flattened coefficients(N, J, C).
- _build_coefficient_index() numpy.ndarray[source]#
Build the coefficient subset consumed by the projector matrices.
- abstractmethod _build_projection_mats(coeff_index: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]#
Build
to_grid_mat (G, J)andfrom_grid_mat (J, G).
- class deepmd.dpmodel.descriptor.dpa4_nn.projection.S2GridProjector(*, lmax: int, mmax: int | None = None, precision: str = DEFAULT_PRECISION, grid_resolution_list: list[int] | None = None, coefficient_layout: str = 'packed', grid_method: str = 'e3nn')[source]#
Bases:
BaseGridProjectorProject SO(3) coefficients to/from a flattened S2 grid (Lebedev only).
- Parameters:
- lmax
Maximum spherical harmonic degree.
- mmax
Maximum order kept in the coefficient layout. If None, use
lmax.- precision
Buffer precision used by the projection matrices.
- grid_resolution_list
Two-element resolution list
[precision, n_points]forgrid_method='lebedev'. If None, resolved automatically.- coefficient_layout
Coefficient ordering expected by the caller: -
"packed": packed(l, m)order, optionally truncated bymmax. -"m_major": reduced m-major order used insideSO2Convolution.- grid_method
S2 quadrature backend. Must be
"e3nn"or"lebedev"; only"lebedev"(lebedev_quadrature=True) is ported to dpmodel.
- _rescale_truncated_matrix(mat: numpy.ndarray) None[source]#
- _build_projection_mats(coeff_index: numpy.ndarray) tuple[numpy.ndarray, numpy.ndarray][source]#
Build
to_grid_mat (G, J)andfrom_grid_mat (J, G).
- deepmd.dpmodel.descriptor.dpa4_nn.projection.resolve_s2_grid_resolution(lmax: int, mmax: int, *, method: str = 'e3nn') list[int][source]#
Resolve the default S2 grid resolution.
For
method='e3nn', the automatic default uses even azimuthal samplingR_phi = 2 * mmax + 4and even polar samplingR_theta = ceil_even(3 * lmax + 2).For
method='lebedev', the automatic default picks the smallest packaged Lebedev rule whose algebraic precision is at least3 * lmaxand returns[precision, n_points].