Skip to content

Comments

Refactor s2c::get_class_with_defaults#36

Merged
kfrey-idm merged 11 commits intoEMOD-Hub:mainfrom
kfrey-idm:kfrey_s2c_bug_v2
Nov 12, 2025
Merged

Refactor s2c::get_class_with_defaults#36
kfrey-idm merged 11 commits intoEMOD-Hub:mainfrom
kfrey-idm:kfrey_s2c_bug_v2

Conversation

@kfrey-idm
Copy link
Member

@kfrey-idm kfrey-idm commented Oct 30, 2025

Reorganizes the get_class_with_defaults to make it somewhat more logical. The function still needs a lot of work in future PRs, but these changes should resolve the bug where default containers aren't unique.

Also enables helpful simplifications planned in EMOD:

  • idmType:IReport should be idmAbstractType
  • idmType:WaningEffect should be idmAbstractType

Adds additional exceptions and removes some special case handling. Open PRs in emodpy and emodpy-hiv should be merged first. They do not depend on these changes, but will ensure these changes don't break anything:

No issues (apparently) with emodpy-workflow.

@kfrey-idm kfrey-idm self-assigned this Oct 30, 2025
@kfrey-idm kfrey-idm added the help wanted Extra attention is needed label Oct 30, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors the get_class_with_defaults function to improve organization and fix a bug where default containers weren't unique. The changes consolidate the complex conditional logic into a more systematic approach and ensure that default collections are properly isolated between instances.

  • Reorganized the conditional logic in get_class_with_defaults into a more structured if-elif chain
  • Added a new eval_default helper function to ensure container defaults return new instances rather than shared references
  • Removed the show_warnings parameter and some special case handling

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
emod_api/schema_to_class.py Major refactoring of get_class_with_defaults function with improved logic organization and bug fixes
tests/test_schema.py New comprehensive test suite for schema validation and unique container defaults
tests/test_config.py Updated test to use correct EventCoordinator class name

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +373 to +374
if ('NodeListConfig' in classname): # KF: Need to remove NodeListConfig
schema_blob = dict()
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

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

This is a hardcoded workaround for a specific class. The comment indicates this should be removed, suggesting this is technical debt that should be addressed.

Suggested change
if ('NodeListConfig' in classname): # KF: Need to remove NodeListConfig
schema_blob = dict()
# Removed hardcoded workaround for NodeListConfig

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

🥲

@kfrey-idm kfrey-idm removed the help wanted Extra attention is needed label Nov 7, 2025
Copy link
Collaborator

@Bridenbecker Bridenbecker left a comment

Choose a reason for hiding this comment

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

I ran out of time to really review this before I go to ASTMH. comments

  • AdditionalRestrictions should be abstract. not sure why it is not
  • code starting at 297 looks like it repeats over and over for with mostly the abstract key being different. Seems like that code could be put in a function. I wish there was a way to put the elif check too since it is repeated numerous times.

Sorry not much more

abstract_key4 = "idmAbstractType:NodeSet"
abstract_key5a = "idmAbstractType:WaningEffect"
abstract_key5b = "idmType:WaningEffect"
abstract_key6 = "idmAbstractType:Intervention"
Copy link
Collaborator

Choose a reason for hiding this comment

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

These variable names make the code hard to read. I forget what key4 is. I'm assuming that you are doing this instead of having the string repeated everywhere. I'd make them constants (i.e. move to module level, make all caps, have better names, etc. If you are trying to have short names, I would do something like "KEY_AR" or "KEY_REPORT". I'd also recommend an indicator in the name like KEY_REPORT_OLD or KEY_REPORT_MH where comment says MH is malaria-hiv

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added additional comments so scrolling back and forth isn't needed. Once all the AbstractTypes are correctly labeled in EMOD, most of the if-else chain can go away.

@kfrey-idm
Copy link
Member Author

I ran out of time to really review this before I go to ASTMH. comments

  • AdditionalRestrictions should be abstract. not sure why it is not
  • code starting at 297 looks like it repeats over and over for with mostly the abstract key being different. Seems like that code could be put in a function. I wish there was a way to put the elif check too since it is repeated numerous times.

Sorry not much more

Thank you! I didn't realize AdditionalRestrictions was abstract. I've changed a few comments to emphasize that it should be abstract.

These changes are setting up future changes. Once IReport, WaningEffect, and AdditionalRestrictions are changed to idmAbstractType in EMOD, this function can be simplified a lot.

For now, there's a lot of if-else to accommodate doing it both ways. That should go away soon, but not in this PR.

@kfrey-idm kfrey-idm merged commit 40b695b into EMOD-Hub:main Nov 12, 2025
5 checks passed
@kfrey-idm kfrey-idm deleted the kfrey_s2c_bug_v2 branch November 12, 2025 19:09
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