covasim icon indicating copy to clipboard operation
covasim copied to clipboard

Contact between identical agentid?

Open RobRomijnders opened this issue 1 year ago • 2 comments

Hey covasim team, thanks again for opensourcing this simulator. I'm asking this question on the public github so other people get to benefit as well from your answers. Best regards, Rob

Describe the bug

Some layers seem to define contacts between two identical agents. For example, contacts[layer]['p1'][i] == contacts[layer]['p2'][i] for some i. Is this expected or is this a bug?

To reproduce

  1. Run a simulation like in the tutorial5.ipynb
  2. Use as subtarget function for test_num the following:
  def subtarget_func(sim):
    contacts = sim.people.contacts

    for layerkey in contacts.keys():
      num_selfcontact = np.sum(
        contacts[layerkey]['p1'] == contacts[layerkey]['p2'])
      if num_selfcontact > 0:
        print(f"Found {num_selfcontact} contacts in layer {layerkey}")

    # Baseline intervention
    vals = np.ones(len(sim.people))  # Create the array
    vals[cv.true(sim.people.exposed)] = 100  # Probability for testing
    output = dict(inds=sim.people.uid, vals=vals)
    return output

Expected behavior

I would expect that a simulator wouldn't simulate a contact between the identical agent, unless this contact has a special meaning?

Screenshots or outputs

The above subtarget function will print an output like the following. The num_selfcontact differs randomly between runs, but is usually around 5 to 50.

All layers: ['h', 's', 'w', 'c']
Found 8 contacts in layer s
Found 13 contacts in layer w
Found 7 contacts in layer c

Platform (please complete the following information):

  • Covasim version: 3.1.4
  • Python 3.9 on Ubuntu 22

RobRomijnders avatar Jun 27 '23 13:06 RobRomijnders

Hi @RobRomijnders -- well spotted, you're right! In Covasim's default "hybrid" network, we don't bother to remove self-connections, because they have (virtually) no effect on the network, and are computationally costly to find and remove. However, other network options -- such as SynthPops -- do have self-connections removed. We'll add this to the FAQ, because you probably aren't the only person who was confused by this.

cliffckerr avatar Jun 28 '23 02:06 cliffckerr

Ok, good to know. Thanks!

RobRomijnders avatar Jun 28 '23 07:06 RobRomijnders