Differentiability
Which Radar inputs carry first-order VJP and JVP derivatives to the data cube, which are refused, and why Radar fails loudly instead of detaching.
Radar computes first-order derivatives of the data cube with respect to scene and target parameters. Reverse mode (VJP, the usual loss.backward()) and forward mode (JVP, torch.autograd.forward_ad) both run through native CUDA companions of the propagation and synthesis kernels. This page lists what is differentiable and how Radar treats everything else.
Turn it on#
Pass grad="vjp" or grad="jvp" to trace, simulate or stream. The default, grad="none", builds no graph. The primal cube is bitwise identical in all three modes.
import torch
from witwin.radar import PointTargets
positions = torch.tensor([[0.0, 0.0, -3.0]], device=radar.device, requires_grad=True)
result = radar.simulate(scene, PointTargets(positions=positions, rcs=1.0), times=(0.0,), grad="vjp")
result.cube.abs().square().sum().backward()
print(positions.grad)See Take gradients for forward mode and more leaves.
Supported leaves#
| Leaf | How you mark it |
|---|---|
| Target positions | PointTargets(positions=t) with t.requires_grad_() or a forward dual |
| Target strength | PointTargets(rcs=t) or PointTargets(amplitude=t) with a 0-dim tensor |
| Mesh vertices | The Mesh vertex tensor of a structure in the Scene |
| Material permittivity and conductivity | PhysicalMaterial(eps_r=t), sigma_e=t (reverse mode for conductivity) |
| Antenna phase centres | Core endpoint positions through endpoints=SensorEndpointIds(...) |
Derivatives reach the cube through every waveform (FMCW spectrum and beat, OFDM, pulsed), through the antenna pattern weights, through aspect-dependent scattering, through adaptive motion interpolation, and through the receiver chain's noise, LNA and AGC stages.
Some derivatives are exactly zero and that is the correct answer: for example, the in-plane component of a mesh vertex gradient, the delay gradient of a rectangular pulse, or the response phase under a magnitude-only loss.
Refused inputs#
Radar refuses a derivative request before any numerical work instead of detaching the tensor and returning a plausible answer with grad is None.
| Input | Why |
|---|---|
Radar pose (position, look_at, up, polarization) | A host declaration. Every element position is derived from it, and detaching would sever the tape silently. Move antennas through SensorEndpointIds instead |
| Waveform, noise, AGC, ADC, LNA, impedance and seed values | Configuration scalars must be host floats. A tensor is refused even without a gradient |
| The ADC input signal | Quantization has no useful derivative |
| Oscillator timestamps and path delays inside phase noise | The Brownian phase has no time derivative |
SMPL pose, shape, pose rate, body position and rotation through SmplPoseDeformation | Not supported through the deformation bridge |
Higher-order derivatives (create_graph=True, nested forward levels) | First order only |
| Diffraction and transmission propagation components | Not available to Radar |
A per-target rcs or amplitude vector without an Aspect raises ValueError: the isotropic response carries one value. With an Aspect, give the vector as amplitude; a vector rcs is still refused.
The processing wall#
Processing splits at the first discrete decision:
- Differentiable:
range_profile,range_doppler_map,beam_cube,matched_filter,tdm_compensate,music_spectrum,music_image. - Refused in both modes:
ca_cfar,os_cfar,ca_cfar_1d,point_cloud,phase_comparison_aoa,fft2_aoa, andDetectionFrame. They threshold, sort or pick peaks.
Write losses on cubes, range profiles, range-Doppler maps or MUSIC spectra. If you need a detection-like loss, build a smooth one from the range-Doppler map yourself.
Noise and reproducibility#
Thermal noise and phase noise are drawn from a counter-based (Philox) generator keyed by Radar.seed. The same seed gives a bitwise identical cube and gradient, so a noisy objective is deterministic for a fixed seed. Change the seed per step if you want stochastic optimization.
What "velocity" means for a gradient#
A forward-mode tangent on a target position is a parameter derivative, not a physical velocity. Doppler comes only from motion you declare (a trajectory, a DynamicScene), and Radar never turns a tangent into a delay rate.