HopkinsIDD / flepiMoP

The Flexible Epidemic Modeling Pipeline
https://flepimop.org
GNU General Public License v3.0
9 stars 4 forks source link

[Bug]: Using disease state names 'I1' and 'I2' only works when `proportional_to` are equal to "source" #298

Closed twallema closed 3 months ago

twallema commented 3 months ago

Label

bug, gempyor

Priority Label

medium priority

Describe the bug/issue

Trying to run a chain trick on the I compartment in an SIR model, so S --> I1, I1 --> I2, I2 --> R. Gempyor doesn't like me using the names I1 and I2, it returns the following error,

"""
Traceback (most recent call last):
  File "/opt/miniconda3/envs/flepimop-env/lib/python3.12/concurrent/futures/process.py", line 263, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda3/envs/flepimop-env/lib/python3.12/concurrent/futures/process.py", line 212, in _process_chunk
    return [fn(*args) for args in chunk]
            ^^^^^^^^^
  File "/Users/twallema/Documents/academic/github/flepimop_parent/flepiMoP/flepimop/gempyor_pkg/src/gempyor/seir.py", line 275, in onerun_SEIR
    ) = modinf.compartments.get_transition_array()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/twallema/Documents/academic/github/flepimop_parent/flepiMoP/flepimop/gempyor_pkg/src/gempyor/compartments.py", line 493, in get_transition_array
    raise ValueError(f"Could not find proportional_to {elem3} in compartments")
ValueError: Could not find proportional_to I in compartments
"""

Changing "I1" --> "I" and "I2" --> "A" doesn't result in this error, so it's likely due to both compartment names starting with "I"? (Ione/Itwo or 1I/2I also return a similar error)

To Reproduce

Run a config with the following seir setup (IC & subpop shouldn't matter).

compartments:
  infection_stage: ["S", "I1", "I2", "R"]

seir:
  integration:
    method: rk4
    dt: 1.0
  parameters:
    beta:
      value: 0.6
    alpha:
      value: 0.5
    gamma:
      value: 0.2

  transitions:
    - source: ["S"]
      destination: ["I1"]
      rate: ["beta"]
      proportional_to: ["S", ["I1","I2"]]
      proportion_exponent: ["1", "1"]
    - source: ["I1"]
      destination: ["I2"]
      rate: ["alpha"]
      proportional_to: ["I1"]
      proportion_exponent: ["1"]
    - source: ["I2"]
      destination: ["R"]
      rate: ["gamma"]
      proportional_to: ["I2"]
      proportion_exponent: ["1"]

Environment, if relevant

Mac OS, FLEPIMOP-ENV, verified flepiMoP Git checked out to current main branch.

twallema commented 3 months ago

Or "1I" and "2I".. what's going on. Changing I1 --> I, I2 --> A works. Seems like a disease state can only have length of one?

saraloo commented 3 months ago

I think this might be something wrong with your config or input files. There shouldn't be anything wrong with these names, as we use I1, I2 and I3 in covid... I can't see anything wrong on first glance though. You could try replace the proportional_to parts of your second and third transitions to "source" and see if that makes a difference

On Fri, 16 Aug 2024, 10:32 am Tijs Alleman, @.***> wrote:

Or "1I" and "2I".. what's going on.

— Reply to this email directly, view it on GitHub https://github.com/HopkinsIDD/flepiMoP/issues/298#issuecomment-2293724676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZGJPSXG2XW5YJBMJ5URN3ZRYLSPAVCNFSM6AAAAABMUHL5A6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTG4ZDINRXGY . You are receiving this because you were mentioned.Message ID: @.***>

twallema commented 3 months ago

Changing the names to "source" resolves the issue, I do believe this is worth fixing as such intricacies have the potential to scare away novel users. Retrospectively changing the issue name at this point.

name: SI2RD
setup_name: USA
start_date: 2023-09-01
end_date: 2024-07-01
nslots: 1

subpop_setup:
  geodata: model_input/data/geodata_2019_statelevel.csv
  mobility: model_input/data/mobility_2011-2015_statelevel.csv

initial_conditions:
  method: plugin
  plugin_file_path: model_input/initial_conditions_SI2RD.py

compartments:
  infection_stage: ["S", "I1", "I2", "R"]

seir:
  integration:
    method: rk4
    dt: 1.0
  parameters:
    beta:
      value: 0.6
    alpha:
      value: 0.5
    gamma:
      value: 0.2

  transitions:
    - source: ["S"]
      destination: ["I1"]
      rate: ["beta"]
      proportional_to: ["source", ["I1","I2"]]
      proportion_exponent: ["1", "1"]
    - source: ["I1"]
      destination: ["I2"]
      rate: ["alpha"]
      proportional_to: ["source"]
      proportion_exponent: ["1"]
    - source: ["I2"]
      destination: ["R"]
      rate: ["gamma"]
      proportional_to: ["source"]
      proportion_exponent: ["1"]
twallema commented 3 months ago

Moving this discussion to #301 and closing this as active.