Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic bolus dosing #1219

Closed
wants to merge 48 commits into from
Closed

Automatic bolus dosing #1219

wants to merge 48 commits into from

Conversation

ps2
Copy link
Collaborator

@ps2 ps2 commented Dec 29, 2019

An implementation of using boluses for dosing. Independent of #1205.

This feature is enabled by a new switch in settings that allows the user to select between the existing temp basal strategy and this new bolus strategy.

Boluses are issued for high corrections, when Loop thinks additional insulin is required beyond your basal needs. During each loop, up to 40% of the required insulin will be dosed via bolus. When insulin requirements are below basal, Loop will use temp basals, as before. High temps are no longer used, except to maintain scaled basal when a high override is in effect.

Automatic bolus sizes are limited to not exceed 40% of your max bolus setting.

@francescaneri
Copy link

francescaneri commented Dec 30, 2019

awesome wauu!

Immagine del 30-12-19 alle 15 32

@erikdi
Copy link
Contributor

erikdi commented Dec 31, 2019

Can we revisit the discussion from #707 around implementing a maximum Insulin-On-Board limit now?

Having run more or less the same automatic bolus code for 2 years I still believe it is a necessary safe guard.
 
IIUC this implementation correctly it will issue an automatic bolus on every run of the loop, so every 5 minutes with a Dexcom cgm.

Given that most people run this unattended the 40% of max bolus per Loop will not limit the amount of insulin delivered in any meaningful way in practice and makes the use of it unsafe.

Let's say you have a max-bolus set to 5. It would deliver 2 units in each iteration, ie. 4U after 5 minutes, 6U after 10 minutes, or 10U in 20 minutes when you realistically start to feel the effects of the wrong dosing. At that point it requires quite a bit of fast carbs to get out of it.

