Skip to content

Let models change the inlet media during a run - #50

Merged
marpaia merged 1 commit into
masterfrom
marpaia/inlet-signal-schedule
Nov 13, 2026
Merged

marpaia merged 1 commit into
masterfrom
marpaia/inlet-signal-schedule

Conversation

@marpaia

@marpaia marpaia commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8.

Problem

The media entering a device had one composition for the whole run. apply_to_grid set a fixed inlet boundary, and the solved flow carried it in, but nothing could replace a fixed boundary's values after configure_signal_grid. A model could not switch reservoirs, pulse an inducer, or ramp a nutrient, which is most of what a microfluidic experiment does at its inlet.

Changes

  • Native: SignalGrid::set_boundary_values(face, values) and Simulation::set_signal_boundary_values replace the per-signal values of a fixed boundary between steps. A new GridFace enum names the six faces. Only the values change, never the boundary kind, so the transport operator keeps its structure.
  • Python: Simulation.set_signal_boundary_values(GridFace, values) is bound, and GridFace is exported.
  • Device helpers: set_inlet_values(simulation, values) on the trap devices, and InletSchedule for a composition that switches or ramps over model time (InletSchedule.pulse for the common case).
  • Docs: a "Changing the inlet media" section in the microfluidics tutorial, and a note in the grid-signaling ADR.

No backend kernel changes were needed: CPU, Metal, and CUDA already read the fixed values from the grid on every step. The values live in the grid spec, so checkpoints carry them without a format change.

Verification

Check Result
Native tests, Metal-enabled build 30/30 pass
Python suite 526 passed, 34 skipped
pre-commit clean

New tests:

  • A value set mid-run gives bit-identical levels to a grid configured with that value from the same field (CPU and Metal).
  • A pulse at the inlet reaches a downstream probe at the flow's transit time, within 10%, and clears afterwards (CPU and Metal).
  • A checkpoint taken after a mid-run change resumes on the same trajectory.
  • Rejections: a non-fixed face, a wrong value count, a negative value, and a simulation without a grid. A rejected call leaves the inlet unchanged.
  • InletSchedule switching, ramping, pulse, and validation.

Not covered

  • CUDA is not compiled or run. No CUDA source changed, but the shared headers did, and the CUDA parametrizations of the new tests were skipped here. The CUDA compile workflow should run before merge.
  • The outlet is still a fixed-value boundary. Examples pass outlet_values=[0.0], which also acts as a diffusive sink at the outlet. A proper outflow boundary needs kernel changes on all three backends and is left for a follow-up.
  • The inlet composition is uniform across the inlet face. Two-stream or gradient inlets are not expressible.
  • No new example model. The tutorial shows the usage as a snippet.

🤖 Generated with Claude Code

The media entering a device had one fixed composition for the whole
run: a fixed boundary's values were set when the signal grid was
configured and nothing could replace them, so a model could not switch
reservoirs, pulse an inducer, or ramp a nutrient.

SignalGrid::set_boundary_values and Simulation.set_signal_boundary_values
replace the per-signal values of a fixed boundary between steps. The
boundary kind does not change, so the transport operator keeps its
structure, and every backend already reads the values from the grid on
each step. The values are part of the checkpointed grid.

Device helpers gain set_inlet_values, and InletSchedule describes a
composition that switches or ramps over model time.
@marpaia
marpaia merged commit e29a8d4 into master Nov 13, 2026
3 checks passed
@marpaia
marpaia deleted the marpaia/inlet-signal-schedule branch November 13, 2026 11:54
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.

add chemicals and cells comming from the source flow

1 participant