Thanks again for your helpful reply. I have now changed my approach to modifying the beta parameter instead, as you suggested in your previous reply. However, I’m still running into unexpected behaviour.

I would expect that I can change the beta parameters after the model is instantiated, to modify the progress of infection between iterations of the model; at least that is what I thought the constant_beta flag is for. However, it seems that the model ignores any changes that I make to the beta map after instantiating. What am I doing or understanding wrong?

Here’s my minimum working example (adapted to the new approach), where I set beta to 0 for all edges but new infections still happen.

# SETUP
from graph_tool.generation import price_network
from graph_tool.dynamics import SIRSState
g = price_network(20, directed=False)
# Initialise beta map with transmission probability 1 for all edges
beta_map = g.new_edge_property('float', 1)
model = SIRSState(g, beta=beta_map, r=0,
constant_beta=False) # ensure no spontaneous infections
state = model.get_state()

# TEST
print("before quarantining:\n", state.a)
# Set transmission probability to 0 for all edges
beta_map.a = 0
# Run model one time step
model.iterate_sync()
# New nodes in the filtered graph are infected
print("filtered state after quarantining:\n", state.a)

Essentially, I am looking for some way to isolate vertices and ensure they cannot infect others.

On a related note, I am running into issues implementing the following subroutine efficiently: for a list of vertices (as a numpy integer array), determine the indices of all edges in the graph incident to at least one of the vertices in the list. Here the index is w.r.t. edge property maps. Is there an efficient way using a graph-tool function that I’m missing?

Thanks again for your helpful reply. I have now changed my approach to modifying the beta parameter instead, as you suggested in your previous reply. However, I’m still running into unexpected behaviour.

I would expect that I can change the beta parameters after the model is instantiated, to modify the progress of infection between iterations of the model; at least that is what I thought the constant_beta flag is for. However, it seems that the model ignores any changes that I make to the beta map after instantiating. What am I doing or understanding wrong?

Here’s my minimum working example (adapted to the new approach), where I set beta to 0 for all edges but new infections still happen.

# SETUP
from graph_tool.generation import price_network
from graph_tool.dynamics import SIRSState
g = price_network(20, directed=False)
# Initialise beta map with transmission probability 1 for all edges
beta_map = g.new_edge_property('float', 1)
model = SIRSState(g, beta=beta_map, r=0,
constant_beta=False) # ensure no spontaneous infections
state = model.get_state()

# TEST
print("before quarantining:\n", state.a)
# Set transmission probability to 0 for all edges
beta_map.a = 0
# Run model one time step
model.iterate_sync()
# New nodes in the filtered graph are infected
print("filtered state after quarantining:\n", state.a)

Essentially, I am looking for some way to isolate vertices and ensure they cannot infect others.

This is in fact a bug with constant_beta=False: for efficiency, the
state keeps track of the total transmission probability per node,
separately from what beta says. So the change in beta will take effect
only the next time a node is infected.

So for now you will have to re-initialize the state every time you
change beta (or filter the graph), until I fix things for the next release.

On a related note, I am running into issues implementing the following subroutine efficiently: for a list of vertices (as a numpy integer array), determine the indices of all edges in the graph incident to at least one of the vertices in the list. Here the index is w.r.t. edge property maps. Is there an efficient way using a graph-tool function that I’m missing?

You can get something similar to this by marking the nodes with a
boolean property map and then calling edge_endpoint_property() which
will mark the incident edges.