PyTorch API reference
Install the optional backend with python -m pip install '.[torch]' and
import it from specd.torch. It runs without the native extensions.
See PyTorch backend for model conventions, differentiation,
kernel units, and runnable examples.
Solver workspace
- class specd.torch.SpecWorkSpace(wavetype=None, *, device=None, ngll=7, ngrl=30, halfspace_wavelengths=50)[source]
Bases:
objectIndependent PyTorch implementation of the SpecSWD spectral solver.
Model tensors retain their graphs. Non-tensor inputs become float64 leaf tensors requiring gradients, accessible through
parameters. Geometry, adaptive element counts, interpolation locations and mode selection are discrete, fixed decisions during differentiation.- get_egnfunc(imode, return_displ=True, return_left=False)[source]
Return displacement at SEM nodes or the raw right eigenvector.
Anisotropic displacements use radial/transverse/vertical components; Rayleigh uses the native real polarization amplitude convention.
- group_velocity()[source]
All modes at once using operator JVPs and eigenvalue perturbation.
For P(k,f)r=0, dk/df = -(l^H P_f r)/(l^H P_k r). Forward-mode autodiff computes the operator partials without one eigensolver backward per mode. Keeping the eigenvectors in the graph supports group kernels.
- initialize(wavetype, z, rho, *, vph=None, vpv=None, vsh=None, vsv=None, eta=None, Qa=None, Qc=None, Qn=None, Ql=None, c21=None, Qani=None, reference_frequency=1.0)[source]
- kernels(imode=0, *, observable='phase', component='real', create_graph=False)[source]
Return named autograd derivatives on the original model grid.
Q derivatives here are d/dQ.
get_phase_klandget_group_klconvert these to d/d(Q^-1), matching the native kernel convention. Anisotropic group kernels use the radial group component.
- property parameters
Tensor dispersion tables
- class specd.torch.DispersionTable(frequency_hz: 'torch.Tensor', azimuth_deg: 'torch.Tensor', phase_rows: 'list', group_rows: 'list | None' = None, group_components: 'tuple' = ('radial',), phase_mode_rows: 'list | None' = None, group_mode_rows: 'list | None' = None)[source]
Bases:
object- azimuth_deg: Tensor
- frequency_hz: Tensor
- classmethod from_hdf5(path, *, device=None)[source]
Read detached float64/complex128 tensors from a v1 dispersion file.
- group_components: tuple = ('radial',)
- group_mode_rows: list | None = None
- group_rows: list | None = None
- phase_mode_rows: list | None = None
- phase_rows: list