Enable switching service availability in healthsystem module#1802
Enable switching service availability in healthsystem module#1802sangeetabhatia03 wants to merge 18 commits intomasterfrom
Conversation
| @@ -0,0 +1,45 @@ | |||
| """The file contains all the definitions of scenarios for the TLO-LCOA project.""" | |||
There was a problem hiding this comment.
just a quick look at this -- why not put this into your main scenario file?
There was a problem hiding this comment.
Nice logic and nice test.
Personal taste but I would suggest simplifying the scenario file so that we have everything in one file. (The style of having it split across multiple files is useful when we have lots of scenario file drawing from the same 'base', but it feel a bit confusing here).
| if (self.sim.date.year == self.parameters['year_service_availability_switch'] - 1): | ||
| self._compute_factors_for_effective_capabilities() |
There was a problem hiding this comment.
This is fine. but its different to the pattern we have for other changes - which is to schedule an event to occur on the date we we want the switch to happen, and then let the event do this work. Don't feel strongly about this!
src/tlo/methods/healthsystem.py
Outdated
| # Don't increment the counter; log and return. | ||
| if not self.is_treatment_id_allowed(hsi_event.TREATMENT_ID, self.service_availability): | ||
| self.call_and_record_never_ran_hsi_event(hsi_event=hsi_event, priority=priority, clinic=clinic) | ||
| return |
There was a problem hiding this comment.
we don't need this 'return'
| def _compute_factors_for_effective_capabilities(self): | ||
| """Compute factor to rescale capabilities to capture effective capability. | ||
| Computation of these factors is split from the actual rescaling to facilitate | ||
| capturing them even when running the model in mode 1.""" | ||
| self._rescaling_factors = defaultdict(dict) | ||
| for clinic, clinic_cl in self._daily_capabilities.items(): | ||
| for facID_and_officer in clinic_cl.keys(): | ||
| self._rescaling_factors[clinic][facID_and_officer] = self._summary_counter.frac_time_used_by_facID_and_officer( | ||
| facID_and_officer=facID_and_officer, clinic=clinic | ||
| ) | ||
| self._summary_counter._rescaling_factors = self._rescaling_factors | ||
|
|
There was a problem hiding this comment.
is this intended to be on this PR?
There was a problem hiding this comment.
yes, so that we can log rescaling factors.
marghe-molaro
left a comment
There was a problem hiding this comment.
Hi @sangeetabhatia03, this is looking great, I've just added a few comments!
Summary:
- I agree with Tim about having a single scenario file
- I've suggested tightening the test just a little bit, it shouldn't take too long!
src/tlo/methods/healthsystem.py
Outdated
| # First check that the service the HSI needs is available. If not, don't add to queue. | ||
| # Don't increment the counter; log and return. | ||
| if not self.is_treatment_id_allowed(hsi_event.TREATMENT_ID, self.service_availability): | ||
| self.call_and_record_never_ran_hsi_event(hsi_event=hsi_event, priority=priority, clinic=clinic) |
There was a problem hiding this comment.
To be consistent with how HSIs are removed from the queue when the HSI is no longer available in the health system, I think here too never_ran should be scheduled for topen
| super().__init__() | ||
| self.seed = 0 | ||
| self.start_date = Date(2010, 1, 1) | ||
| self.end_date = Date(2040, 1, 1) |
There was a problem hiding this comment.
I think to have full 15 years from the 1st of Jan 2026 you want to end this on the 1st of Jan 2041
| self.seed = 0 | ||
| self.start_date = Date(2010, 1, 1) | ||
| self.end_date = Date(2040, 1, 1) | ||
| self.pop_size = 100 |
There was a problem hiding this comment.
Assuming this is a relic from local tests, but just to remind ourselves I think we said we were going to go up to 250k?
| 'yearly_HR_scaling_mode': 'historical_scaling', | ||
| }, | ||
|
|
||
| "ImprovedHealthSystemAndCareSeekingScenarioSwitcher": { |
There was a problem hiding this comment.
Just checking - did you check that these are compatible with the suspend/resume on Azure?
There was a problem hiding this comment.
As discussed with @marghe-molaro parking this check for now because switching to max_healthsystem_function and max_healthcare_seeking is the same across all draws for our current analysis.
| 'year_of_switch': self.YEAR_OF_SERVICE_AVAILABILITY_SWITCH, | ||
| }, | ||
|
|
||
| "ImprovedHealthSystemAndCareSeekingScenarioSwitcher": { |
There was a problem hiding this comment.
As above, would be good to double check that this is compatible
| scenario_definitions.baseline(), | ||
| { | ||
| 'HealthSystem': { | ||
| 'service_availability_postSwitch': list(self._scenarios.values())[draw_number], |
There was a problem hiding this comment.
I guess you've tested locally that the conversion into a list here makes the different service_availability configurations accessible via draw_number? Just struggling to wrap my head around it without running it
| level="0", | ||
| treatment_id="ThisEventShouldNotRunPostSwitch", | ||
| ) | ||
| ## These events open after service availability switch |
There was a problem hiding this comment.
To tighten this test a little bit, it would be good to schedule say 60% of these treatment_IDs before the switch, and 40% after. You then want to double check that 60% did go ahead (and all with dates < switch), and that 40% were never ran.
The "risk" of treatment_IDs "slipping" into the post-switch period and affecting the health outcome is I think higher than treatment_IDs being scheduled in that period at all!
…odel into sb/lcoa-inputs-from-tlo
This pull request enables switching of service availability in the healthsystem module. Key changes include the addition of new parameters for service availability switching.
I have also created a scenario file for our initial analysis; would be great to get your feedback on this.