sft-wick: Feynman-Diagram Expansion for Stochastic Field Theories¶
sft-wick automates perturbative calculations for stochastic (partial) differential equations in the Martin–Siggia–Rose (MSR) response-field formalism. Starting from a Langevin-type field equation — a deterministic drift plus noise that may be non-Gaussian and spatially correlated — it builds the interaction action, applies Wick’s theorem to expand arbitrary field moments order by order, and writes every term using just two two-point propagators: the correlation function \(C = \langle\phi\phi\rangle\) and the response (Green’s) function \(R = \langle\phi\psi\rangle\).
Key Features¶
Three-layer API — pick your abstraction: L0 symbolic / L1 workflow (
System,Expansion,Propagators,SweepResult) / L2 YAML + CLI (sft-wick run config.yaml).No SymPy dependency — custom lightweight expression tree with exact rational arithmetic via
fractions.Fraction.MSR-optimised contraction — exploits the constraint \(\langle\psi\,\psi\rangle = 0\) to skip vanishing pairings entirely.
Feynman diagram generation —
networkx-based graph representation withmatplotlibrendering (correlation \(C\) as solid blue lines, response \(R\) as dashed red arrows).LaTeX output — every expression renders to publication-ready LaTeX, with configurable propagator names.
Numerical evaluation — QMC with causal simplex mapping and O(1/N) convergence; separable / rotational / general spatial homogeneity modes; optional closed-form C bypass.
Time-dependent linear operator and spacetime-dependent non-local couplings both supported end-to-end through the L1 API.
Quick Start (L2 — config file)¶
The recommended entry point for any new analysis. Write a YAML
config once, run it from the shell, iterate with --override or
edits. The CLI registers automatically on install.
# demo1_config.yaml
system:
field: {name: phi, n_components: 2}
linear: {type: diagonal, gamma: [1.0, 1.0]}
vertices:
- name: F
coupling: # bare F; MSR factor
- [[0.0, 0.0], [0.0, 1.0]] # applied automatically
- [[0.0, 0.5], [0.5, 0.0]]
noise:
kappa2:
type: separable_translation
temporal: {type: exponential, lam: 0.05, sigma_t: 0.3}
spatial: {type: exponential, sigma_x: 1.0}
expand:
observable: ["phi_a(x)", "phi_b(y)"]
orders: [0, 2, 4]
propagators: {t_max: 15.0, n_grid_t: 60}
sweep:
positions_grid: {x: [0.0], y: [0.0, 0.5, 1.0, 2.5]}
t_final_grid: [1.0, 15.0]
component_pairs: [[0, 0], [1, 1]]
n_samples: 8192
seed: 42
sft-wick run demo1_config.yaml
sft-wick run demo1_config.yaml --override sweep.seed=7
sft-wick run demo1_config.yaml --dry-run # validate only
See Workflow API (L1 + L2) for the complete YAML schema and
examples/demo1_config.yaml / examples/demo2_config.yaml
for non-local vertices, closed-form \(C\) hooks, and dynamic
couplings.
Quick Start (L1 — Python, for programmatic use)¶
The same workflow expressed directly in Python — use this when embedding the pipeline inside a larger script:
import numpy as np
import sft_wick as sw
F = np.zeros((2, 2, 2))
F[0, 1, 1] = 1.0
F[1, 0, 1] = F[1, 1, 0] = 0.5
system = sw.System(
field=sw.FieldSpec("phi", n_components=2),
linear=sw.DiagonalA(gamma=[1.0, 1.0]),
vertices=[sw.LocalVertex("F", coupling=F)], # bare F
noise=sw.GaussianNoise(kappa2=sw.SeparableTranslation(
temporal=sw.ExponentialTemporal(lam=0.05, sigma_t=0.3),
spatial=sw.ExponentialSpatial(sigma_x=1.0),
)),
)
expansion = system.expand(("phi_a(x)", "phi_b(y)"),
orders=[0, 2, 4])
props = system.propagators(t_max=15.0, n_grid_t=60)
sweep = expansion.sweep(
props,
positions_grid={"x": [0.0], "y": [0.0, 0.5, 1.0, 2.5]},
t_final_grid=[1.0, 15.0],
component_pairs=[(0, 0), (1, 1)],
)
print(sweep.totals())
For the L0 symbolic API (fine-grained control over individual pairings, canonical forms, custom simplification), see User Guide.
Contents
- Installation
- Theoretical Background
- Getting Started
- Step 1 — Install and Import
- Step 2 — Define Fields
- Step 3 — Create an Observable
- Step 4 — Compute the Zeroth-Order Moment
- Step 5 — Define an Interaction Vertex
- Step 6 — Compute to First Order
- Step 7 — Inspect Feynman Diagrams
- Step 8 — Format as LaTeX
- Step 9 — Conventions: Itô and Response Phase
- Next Steps
- User Guide
- Examples
- Verification
- API Reference
sft_wick.workflow— High-Level Workflow API (L1 + L2)sft_wick.fields— Fields and Field Operatorssft_wick.expressions— Symbolic Expression Treesft_wick.vertices— Vertices and Vertex Instancessft_wick.action— Action Definitionsft_wick.wick— Wick Contraction Enginesft_wick.propagators— Propagator Contraction Rulessft_wick.perturbation— Perturbative Expansion Driversft_wick.simplify— Expression Simplificationsft_wick.evaluate— Numerical Evaluation Pipelinesft_wick.diagrams— Feynman Diagram Representationsft_wick.drawing— Diagram Renderingsft_wick.drawing_tikz— TikZ/PGF Diagram Backendsft_wick.render_style— Visual Style Specificationssft_wick.indices— Index Managementsft_wick.latex— LaTeX Formattingsft_wick._util— Internal Utilities
- Contributing
- Changelog