phyz
Multi-physics differentiable simulation.
Pure Rust. GPU-accelerated. Hackable.

phyz is a differentiable simulation engine for articulated rigid bodies, particles, electromagnetic fields, molecular dynamics, and beyond. Every algorithm computes gradients for optimization, control, and learning.

Built on Featherstone's spatial algebra, phyz runs O(n) forward dynamics with analytical Jacobians. Plug in semi-implicit Euler, RK4, or your own solver. Load MuJoCo MJCF models. Batch thousands of environments on GPU.

phyz is early, ambitious, and open source.

use phyz::{ModelBuilder, Simulator, Vec3};
use phyz_diff::analytical_step_jacobians;

// Double pendulum: two revolute joints
let model = ModelBuilder::new()
    .add_revolute_body("upper", -1, 1.0, Vec3::new(0., 0., -1.))
    .add_revolute_body("lower",  0, 0.8, Vec3::new(0., 0., -1.))
    .build();

let mut state = model.default_state();
state.q  = vec![0.5, -0.3];  // joint angles
state.qd = vec![0.0,  0.0];  // velocities

// Simulate with analytical Jacobians at every step
let sim = Simulator::rk4();
let dt = 0.002;

for _ in 0..500 {
    let jac = analytical_step_jacobians(&model, &state, dt);
    sim.step(&model, &mut state, dt);

    // jac.dq_dq0: ∂(next state) / ∂(current state)
    // jac.dq_dtau: ∂(next state) / ∂(applied torques)
    // → chain rule through the trajectory for end-to-end gradients
}

let tip = state.body_position(1);
println!("tip = ({:.3}, {:.3})", tip.x, tip.y);
println!("sensitivity ‖∂q'/∂q₀‖ = {:.2e}", jac.dq_dq0.norm());
phyz-rigid double_pendulum Chaotic two-link chain with joint dissipation. loading wasm... Also: pendulum, chain
phyz-contact sphere_cascade 20 spheres pile up. GJK/EPA + penalty contacts. loading wasm... Also: bouncing_spheres, newtons_cradle
phyz-gpu ensemble_divergence 100 double pendulums. Lyapunov divergence in real time. loading wasm... Also: wave_field, policy_search
phyz-particle granular_column 280 particles. Drucker-Prager yield via MPM. loading wasm... Also: fluid_dam, elastic_blob
phyz-world tendon_demo 4-link chain with sinusoidal tendon actuation. loading wasm... Also: random_chain, phase_portrait
phyz-em double_slit FDTD plane wave. Interference fringes in real time. loading wasm... Also: dipole_radiation, waveguide
phyz-md polymer_chain 40-bead LJ chain. Coil-stretch dynamics. loading wasm... Also: argon_gas, crystal_lattice
phyz-qft u1_plaquette 16x16 U(1) lattice. Metropolis updates at beta=2.0. loading wasm... Also: wilson_loops, phase_transition
phyz-coupling lorentz_spiral Charged particle spiraling in uniform B field. loading wasm... Also: crossed_fields, magnetic_mirror
phyz-gravity solar_system 5 planets. Kepler orbits with post-Newtonian corrections. loading wasm... Also: binary_orbit, precession
phyz-guardian adaptive_dt Fixed vs adaptive timestep. Watch energy drift. loading wasm... Also: energy_monitor, correction_demo
phyz-lbm vortex_street D2Q9 flow around obstacle. Von Karman vortex street. loading wasm... Also: cavity_flow, channel_flow
phyz-prob svgd_particles SVGD converging to a Gaussian mixture target. loading wasm... Also: uncertainty_cone, monte_carlo
phyz-diff gradient_target Gradient descent optimizing angle to hit a target. loading wasm... Also: jacobian_heatmap, sensitivity
phyz-mjcf load_ant Ant kinematic tree: 4 legs with hip and shin joints. loading wasm... Also: load_cartpole, model_editor
phyz-real2sim loss_landscape 2D loss contour with gradient descent path overlay. loading wasm... Also: param_fit, adam_vs_gd
phyz-regge curvature_slice Reissner-Nordstrom edge lengths as color heatmap. loading wasm... Also: symmetry_bars, action_landscape
phyz-compile kernel_ir Physics kernel IR DAG: fields, stencils, binary ops. loading wasm... Also: wgsl_output, fusion_viz