Because the carb amounts are not limited either, it is pretty easy to get into this state by entering the wrong carb amount (let's say an inexperienced caregiver mixes up total weight of food and carbs).

@ps2
Copy link
Collaborator Author

ps2 commented Dec 31, 2019

@erikdi Yes, I do think a max iob guard might be necessary here. Not as a therapy setting that people use to often limit dosing, but as a protection for the kinds of scenarios you describe.

@live4sw
Copy link

live4sw commented Dec 31, 2019

I agree it makes sense as a safety feature. Very similar issue as with OpenAPS with SMB enabled (OA has a max iob setting, though it is user configurable). Of course this also gets tricky with mealtimes, particularly for those with high carb diets.

@dyjaks
Copy link

dyjaks commented Dec 31, 2019

Since there are two approaches for this, is the intent that they go head to head and validate outcomes or will the two at some point merge?

@alevar1975
Copy link

Definitely merge👍💕

@dyjaks
Copy link

dyjaks commented Dec 31, 2019

@alevar1975 The question would be how. If branch A does X and branch B does Y the union of the branches A&B doesn't mean the union of results X&Y. It in fact makes a whole new thing.

@dyjaks
Copy link

dyjaks commented Jan 1, 2020

@ps2 Potential safety issue, would like your thoughts on. I just started a new G6 sensors so have no readings. I put in a manual BG entry at 9:12 PST. I have gotten three automatic boluses in that time at:

9:13 for .3U (good)
9:18 for .2U (probably fine)
9:23 for .1U (maybe not fine)

After the last .1U the manual input was out dated and loop doesn't count it. But per entry being able to get 3 decisions seems like a lot because automatic boluses can stack really fast should we be more demanding of recent readings? Loop making decisions 10 minutes out from last reading after already giving two boluses might cause issue.

And happy new year!

EDIT - I have a report if it at all matters but it'll be cluttered with setup since I also just switched from mdt to pod.

@ps2
Copy link
Collaborator Author

ps2 commented Jan 1, 2020

That is expected behavior at this time. Loop will continue to dose as long as BG is < 15m old. It's similar in behavior to how it works with Temp Basals, too. This is actually more conservative than a temp basal would end up delivering. A temp basal over 30m is 100% of Loop's calculated dose. In your case, assuming Loop called for .75 U (based on your initial 0.3 dose being 40% of total), using temp basals Loop would deliver 0.75 U. Using boluses with partial application, you got 0.5 U delivered, or 67% of the total dose.

@dyjaks
Copy link

dyjaks commented Jan 1, 2020

I thought so but always want to make sure. It was for .85 and I got .6 so that'd be 70%.

I don't know if I'd say it's the same though. 70% in 10 minutes where as the tmp basal would be only at 33% in the same time frame. Given enough time they even out.

@dyjaks
Copy link

dyjaks commented Jan 8, 2020

An update now that I've been running this almost a week. No real bad episodes, or any episodes really, have happened since that first initial scare. Seems to handle long meals better (great for low carb). I think pods like it a lot better than temp basals.

@jbwittmer
Copy link

We are likewise quite pleased after a week. I'd be curious to test with slightly more aggressive application of the calculated need. Am I reading the code correctly that by changing "bolusPartialApplicationFactor = 0.4 // %" to 0.5 it would apply half of the calculated corrective bolus each dosing interval rather than 40%? Nothing else would need to be changed?

@ps2
Copy link
Collaborator Author

ps2 commented Jan 8, 2020

@jbwittmer, that’s all you need to change. But remember that you need to leave room for loop to react to bg going lower than expected, like overestimating carbs, exercise, etc. 40% is already a huge jump from Loop’s previous effective partial application factor of 17%.

@francesc0-cgm
Copy link

francesc0-cgm commented Jan 8, 2020 via email

@loyalchallenger
Copy link

Just to verify again, this feature will be able to be turned off/on once implemented? I have not needed a correction bolus in a very long time and sometimes my cgm predicts that I will be much higher than I ever actually get. But I’m on such low doses and low carb, that I don’t need correction boluses.

@ps2
Copy link
Collaborator Author

ps2 commented Jan 8, 2020

@francesc0-cgm I think it's best to look at increasing partial application not as increasing Loop's "aggressiveness", but rather increasing Loop's confidence in dosing. The top variables you should play with if Loop is being too aggressive (i.e. calling for too much insulin) are ISF, basal, and target range. So I would recommend you try adjusting those first. Of course all the variables play out together in treatment, and cannot be entirely separated, so moving to a bolus dosing strategy might mean that what was once an effective ISF value under temp basal strategy might be different now.

@tkk41
Copy link

tkk41 commented Jan 8, 2020

I've been running automatic-bolus since a few days, looks good to me, no issues so far. I'll carefully run this dosing strategy and in case any issues were coming up, I'll post here.

@ps2
Copy link
Collaborator Author

ps2 commented Jan 8, 2020

At some point the various parts of the Loop forecast will likely have confidence terms associated with them, which will give us a better way to adjust partial application automatically.

For now, tuning Loop is already fairly complicated, and reducing the number of free variables helps most people find their best settings quicker. Adjusting the partial application factor may make sense to vary based on the hour to hour variance of your individual response to insulin, but it is not a good way to adjust the average amount of insulin you need for a given situation.

If you're someone with very reliable response to insulin, carbs, etc, then maybe you could consider bumping up PA factor. If you're someone with a very unreliable response to those things (caution! bad settings can look like this, but is a different situation), then maybe 40% is too high.

@macbenoit
Copy link

Hello
Is there a possibility to implement autobolus with spike ?

1 similar comment
@macbenoit
Copy link

Hello
Is there a possibility to implement autobolus with spike ?

@Nightfoxy
Copy link

Nightfoxy commented Aug 13, 2020 via email

@andrew-dixon
Copy link

@ps2 How does an override affect autobolus, specifically if the override is turned on after carbs are entered. For example, if I enter 50g carbs with 4 hour absorption time and then after 1-hour turn on an override to increase by 20% for 1 hour are the auto boluses given during that 1 hour to cover the carbs increased by 20%? If so, what then happens in hours 3 and 4 as it will see IOB higher than it would have seen without the increase. Hope that makes sense, thanks.

@PieterGit
Copy link

Pete, can you explain what need's to be done/tested/fixed before this branch can be merged to dev?

@ps2
Copy link
Collaborator Author

ps2 commented Dec 28, 2020

@PieterGit A few things:

  1. The changes here need to be merged with all the changes that happened on dev recently, mainly the Tidepool merges.
  2. There are some model changes needed to track whether a bolus was delivered automatically or manually.
  3. The model changes are slated to be done after the Dose logging changes are landed, as those involve model changes as well, and dealing with conflicts in model changes is messy.

@PieterGit
Copy link

Sinc I overlooked the Zulip message of @ps2, I'll repeat it for others that are mainly reading Github and not the Zulip channel:

Automatic Bolus dosing strategy is now an option in dev, alongside the traditional temp basal strategy (which is still default). Appreciate any testing. Please remember this is a fairly unstable branch, and you should probably only be using it on test/development setups. Any issues, please report here on zulip or file github issues.

Source: https://loop.zulipchat.com/#narrow/stream/144182-development/topic/Automatic.20Bolus.20on.20dev

So I assume the automatic-bolus branch from this PR is now obsolete and you should test dev branch for testing Automatic bolus dosing.

@ps2: perhaps you can close these branches/PR's to be clear about the state of these branches/PR's?

I will do some testing and report with Github issues or in Zulip chat.

@ps2
Copy link
Collaborator Author

ps2 commented Feb 2, 2021

The automatic-bolus branch this PR is tracking has de-facto become the main branch for anyone wanting to actually run automatic-bolus in Loop despite being what I would call an "experimental branch". It is still an experimental branch, but it's fairly stable, and is very in sync with the current Loop release, 2.2.4. The dev branch is still unstable so this branch will stay until there is an actual new release. The two other dev branches, track-automatic-bolus and automatic-bolus-merge will be deleted soon.

@juan-restrepo
Copy link

Are there plans to sync this branch with 2.2.5 or 2.2.6?

@juan-restrepo
Copy link

Thanks @jonfawcett. I'll check that out next time if my wife or kid are very adamant about having the latest version + autobolus (although my kid is <3, so I guess he won't have an opinion for a few years).

@andrew-dixon
Copy link

@juan-restrepo @jonfawcett Not sure if this is the same thing, but Automatic Bolus was added to master in release 2.2.5 - https://github.com/LoopKit/Loop/releases/tag/v2.2.5

@jonfawcett
Copy link

@juan-restrepo @jonfawcett Not sure if this is the same thing, but Automatic Bolus was added to master in release 2.2.5 - https://github.com/LoopKit/Loop/releases/tag/v2.2.5

My mistake. I have been getting so many tags about my dose strategy switcher that I mistakenly thought this was another one.

@marionbarker
Copy link
Contributor

I believe this PR should be closed as overtaken by events. This dosing strategy was added to master with release Loop v2.2.5.

@juan-restrepo
Copy link

I ended up having some issues and upon converging to master 2.2.6 I had the great surprise of having autobolus there. Thanks!

@ps2 ps2 closed this Mar 11, 2022
@ps2 ps2 deleted the automatic-bolus branch June 8, 2022 19:08
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.