Tools for agent-based modelling indevelopmental biologySteffen PlunderKyoto UniversityInstitute for the Advanced Study of Human Biology (ASHBi)JuliaCon 2024 Einhoven
1. Challenges of Agent-Based Models in Developmental Biology2. Moving towards GPUs... SpatialHashTables.jl3. Small helper for dynamic networks BoundedDegreeGraphs.jl)4. Next steps: GPU implementations of Position-Based Dynamics (PBD) and Vertex Block Decent (VBD)Overview
Show me some code...SpatialHashTables.jl: GPU-capable iteration over pairs of positions within cutoff.BoundedDegreeGraphs.jl: Allocation free graph type. (But not quite GPU ready yet.)+ examples for usage in interdisciplinary projects with biologists.
Part I:Applications in Developmental Biology
What is Agent-Based/Individual-Based Modelling?Find relation between interaction laws and emergent behaviour: "Agent-based models are not per se elegant or structured models, rather, they are a last resort when the nature of things is messy and complex."
Developmental BiologyFigure Source: Gilbert et al, Developmental BiologyToo complex for elegant math/physics models...
Project #1: Modelling of epithelial-to-mesemchymal transitionsthink: skin becomes cancer2019: Started my PhD rewriting the FORTRAN/MATLAB into Julia.Obviously, the combined pipeline became easily 1000x faster ;)
Key ChallengeInput:Timing of phenotype changes{ never, early, normal, late} A: loss of apical adhesionB: loss of basal adhesionS: loss of polarityP: protrusive activitiesINM: rapid apical movementSimulation"Black-Box"Heterogeneity between cells!Biological relevant parametersare not single values, but large ranges!
Need for SpeedPrevious FORTRAN/MATLAB combination:~ 30 seconds per simulation + 1-2 minutes for video/plotsMonte-Carlo Parameter Studywith N = 150.00052 daysJulia Code (same algorithm):~ 8 seconds per simulation + 20 seconds per video/plots (GLMakie.jl)13 daysJulia code (+ position-based dynamics):~ 0.04 seconds per simulation100 minutes0.07 days
SP, Cathy Danesin, Bruno Glise, Marina A. Ferreira, Sara Merino Aceituno, and Eric Theveneau. “Modelling Variability and Heterogeneity of EMT Scenarios Highlights Nuclear Positioning and Protrusions as Main Drivers of Extrusion.” (2024) [Accepted in Nature Communications]Despin-Guitard, Evangéline, SP, Navrita Mathiah, Eric Theveneau, and Isabelle Migeotte. “Occurrence of Non-Apical Mitoses at the Primitive Streak, Induced by Relaxation of Actomyosin and Acceleration of the Cell Cycle, Contributes to Cell Delamination during Mouse Gastrulation.” bioRxiv, (2024)Biological results...
Project: Understanding limb morphogenesiswith Antoine Diez (math) and Rio Tsutsumi (biology)Combined Agent-based Model with Reaction-Diffusion equations (OrdinaryDiffEq/ROCK2 solver) experimental data (R. Tsutsumi)Able to recapitulate several complex biological steps (symmetry breaking & convergent extension) and give new ideas how elongation might be orchestrated. (Work in progress.)
Other modelsBacteria model from Michéle Romanos Anisotropic repulsion from Claudia Wytrzens, Sara Merino-Aceituno Germinal center growthwith Seirin-Lee
Lessons learned1. Plain Julia is already a pretty decent framework for Agent-Based Models. Allows fast development!2. Analysis of simulation results requires often more effort than simulation themselves.
Part II:Towards GPU Agents(SpatialHashTables.jl)
A toy model: a sphere of spheresConsider N particles with pairwise repulsion (within radius R)and attraction to center. Cannonical simulation strategy:Local detection of neighbours (e.g. cell list method)https://github.com/SteffenPL/GPUAgents
Cell list method: Partition space and only iterate neigbouring boxes:
SpatialHashTables.jl: Basic ExampleWell known method, very similar to CellListMaps.jl!Key features:Unbounded domainthanks to hashing!Allocation free &GPU kernel friendly.Minimal interface.
Idea of Spatial Hash Gridsspacialpositionlattice positioncell listindexBoundedGrid123456123456123456(maybe periodically)HashGrid 163426542416134252Details about GPU implementation: See GPU Germs 3, NVIDIA Warp orTeschner et al, Optimized Spatial Hashing for Collision Detection of Deformable Objects
Minimal interfaceConstructorsUpdateIterator
Usage with KernelAbstractions.jlBasically, user decides how to parallelize (for example also via Threads)
Current alternatives in the Julia ecosystemCellListMap.jl...also based on grid based cell lists+ more general cells (e.g. if the domain is not a square)+ sometimes faster CPU multithreading, especially for dense particles like in atomic simulations+ requires less boilderplate code- No GPU support (yet)NearestNeighbours.jl... uses KDTrees+ adaptive and good for non uniform particle distributions+ slower update of new positions- No GPU supportThese are bothgreat packages!
BenchmarksFew neighbours (e.g. collision setting)Many neighbours (intermediate range forces)
Next stepsImprove CPU performance...Implementation on M1 (I don't have a Mac)?Big bottleneck is lack of suitable sorting algorithms for GPUs.Radix sort including pre-allocation would be ideal...Bugs & DocumentationExamples with Agents.jl
Part III:BoundedDegreeGraphs.jland a few tips for coding agents
Dynamic networks and allocationsBiological cells have adhesive bonds which might get created/destroyed. To avoid allocations, one can essentially store edges in a matrix of size: BoundedDegreeGraphs.jl is a Graphs.jl compliant implementation for that.
Basic usage and metadata
Benchmark: allocation free and a bit faster "add/has/rem_edge"
Example Code for Plain Julia Agent-Based Models
Part IV:Next steps: GPU accelerated contact resolutionwith Position-Based Dynamics/Vertex Block Decent
Contact mechanics and stiffness Feasible states: "swiss cheese set"With penalty terms: Going non-smooth: set of orthogonally outward pointing vectors
Comparing position based dynamics (PBD) and a penalty method Models: PBD is fast, stable and easy to implement! 🥳... there must be a catch?! 🤨
History of PBD(2006) Müller, Heidelberger, Hennix, Ratcliff Position Based Dynamics (2013) Macklin, Müller: Position Based Fluids (2015) Wang et al: Chebyshev Semi-Iterative Approach for Accelerating Projective and Position-based Dynamics(2016) Macklin, Müller: XPBD(2019) Macklin et al: Small Steps in Physics Simulation(2024) Anka Chen et al: Vertex Block Decent
Recall the Gauss-Seidel principle: "Use always the newest information available"Linear Algebra:solve only for ith coordinate, easy! Nonlinear equations: Non-smooth equations:
Classical numerical methods for non-smooth dynamical systems Moreau's catch-up scheme: Typical approach for time-stepping schemes: Use Lagranian multipliersTaylor (+ index reduction) Solve for multipliers with iterative methods. Projected Nonlinear Gauss-Seidel (PNGS): Position Based Dynamics: "Don't worry about convergence of local solver, just use n = 1."
Theoretical resultThm. [SP, Sara Merino (2023) arxiv]For first order dynamics, Position-Based Dynamics converges (uniformly).cp. (2011) Bertrand Maury, Juliette Venel: A discrete contact model for crowd motion, ESAIMcomputational costExperiment: github.com/SteffenPL/DifferentialInclusions.jl
Large, accurate time-steps (PNGS) vs small, inaccurate time-steps (PBD)
Relatively easy to implement in Julia with KernelAbstractions.jl & Atomix.jlhttps://github.com/SteffenPL/LearnGPUParticles
Many contacts and self-collisions: Graph coloring neededWe cannot compute the sequential Gauss-Seidel steps in parallel.But with a graph coloring we can break it down into a few parallel steps!(Often, last color can use a Jaccobi step which always works in parallel.)Currently missing: Inaccurate but fast graph coloring (on GPUs).
Next steps:1. More interesting open source examples (maybe in Agents.jl)2. Combine SpatialHashTables.jl + BoundedDegreeGraphs.jl forGraph coloring within PBD3. Possibly, work towards GPU (Newton-Gauss-Seidel style)PDE solver on unstructured meshes
ThanksTo you, the amazing Julia community: