It's not a big deal for now but ultimately we'll want to be able to set seeds for the rewiring algorithms. I see a few possibilities for this:
- Use the standard library's
random, and set the seed using random.seed($SEED). I don't like this because it mutates global state.
- Use numpy's
Generator object. This is probably preferable but a bit heavy (and tricky for users).
- Add a parameter for passing a random seed at initialization, store a
random.Random as an attribute, and call that to generate random numbers.
- Do the same, with a
np.random.Generator.
I think #3 could look like the following:
class BaseRewirer:
<...>
def __init__(seed: Optional[int] = None):
self.rand = random.Random(seed)
<...>
def rewire(self, G, **kwargs):
# selecting a random edge
rand_edge = rand.choice(list(G.edges))
<...>
The challenge with using np.random.Generator is that numpy randomness wants to return arrays, which we don't always want (e.g., when sampling edges).
It's not a big deal for now but ultimately we'll want to be able to set seeds for the rewiring algorithms. I see a few possibilities for this:
random, and set the seed usingrandom.seed($SEED). I don't like this because it mutates global state.Generatorobject. This is probably preferable but a bit heavy (and tricky for users).random.Randomas an attribute, and call that to generate random numbers.np.random.Generator.I think #3 could look like the following:
The challenge with using
np.random.Generatoris that numpy randomness wants to return arrays, which we don't always want (e.g., when sampling edges).