Force Operators
forces
Force operators for lattice field evolution using autodiff.
All potential-derived forces use JAX autodiff, guaranteeing correctness and energy conservation in symplectic integrators.
Design principles:
- Forces are computed as \(F = -\frac{\partial H}{\partial q}\) via autodiff
- Spatial operators (Laplacians) use finite differences (appropriate for lattices)
- Factory functions return JIT-compiled, cached force functions
- Support for both flat spacetime and expanding universe (FRW)
Example
make_scalar_force(potential, dx)
Create force function for free scalar field (no gauge coupling).
Computes \(F(\phi) = \nabla^2\phi - dV/d\phi\) where:
- \(\nabla^2\) is the discrete Laplacian (finite differences)
- \(dV/d\phi\) is computed via autodiff
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
ScalarPotential | PotentialFunction
|
ScalarPotential instance or legacy potential function |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array], Array]
|
JIT-compiled function: field -> force |
Example
Source code in jaxlatt/operators/forces.py
make_coupled_scalar_force(potential, dx)
Create force for scalar field coupled to gauge field (flat spacetime).
Computes \(F_\phi = D^2\phi - dV/d\phi\) where:
- \(D^2\) is the covariant Laplacian (includes gauge links)
- \(dV/d\phi\) is computed via autodiff
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
ScalarPotential | PotentialFunction
|
ScalarPotential instance or legacy potential function |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, Array], Array]
|
JIT-compiled function: (phi, links) -> force |
Example
Source code in jaxlatt/operators/forces.py
make_coupled_scalar_force_expanding(potential, dx)
Create force for scalar field in expanding FRW universe.
Computes \(F_\phi = (1/a^2) D^2\phi - a^2 \, dV/d\phi^*\) where:
- \(D^2\) is the covariant Laplacian
- \(dV/d\phi\) is computed via autodiff
- \(a\) is the scale factor
Note: The Hubble friction term \(-2H\pi\) is NOT included here; it should be applied separately in the evolution equation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
ScalarPotential | PotentialFunction
|
ScalarPotential instance or legacy potential function |
required |
dx
|
float
|
Comoving lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, Array, float], Array]
|
JIT-compiled function: (phi, links, a) -> force |
Example
Source code in jaxlatt/operators/forces.py
make_rescaled_scalar_force(potential, dx)
Create force for rescaled field χ = aφ (eliminates Hubble friction).
The rescaled field evolution equation is:
where \(V_\mathrm{eff}\) is the effective potential for \(\chi\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
ScalarPotential | PotentialFunction
|
ScalarPotential for physical field φ (not χ) |
required |
dx
|
float
|
Comoving lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, Array, float, float], Array]
|
JIT-compiled function: (chi, links, a, addot) -> force |
Example
Source code in jaxlatt/operators/forces.py
make_gauge_force(g, dx)
Create force on electric field from pure gauge + scalar coupling.
Computes F_E for all three directions. This is geometric and doesn't particularly benefit from autodiff, but is provided here for API consistency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
float
|
Gauge coupling constant |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, Array], Array]
|
JIT-compiled function: (phi, links) -> force array (3, N, N, N) |
Source code in jaxlatt/operators/forces.py
make_gauge_force_expanding(g, dx)
Create force on electric field in expanding universe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
float
|
Gauge coupling constant |
required |
dx
|
float
|
Comoving lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Array, Array, float], Array]
|
JIT-compiled function: (phi, links, a) -> force array (3, N, N, N) |
Source code in jaxlatt/operators/forces.py
make_forces_from_hamiltonian(potential, g, dx)
Create scalar and gauge forces from full Hamiltonian via autodiff.
This guarantees F = -∂H/∂q exactly, useful for: 1. Validating other force implementations 2. Energy conservation checks 3. Novel potentials without analytical derivatives
Note: Slightly slower than specialized implementations due to full Hamiltonian evaluation. Use make_coupled_scalar_force for production.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
potential
|
ScalarPotential | PotentialFunction
|
ScalarPotential or legacy potential function |
required |
g
|
float
|
Gauge coupling constant |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
tuple[Callable, Callable]
|
Tuple of (scalar_force_fn, gauge_force_fn) |
Example
Source code in jaxlatt/operators/forces.py
validate_force_against_manual(autodiff_force, manual_force, rtol=1e-05, atol=1e-08)
Compare autodiff force with manual implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
autodiff_force
|
Array
|
Force computed via autodiff |
required |
manual_force
|
Array
|
Force computed manually |
required |
rtol
|
float
|
Relative tolerance |
1e-05
|
atol
|
float
|
Absolute tolerance |
1e-08
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with comparison metrics |