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

remove side effects from methods #318

Open
arik-shurygin opened this issue Jan 10, 2025 · 0 comments
Open

remove side effects from methods #318

arik-shurygin opened this issue Jan 10, 2025 · 0 comments
Labels
enterprise_practices Governance housekeeping trying to keep projects usable and secure.

Comments

@arik-shurygin
Copy link
Collaborator

arik-shurygin commented Jan 10, 2025

this is part of a broader push to make methods more functionally pure. There are pieces of code like:

def load_cross_immunity_matrix(self) -> None:
"""
Loads the Crossimmunity matrix given the strain interactions matrix.
Strain interactions matrix is a matrix of shape (num_strains, num_strains) representing the relative immune escape risk
of those who are being challenged by a strain in dim 0 but have recovered from a strain in dim 1.
Neither the strain interactions matrix nor the crossimmunity matrix take into account waning.
Updates
----------
self.config.CROSSIMMUNITY_MATRIX:
updates this matrix to shape (self.config.NUM_STRAINS, self.config.NUM_PREV_INF_HIST) containing the relative immune escape
values for each challenging strain compared to each prior immune history in the model.
"""
self.config.CROSSIMMUNITY_MATRIX = (
utils.strain_interaction_to_cross_immunity(
self.config.NUM_STRAINS, self.config.STRAIN_INTERACTIONS
)
)

within the AbstractParameters class which update self but do not return anything. I think it would be more explicit and better practice to have these types of functions return the parameter in question. Should also be on the look out for any functions which silently change anything about self, these "unpure" functions are likely to create bugs in the future and are bad practice.

@arik-shurygin arik-shurygin added the enterprise_practices Governance housekeeping trying to keep projects usable and secure. label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enterprise_practices Governance housekeeping trying to keep projects usable and secure.
Projects
None yet
Development

No branches or pull requests

1 participant