yasfpy.coupling.backends ======================== .. py:module:: yasfpy.coupling.backends .. autoapi-nested-parse:: Coupling backend implementations. A coupling backend provides the action of the inter-particle coupling operator ``W`` (sometimes called the coupling matrix) used in the multiple-scattering linear system. Backends differ in how they compute/apply that operator: - dense: precompute all pairwise lookup tables and apply the exact dense matvec - tiled dense: compute pairwise lookup tables for particle tiles on the fly - near/far: prototype approximation applying only near-field interactions .. rubric:: References The VSWF-based translation/coupling approach is described in classic multiple scattering formulations :cite:`Waterman-1971-ID50` and in CELES :cite:`Egel-2017-ID1`. Classes ------- .. autoapisummary:: yasfpy.coupling.backends.CouplingBackend yasfpy.coupling.backends.DenseCouplingBackend yasfpy.coupling.backends.TiledDenseCouplingBackend yasfpy.coupling.backends.NearFarCouplingBackend Module Contents --------------- .. py:class:: CouplingBackend Base class for coupling backends. :ivar requires_pairwise_lookups: Whether the backend requires precomputed pairwise lookup tables stored on a :class:`yasfpy.simulation.Simulation` instance. .. py:attribute:: requires_pairwise_lookups :type: bool :value: False .. py:method:: multiply(x, idx = None) :abstractmethod: Apply the coupling operator ``W``. :param x: Input vector/array. :param idx: Optional wavelength/channel index. :returns: ``W @ x``. :rtype: numpy.ndarray .. py:class:: DenseCouplingBackend(simulation) Bases: :py:obj:`CouplingBackend` Exact dense coupling backend. This backend assumes that pairwise lookup tables have been precomputed and stored on the simulation object (``plm``, ``sph_h``, ``e_j_dm_phi``). The actual matvec is delegated to a :class:`yasfpy.coupling.ops.DenseCouplingOps` instance, which may be CPU or CUDA. .. rubric:: Notes The data flow is: - lookups computed by :func:`yasfpy.lookups.compute_lookups` - backend selected by :class:`yasfpy.simulation.Simulation` - matvec executed by :func:`yasfpy.coupling.factory.get_dense_coupling_ops` .. py:attribute:: requires_pairwise_lookups :type: bool :value: True .. py:method:: multiply(x, idx = None) Apply the dense coupling operator ``W``. :param x: Input vector or array. :param idx: Optional wavelength/channel index. :returns: ``W @ x``. :rtype: numpy.ndarray .. py:class:: TiledDenseCouplingBackend(simulation) Bases: :py:obj:`CouplingBackend` Exact dense coupling without O(N^2) lookup tables. This backend computes the same interactions as :class:`DenseCouplingBackend`, but constructs the :func:`yasfpy.functions.misc.mutual_lookup` quantities in particle tiles and immediately applies them to the matvec. This keeps memory usage bounded by tile size. .. rubric:: Notes This backend is currently CPU-only. .. py:attribute:: requires_pairwise_lookups :type: bool :value: False .. py:method:: multiply(x, idx = None) Apply tiled dense coupling. :param x: Input vector/array. :param idx: Optional wavelength/channel index. :returns: ``W @ x``. :rtype: numpy.ndarray :raises NotImplementedError: If GPU execution is requested. .. py:class:: NearFarCouplingBackend(simulation) Bases: :py:obj:`CouplingBackend` Approximate near/far coupling backend (prototype). The current implementation applies *near-field* interactions exactly (via :func:`yasfpy.functions.misc.mutual_lookup`) for particle pairs within a configurable cutoff radius and ignores all remaining (far-field) interactions. Compared to the initial prototype, this backend caches the near-field neighbor structure (per source tile) once, because particle geometry is fixed for the lifetime of a :class:`yasfpy.simulation.Simulation`. .. rubric:: Notes - CPU only (GPU uses the dense GPU kernel today). - This is an approximation unless the radius includes all pairs. .. py:attribute:: requires_pairwise_lookups :type: bool :value: False .. py:method:: multiply(x, idx = None) Apply the near-field-only coupling approximation. :param x: Input vector/array of multipole coefficients. :param idx: Optional wavelength/channel index. :returns: Approximate ``W @ x`` where only near-field pairs contribute. :rtype: numpy.ndarray :raises ValueError: If ``numerics.coupling_near_field_radius`` is not set. :raises NotImplementedError: If GPU execution is requested.