InstituteforDiseaseModeling / covasim

COVID-19 Agent-based Simulator (Covasim): a model for exploring coronavirus dynamics and interventions
https://covasim.org
MIT License
255 stars 224 forks source link

Add Aggregate Results to base.py #333

Closed edwardtang12 closed 3 years ago

edwardtang12 commented 3 years ago

Please note: this PR is part of a school project.

Why?

We observe that in the Sim class, we have a number of functions to initialize fields—examples include init_results, init_people, init_interventions, init_analyzers, init_variants and init_immunity. These functions utilize modules outside of the Sim class, which are imported and called with the result of initializing fields of the current simulation. For example, to create the interventions field in init_interventions, functions of the interventions.py module are called.

Unlike the other init functions, we notice that init_results directly initializes the results field of the Sim class, without utilizing an external module for generating the results (like how interventions.py was responsible for generating interventions). We also notice, however, that init_results utilizes an external module for a single result in the init_res function, referencing the Result class of base.py. This is an area where the aggregate domain pattern can be applied, with a Results aggregate to coincide with the Result class.

Description of Changes

The class Results thus resides in base.py alongside the Result class. This includes the initialization of results, creating the aggregate root results utilizing the aforementioned init_res function. As an aggregate, Results has multiple Result instances, but these Result instances’ lifecycles are not tied to that of Results. The init_results method is now simplified to accessing the simulation results through the root of the Results aggregate.

cliffckerr commented 3 years ago

Thanks for the PR -- we're not considering major architectural changes currently, but we appreciate the contribution to open-source software!