Skip to content

fix: keep every factor of coupled infection rate expressions - #26

Merged
AdishAssain merged 1 commit into
mainfrom
fix/network-infection-rate-expression
Sep 9, 2026
Merged

AdishAssain merged 1 commit into
mainfrom
fix/network-infection-rate-expression

Conversation

@AdishAssain

Copy link
Copy Markdown
Member

Bug

In a multi-patch or grouped model, an infection transition whose rate expression mentioned the parameter beta was replaced by beta * S * lambda. Every other factor in the expression was discarded, and the outcome depended on the parameter's name.

Two-patch SIR template, final I in patch A after 60 days:

Expression Final I
S -> I: beta 0.2113
S -> I: beta * 0.5 0.2113, identical
S -> I: b * 0.5, same value 0.0235

An intervention term such as beta * (1 - efficacy * coverage) therefore ran at full beta with no warning. No test covered a multiplied beta in a coupled model.

Fix

_adjust_infection_rate now multiplies the local flow by the infectious pressure for every infection transition under mixing, which is the rule docs/rate-multiplication.md already documents. The special case, its regex on the parameter name, and the parameters that only served it are removed.

Behaviour change to note

A coupled infection expression that names I or E, for example beta * I / N, is now honoured as written, so the flow carries the local prevalence and the infectious pressure. Before, that double counting was avoided only when the parameter happened to be named beta. The documentation already says not to add a second infectious proportion to a coupled template; the model now logs a warning at construction when it finds one.

The S > 0 guard that existed on one of the two old branches is gone. The local flow already carries S, so a zero S gives a zero flow, and a negative S from solver overshoot gives a restoring flow rather than a frozen negative state.

Tests

  • Coupled flow equals local flow times lambda for the documented template.
  • A constant factor in the expression scales the coupled flow.
  • The parameter name does not change the result.
  • Recovery flow is not scaled by the infectious pressure.
  • Warning is logged for an expression naming I, and not for a per-capita rate.

ruff check, ruff format --check, and pytest with 183 passed are clean.

In multi-patch and grouped models an infection expression that named
beta was replaced by beta * S * lambda, so any other factor in the
expression was dropped and the result depended on the parameter name.
Multiply the local flow by the infectious pressure for every infection
transition, as documented in rate-multiplication.md.

Warn when a coupled infection expression names an infectious
compartment, since the flow is then multiplied by the pressure as well.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 25 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1aef1257-19ec-4d85-a3ff-f9b67c03bff2

📥 Commits

Reviewing files that changed from the base of the PR and between e947e4b and eee0749.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/patchsim/core/model.py
  • tests/test_model.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AdishAssain
AdishAssain merged commit 5fb2fc5 into main Sep 9, 2026
4 checks passed
@AdishAssain
AdishAssain deleted the fix/network-infection-rate-expression branch September 9, 2026 08:33
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