Skip to content

negative_insulin: add version compatible with Loop next-dev#79

Open
bjorkert wants to merge 3 commits into
mainfrom
nextdev_negative_insulin
Open

negative_insulin: add version compatible with Loop next-dev#79
bjorkert wants to merge 3 commits into
mainfrom
nextdev_negative_insulin

Conversation

@bjorkert

@bjorkert bjorkert commented Jul 14, 2026

Copy link
Copy Markdown
Member

The existing negative_insulin patches do not apply to the Loop next-dev branch, so the customization shows as incompatible.

On next-dev the glucose-prediction pipeline (including DoseMath and the insulin model) moved into the standalone LoopAlgorithm Swift package, which no longer depends on LoopKit. The original approach — a doseEnd parameter on DoseStore.getGlucoseEffects, the LoopKit insulin-model changes, LoopState.negativeInsulinDamper, etc. — no longer applies. nextdev_negative_insulin.patch keeps the same behavior with a smaller, retargeted change: the damper coefficient is computed in LoopDataManager and threaded into the algorithm as an optional AlgorithmInput.negativeInsulinDamper, with the damping applied inside LoopAlgorithm.generatePrediction.

The Negative Insulin Damper is an opt-in Algorithm Experiment, off by default. With it off the coefficient is nil and the algorithm behaves exactly as stock.

Test

Requires LoopWorkspace on the Loop next-dev branch. No lnl-scripts change is needed; only PATCH_BRANCH is overridden.

reset command

This command resets the branch to default state.

git submodule foreach 'git reset --hard; git clean -fd;'

apply

export PATCH_BRANCH="nextdev_negative_insulin"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/loopandlearn/lnl-scripts/main/CustomizationSelect.sh)" \
    negative_insulin
unset PATCH_BRANCH

@bjorkert
bjorkert requested a review from marionbarker July 14, 2026 17:39
@marionbarker

Copy link
Copy Markdown
Contributor

Updated code

The location in Loop/Loop.xcodeproj/project.pbxproj where Preferences.swift line is inserted for basal_lock and where NegativeInsulinDamperSelectionView.swift line is inserted for negative_insulin were too close together.

The lines in the negative_insulin/nextdev_negative_insulin.patch file were modified to shift the insertion of NegativeInsulinDamperSelectionView.swift a few lines earlier in the pxbproj file and reduce the number of comparison lines to avoid the location where basal_lock makes a change.

The basal_lock/nextdev_basal_lock.patch was similarly modified to reducs the number of comparison lines to avoid the location where negative_insulin makes a change.

Test

The application and removal of basal_lock and negative_insulin are now independent.

@marionbarker

Copy link
Copy Markdown
Contributor

Test Summary

✅ The negative_insulin damper customization behaves as expected.

For this example glucose pattern, the Loop algorithm (black curve) provides more IOB when recovering from a low than when Negative Insulin Damper is enabled (pink curve).

plot_overlay_nid

The experiment was run using the method described in the Negative Insulin Damper report:

@marionbarker marionbarker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by code review and test. Added a few tweaks to deconflict basal lock and negative insulin damper.

Request @bjorkert review this again.

@bjorkert

Copy link
Copy Markdown
Member Author

Approved, LGTM

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.

2 participants