Open menriquez-IDM opened 4 days ago
this seems like there’s a race condition happening during the setup - the parent Dists object isn’t initialized properly, possibly due to concurrency problems, however this is a very simple script (not intentionally using parallelization)
Branch and Disease module: Malnutrition.py init method
Found the issue -- two different distributions are being assigned the same trace
value, because the last 6 digits are the same:
s1 = 'people_states_malnutrition.height_percentile_default_module_micro_default'
s2 = 'people_states_malnutrition.height_percentile_default'
int.from_bytes(s1.encode(), byteorder='big')
Out [25]: 27799005104623711454959060709994609883093710570832320243914707190666620671010000743368678782368611280387512301456005666920680284384960831028951297485891059307079559274961398900
int.from_bytes(s2.encode(), byteorder='big')
Out [26]: 74300199819311061043722186592658515386210291499026427434428867777338769916261806379905559986374403707116839290598318545398900
Will update to using the hash method for making distribution strings.
Easy workaround seems to be to give the distributions names as follows:
ss.FloatArr('height_percentile', default=ss.uniform(name='height_percentile')), # Percentile, stays fixed
ss.FloatArr('weight_percentile', default=ss.uniform(name='weight_percentile')), # Percentile, increases when receiving micro, then declines?
ss.FloatArr('micro', default=ss.uniform(name='micro')), # Continuous? Normal distribution around zero. Z-score, sigmoid thing. Half-life.
Also noticing here that traces get a bit interesting due to distributions having a pointer to the parent module. Perhaps not wrong, but also could be more right?
Example:
'people_states_malnutrition.height_percentile_default' =
ss.uniform(people_states_malnutrition.height_percentile_default, pars={'low': 0.0, 'high': 1.0})
'people_states_malnutrition.height_percentile_default_module_weight_percentile_default' =
ss.uniform(<no trace>, pars={'low': 0.0, 'high': 1.0})
'people_states_malnutrition.height_percentile_default_module_micro_default' =
ss.uniform(<no trace>, pars={'low': 0.0, 'high': 1.0})
Distribution traces are weird! Running with TB and malnutrition, the traces appear as follows:
'pars_pregnancy_dur_postpartum' =
ss.lognorm_ex(pars_pregnancy_dur_postpartum, pars={'mean': ss.years(0.5, unit=year, values=26.07142857142857), 'std': ss.years(0.5, unit=year, values=26.07142857142857)})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_female_default' =
ss.bernoulli(pars_pregnancy_dur_postpartum_module_fecund_people_states_female_default, pars={'p': 0.5})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_age_default' =
ss.uniform(pars_pregnancy_dur_postpartum_module_fecund_people_states_age_default, pars={'low': 0, 'high': 100})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_SES_default' =
ss.bernoulli(pars_pregnancy_dur_postpartum_module_fecund_people_states_SES_default, pars={'p': 0.3})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default' =
ss.uniform(pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default, pars={'low': 0.0, 'high': 1.0})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_weight_percentile_default' =
ss.uniform(pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_weight_percentile_default, pars={'low': 0.0, 'high': 1.0})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_micro_default' =
ss.uniform(pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_micro_default, pars={'low': 0.0, 'high': 1.0})
'pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_dweight' =
ss.normal(pars_pregnancy_dur_postpartum_module_fecund_people_states_malnutrition.height_percentile_default_module_dweight, pars={'loc': <function Malnutrition.dweight_loc at 0x16b8685e0>, 'scale': <function Malnutrition.dweight_scale at 0x16b868670>})
For whatever reason, these traces do not result in repeated seed errors, whereas running as above with only TB does result in repeats.
Realizing now that the difference in paths is potentially a very serious issue for CRN. Each distribution has to get the exact same path in two comparison sims or distributions will get different seeds - so no CRN!
I think it's fine -- if two sims have different structures, then I think it makes sense for those sims to also have different random numbers. Of course, you can override the default trace by providing an explicit name to the distribution.
I have a nice fix for this, I think... coming soon.
(Context: I am porting tbsim to starsim 2.0 ).... in our Malnutrition Disease Module, as part of the constructor we are using distributions as default values, which used to work fine, but now are failing:
The error is as follows: