Examples¶
Each example is a Python script in the
examples/ directory of the
repository. Its page shows the code with the output that it produced when the
site was built. To run an example yourself, open it in Google Colab, download
the notebook, or run the script with python.
-
Simulate a gas microbubble driven by a short ultrasound pulse. You run a preset in five lines, build the same model from its parts, and then compile the simulation once so that every later run takes milliseconds.
-
Shape the ultrasound that drives a bubble. You compare carrier shapes, combine pulses with arithmetic, sweep the frequency with a chirp, and load a pressure trace measured on a hydrophone. Then you drive the same bubble with the chirp and with the measured trace.
-
Compare the physical parts of a bubble model. You drive an uncoated bubble, a lipid-coated contrast agent, and a polymer-shelled agent with the same pulse, and you see how the lipid shell's surface tension changes with the radius. Then you swap the gas law and the surrounding medium.
-
Solve one bubble with three equations of motion, from the incompressible Rayleigh-Plesset equation to the Keller-Miksis equation, which accounts for the compressibility of the liquid. Then raise the drive pressure to see where stable oscillation gives way to inertial cavitation.
-
Run thousands of bubbles at once.
jax.vmapsimulates a row of bubbles of different sizes in one call, andGridSweepmaps the response over a grid of radius, frequency, and pressure on every CPU core. The map is checked against linear resonance theory, collected batch by batch, saved to a NumPy file, and drawn from that file. -
A hydrophone measures the pressure that a bubble radiates, not its radius. Compute that pressure with
IncompressibleMonopoleandQuasiAcoustic, turn it into a Hann-windowed spectrum without aliasing, and map how the spectrum changes with drive pressure: harmonics at low pressure, then broadband noise once the bubble collapses inertially. -
jbubble integrates with the explicit
Dopri5solver by default, which suits microbubbles. Small or viscous bubbles make the equations stiff. Measure where the implicit solver ofSolverConfig.stiff()wins, see howmax_stepsandconvergedreport a solve that runs out of steps, and see why a stiff problem needs the implicit solver for gradients. -
Add your own laws without touching jbubble. Subclass
Propertyfor a state-dependent coefficient, subclassMediumModelfor a new surrounding medium, and plug both intoKellerMiksis. Then replace a law that you don't know with a neural network throughNeuralProperty, and differentiate a simulation with respect to its weights. -
Every jbubble simulation is a JAX function, so
jax.graddifferentiates any scalar result with respect to any model input, straight through the ODE solve. In this example, you check a gradient against finite differences, compute a whole sensitivity curve in onejax.vmap(jax.grad(...))call, and use the gradient to climb a response map with an optax optimiser. -
Fit shell parameters to radius curves
Estimate the elasticity and the dilatational viscosity of a lipid shell from noisy radius-time curves recorded at three driving pressures. In this example, you declare the unknowns with
Parameterbounds, fit all three recordings at once withfit_parameters, and look at the loss landscape that the optimiser walks across. -
Learn a shell law with a neural network
When you don't know the form of a constitutive law, you can learn it from data. In this example, a small neural network takes the place of the surface tension \(\sigma(R)\) of a lipid shell, and
fit_parameterstrains its weights on radius curves recorded at six driving pressures. The network recovers the buckling, elastic, and ruptured regimes of the Marmottant law without being told that they exist.










