EMOD-Hub / EMOD

Source files for building the IDM EMOD disease transmission model.
MIT License
94 stars 41 forks source link

Enable_Vector_Migration being not on the same chunk as Vector_Migration_parameters causes error in emod_api #31

Closed stitova-idm closed 1 month ago

stitova-idm commented 3 months ago

emod_api.schema_to_class tries to find the "depends-on" paramater in the same chunk of schema wher the parameter with the depends-on is located, but VectorMigration parameters are now inside Vector_Species_Parameters while Enable_Vector_Migration is in the main parameters: chunk.

error: Creating EMODTask (from files)... Traceback (most recent call last): File "C:\GitHub\emodpy-malaria\examples\vector_migration_example\example.py", line 282, in general_sim() File "C:\GitHub\emodpy-malaria\examples\vector_migration_example\example.py", line 219, in general_sim task = EMODTask.from_default2( File "C:\GitHub\emodpy-malaria\venv_malaria\lib\site-packages\emodpy\emod_task.py", line 283, in from_default2 task.config = dfs.get_config_from_default_and_params(config=default_config, set_fn=param_custom_cb) File "C:\GitHub\emodpy-malaria\venv_malaria\lib\site-packages\emod_api\config\default_from_schema_no_validation.py", line 154, in get_config_from_default_and_params config = set_fn(config) File "C:\GitHub\emodpy-malaria\examples\vector_migration_example\example.py", line 62, in set_param_fn vector_config.add_vector_migration(config, species="gambiae", File "C:\GitHub\emodpy-malaria\venv_malaria\lib\site-packages\emodpy_malaria\vector_config.py", line 868, in add_vector_migration species_params.Vector_Migration_Filename = vector_migration_filename File "C:\GitHub\emodpy-malaria\venv_malaria\lib\site-packages\emod_api\schema_to_class.py", line 81, in setattr if self["schema"][k]['default'] == self[k]: File "C:\GitHub\emodpy-malaria\venv_malaria\lib\site-packages\emod_api\schema_to_class.py", line 19, in missing raise KeyError(f"'{key}' not found in this object. List of keys = {self.keys()}.") KeyError: "'Enable_Vector_Migration' not found in this object. List of keys = odict_keys(['Acquire_Modifier', 'Adult_Life_Expectancy', 'Anthropophily', 'Aquatic_Arrhenius_1', 'Aquatic_Arrhenius_2', 'Aquatic_Mortality_Rate', 'Cycle_Arrhenius_1', 'Cycle_Arrhenius_2', 'Cycle_Arrhenius_Reduction_Factor', 'Days_Between_Feeds', 'Drivers', 'Egg_Batch_Size', 'Gene_To_Trait_Modifiers', 'Genes', 'Habitats', 'Immature_Duration', 'Indoor_Feeding_Fraction', 'Infected_Arrhenius_1', 'Infected_Arrhenius_2', 'Infected_Egg_Batch_Factor', 'Infectious_Human_Feed_Mortality_Factor', 'Male_Life_Expectancy', 'Microsporidia', 'Name', 'Temperature_Dependent_Feeding_Cycle', 'Transmission_Rate', 'Vector_Migration_Filename', 'Vector_Migration_Food_Modifier', 'Vector_Migration_Habitat_Modifier', 'Vector_Migration_Modifier_Equation', 'Vector_Migration_Stay_Put_Modifier', 'Vector_Sugar_Feeding_Frequency', 'x_Vector_Migration'])."

Proposed solution: I think since vector migration is per-species and each species keeps track of it's own "vectormigrationenabled" parameter (m_IsEnabled) I believe, we could just use "is Vector_Migration_Filename set to readable file" as a flag for "does this species migrate" and if the Filename paramater is defined (and not just present), we can set internal flag of "m_IsEnabled" and require the MigrationModifierEquation parameters. If the species doesn't have Vector_Migration_Filename defined, we just not have migration turned on for tht species.

Bridenbecker commented 3 months ago

Whether or not the file is defined is probably fine. I don't think our depends-on feature handles this so it will make it harder to write code that uses the schema to know what parameters depend-on the filename not being empty.

stitova-idm commented 1 month ago

got rid of this by getting rid of "Enable_Vector_Migration" parameter, now, to have migration, you need to define the "Vector_Migration_Filename" or to not have migration - leave it as an emtpy string.