Skip to content

Object derived from People is not being propely initialized. #921

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

Open
menriquez-IDM opened this issue Apr 22, 2025 · 0 comments
Open

Object derived from People is not being propely initialized. #921

menriquez-IDM opened this issue Apr 22, 2025 · 0 comments

Comments

@menriquez-IDM
Copy link
Contributor

Issue:

loop.collect_abs_tvecs() function shouldn't be mixing hardcoded strings with dynamic class name strings!

PROPOSED FIX BY Romesh:

I would guess this is because in loop.py it has around line 136

        sim = self.sim
        for key in ['sim', 'people']:
            self.abs_tvecs[key] = sim.t.tvec

which assigns based on string 'people' but the functions are being registered under the actual class name, which is 'cattle'. You could maybe try replacing that snippet above with

sim = self.sim
self.abs_tvecs['sim'] = sim.t.tvec
self.abs_tvecs[sim.people.__class__.__name__.lower()] = sim.t.tvec

Context

I found this issue when trying to create a Cattle object derived from People:

odict key "cattle" not found; available keys are:
sim
people
deaths
births
cattlenetwork
rvf
routineelisatest
elisatest
KeyError: 'cattle'

During handling of the above exception, another exception occurred:

  File "/Users/mine/git/starsim/starsim/loop.py", line 152, in make_plan
    for t in self.abs_tvecs[func_row['module']]:
             ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/Users/mine/git/starsim/starsim/loop.py", line 36, in init
    self.make_plan()
  File "/Users/mine/git/starsim/starsim/sim.py", line 150, in init
    self.loop.init() # Initialize the integration loop
    ^^^^^^^^^^^^^^^^
  File "/Users/mine/git/rvf/scripts/run_simulation.py", line 70, in <module>
    base_sim.init()
sciris.sc_utils.KeyNotFoundError: odict key "cattle" not found; available keys are:
sim
people
deaths
births
cattlenetwork
rvf
routineelisatest
elisatest

It fails during the simulation initialization (triggered automatically by sim.run() ), specifically it fails during the loop.make_plan() function, as it seems like whatever action that ensures that certain modules are part of the odict from which this for loop is reading the keys, doesn't contain cattle (the special version of people).
Any ideas what could be missing - at first glance it seems like I am either missing a function to ben added to the cattle object or is just purely not supported by the latest starsim.
(As context: a monolithic version of this project built with starsim 0.4.0 was handling it just fine).


menriquez-IDM added a commit that referenced this issue Apr 22, 2025
Bug fix: #921 Object derived from People is not being propely initialized.
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

No branches or pull requests

1 participant