Skip to content

Size the trap example to a few hundred cells and fix the implicit signal floor - #49

Merged
marpaia merged 2 commits into
masterfrom
marpaia/small-monolayer-trap
Nov 12, 2026
Merged

marpaia merged 2 commits into
masterfrom
marpaia/small-monolayer-trap

Conversation

@marpaia

@marpaia marpaia commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Why

examples/microfluidic_trap.py is the model the README opens in the viewer. Its trap was 120 × 30 × 6 µm: six cell layers deep, with room for several thousand cells before any could leave. A run reached about 8,000 cells by t = 20 and slowed to a crawl without ever reaching a steady state.

Resizing it exposed a solver defect that also explains the Danino clock failure noted in #48, so both are here.

Changes

Implicit signal solver (CPU, Metal, CUDA). The solve raises its absolute tolerance to a float32 floor of epsilon * rms(right_hand_side). The residual's rounding error also scales with the implicit operator's diagonal, so on a lattice that is fine along one axis, or under a strong affine loss, that floor was below what single precision can reach, and a step with little left to resolve ran to the iteration limit and failed with Implicit coupled signal solve did not converge after 10000 iterations. The floor is now multiplied by the operator's largest diagonal entry.

Trap example.

  • The device is 40 × 20 × 1.5 µm beside a 20 µm channel, so the colony is a monolayer of a few hundred cells. The nutrient lattice is re-laid so its fluid sites span the device exactly.
  • Growth is multiplied by a compression factor that falls linearly to zero as a cell's deepest overlap with a neighbor reaches a fifth of its diameter. This is a model choice, not a measured response; see below.
  • MODEL_VERSION is 5, so checkpoints of the previous trap do not resume.

Tests, tutorials, and the README text follow the new geometry. TrapChannelDevice defaults are unchanged, so the Danino clock keeps its device.

Why the compression rule

Resizing alone was not enough. With the Monod rate only, the small trap settled at about 1,850 cells in a space for roughly 230, with most pairs overlapping by three quarters of a diameter: growth is applied regardless of crowding, and contact relaxation cannot push cells out of the mouth fast enough to keep up. With the rule, the trap holds about 280 cells, sheds cells into the channel continuously, and the total settles near 320.

Coupling growth to the contact solve in the engine would be the general answer and is what #41 attempts. This PR does not do that; the rule lives in the example.

Verification

Check Result
Native tests, Metal-enabled build 30/30 pass
Python suite 512 passed, 32 skipped
pre-commit clean
Trap, 3,000 steps, CPU steady at about 320 cells from t ≈ 21; 25 s wall time
Trap, 2,000 steps, Metal steady at about 320 cells
Danino clock, 1,100 steps, CPU runs (stopped at step 748 before the solver fix)

A new solver test settles a stiff lattice to its steady profile; it aborts without the floor change and passes with it. A new trap test checks that the trap fills, keeps shedding cells, holds a steady population, and keeps every cell inside the walls.

Not covered

  • CUDA is not compiled or run. The CUDA edit passes one more argument to the implicit solve, mirroring Metal. The CUDA compile workflow should run before merge.
  • Solver iteration counts shift slightly wherever the floor decides convergence, because the floor is higher by the operator scale (about 1.4× on the previous trap lattice).
  • Cells in the packed trap still overlap moderately (a tenth of pairs by more than a quarter diameter).
  • The Danino clock and biopixel trap keep their large devices and still grow to thousands of cells.

🤖 Generated with Claude Code

The implicit signal solve raises its absolute tolerance to a float32
floor of epsilon times the right-hand side's RMS. The residual is the
right-hand side minus the implicit operator applied to the iterate, so
its rounding error also grows with the operator's diagonal. On a
lattice that is fine along one axis, or under a strong affine loss, the
floor sat below what single precision can reach and a step that had
little left to resolve ran to the iteration limit and failed.

The floor is now multiplied by the largest diagonal entry of the
implicit operator. The Danino clock, which stopped at 1,024 cells as
its first AHL pulse raised the loss, runs through it.
The trap was 120 by 30 by 6 micrometers, six cell layers deep, and held
several thousand cells before any could leave it, so a run slowed long
before it reached a steady state. It is now 40 by 20 by 1.5 beside a
20-wide channel, on a lattice whose fluid sites span the device exactly.

Growth is multiplied by a compression factor that falls to zero as a
cell's deepest overlap with a neighbor reaches a fifth of its diameter.
Without it the packed colony keeps elongating into itself faster than
contact relaxation can push cells out of the trap mouth. With it the
trap holds about 280 cells, sheds cells into the channel continuously,
and settles near 320 in total.
@marpaia
marpaia merged commit 4a4ce05 into master Nov 12, 2026
3 checks passed
@marpaia
marpaia deleted the marpaia/small-monolayer-trap branch November 12, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant