How can I get reproducible results in a Jupyter Notebook (Python3)?
Defining a seed for the main random generators seems to be not enough, see MWE below:
import numpy as np
import random
import os
random.seed(0)
np.random.seed(0)
os.environ['PYTHONHASHSEED']=str(0)
import networkx
from networkx.algorithms.mis import maximal_independent_set
G = networkx.Graph()
G.add_edges_from([ ('A', 'B'), ('B', 'C'), ('C', 'D'), ('D','E'), ('E','F'), ('A','E'), ('B','E') ])
for i in range(0,10):
print( maximal_independent_set(G, seed=0) )
Gives the same result in each run in the loop.
However, when restarting the kernel and running the cells again, results change to another subset.