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.
SO(3) Wigner-D grid machinery (consumed by SO3GridNet in grid_net.py, which backs the node_wise_so3, message_node_so3, and ffn_so3_grid paths): resolve_so3_grid, _build_so3_frame_set, and SO3GridProjector are ported here. The SO(3) projection matrices are assembled at init time with pure numpy via the Wigner-D quadrature (WignerDCalculator) over a Lebedev x gamma rotation grid, matching the pt float64 buffers to machine precision.
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). | |
Project SO(3) coefficients to/from a Wigner-D grid with frame indices. |
Functions#
| Resolve the default S2 grid resolution. |
| Resolve default grids or validate already-resolved low-level grids. |
| Resolve the default SO(3) quadrature as Lebedev sphere times gamma samples. |
| Build the symmetric frame-index set with zero first. |
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).
- class deepmd.dpmodel.descriptor.dpa4_nn.projection.SO3GridProjector(*, lmax: int, mmax: int | None = None, kmax: int = 1, precision: str = DEFAULT_PRECISION, lebedev_precision: int | None = None, coefficient_layout: str = 'packed')[source]#
Bases:
BaseGridProjectorProject SO(3) coefficients to/from a Wigner-D grid with frame indices.
The coefficient axis is packed as
(l, m, k)with ordinary SeZM(l, m)order outside and the configured frame set inside each row. A frame index outside[-l, l]is kept as a zero column/row. This keeps the tensor layout regular while preserving the exact per-degree frame support.- Parameters:
- lmax
Maximum spherical harmonic degree.
- mmax
Maximum order kept in the coefficient layout. If None, use
lmax.- kmax
Frame-index half-width; the frame set is
{0, -1, 1, ..., -kmax, kmax}.- precision
Buffer precision used by the projection matrices.
- lebedev_precision
Explicit Lebedev rule precision. 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.
- _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].
- deepmd.dpmodel.descriptor.dpa4_nn.projection._normalize_s2_grid_resolution(lmax: int, mmax: int, grid_resolution_list: list[int] | None, *, method: str) list[int][source]#
Resolve default grids or validate already-resolved low-level grids.
- deepmd.dpmodel.descriptor.dpa4_nn.projection.resolve_so3_grid(lmax: int, *, kmax: int = 1, lebedev_precision: int | None = None) tuple[int, int, int][source]#
Resolve the default SO(3) quadrature as Lebedev sphere times gamma samples.
The Lebedev precision follows the same conservative
3*lmaxrule used by the S2 grid path. The gamma grid is chosen for the quadratic grid products used by the SO(3) grid nets, whose third-angle frequency can reachk1 + k2 - kout.