88import numpy as np
99import matplotlib .pyplot as plt
1010
11+
1112def cc_analysis (n : int , p : float , seed : int ):
1213 # The Reticula magic is happening in this paragraph:
1314 state = ret .mersenne_twister (seed )
@@ -25,16 +26,17 @@ def cc_analysis(n: int, p: float, seed: int):
2526 isotropic_chi = 1 / small_field * (1 / n * sum_squares - 1 / (n ** 2 )* sum_cubes )
2627 return largest_comp_size , classic_chi , expected_comp_size , isotropic_chi
2728
29+
2830if __name__ == "__main__" :
2931 parser = argparse .ArgumentParser (
30- description = "Analysis of connected component size and other "
31- "isometric percolation properties in G(n, p) networks." )
32+ description = "Analysis of connected component size and other "
33+ "isometric percolation properties in G(n, p) networks." )
3234 parser .add_argument ("figure" , type = str , help = "output figure filename" )
3335 parser .add_argument ("output" , type = str , help = "output json filename" )
3436 parser .add_argument ("--size" , type = int , default = 10000 , help = "system size" )
3537 parser .add_argument ("--ens" , type = int , default = 100 , help = "ensemble size" )
3638 parser .add_argument ("-j" , "--jobs" , type = int , default = os .cpu_count (),
37- help = "number of parallel workers" )
39+ help = "number of parallel workers" )
3840 args = parser .parse_args ()
3941
4042 seeds = range (args .ens )
@@ -51,10 +53,10 @@ def cc_analysis(n: int, p: float, seed: int):
5153 for p in p_values :
5254 for seed in seeds :
5355 futures .append ((p ,
54- executor .submit (cc_analysis , size , p , seed )))
56+ executor .submit (cc_analysis , size , p , seed )))
5557
5658 for p , f in tqdm .tqdm (futures ):
57- largest_comp_size , classic_chi ,\
59+ largest_comp_size , classic_chi , \
5860 exp_comp_size , isotropic_chi = f .result ()
5961
6062 if p not in largest_comps :
@@ -73,41 +75,39 @@ def cc_analysis(n: int, p: float, seed: int):
7375 isotropic_chis [p ] = []
7476 isotropic_chis [p ].append (isotropic_chi )
7577
76-
7778 fig , axes = plt .subplots (2 , 2 , figsize = (8 , 8 ), sharex = True ,
78- gridspec_kw = {"wspace" : 0.3 , "hspace" : 0.3 })
79+ gridspec_kw = {"wspace" : 0.3 , "hspace" : 0.3 })
7980
8081 ax_max , ax_classic_chi , ax_exp , ax_isotropic_chi = axes .flatten ()
8182
8283 ax_max .plot (
83- p_values - 1 / (size - 1 ),
84- [np .mean (largest_comps [p ]) for p in p_values ])
84+ p_values - 1 / (size - 1 ),
85+ [np .mean (largest_comps [p ]) for p in p_values ])
8586 ax_max .set_xlabel ("$p - p_c$" )
8687 ax_max .set_ylabel ("Largest connected component size" )
8788
8889 ax_classic_chi .plot (
89- p_values - 1 / (size - 1 ),
90- [np .mean (classic_chis [p ]) for p in p_values ])
90+ p_values - 1 / (size - 1 ),
91+ [np .mean (classic_chis [p ]) for p in p_values ])
9192 ax_classic_chi .set_xlabel ("$p - p_c$" )
9293 ax_classic_chi .set_ylabel ("Susceptibility "
93- "($\\ frac{\\ sum_{i>0} s_i^2}{\\ sum_{i > 0} s_i}$)" )
94+ "($\\ frac{\\ sum_{i>0} s_i^2}{\\ sum_{i > 0} s_i}$)" )
9495
9596 ax_exp .plot (
96- p_values - 1 / (size - 1 ),
97- [np .mean (expected_comps [p ]) for p in p_values ])
97+ p_values - 1 / (size - 1 ),
98+ [np .mean (expected_comps [p ]) for p in p_values ])
9899 ax_exp .set_xlabel ("$p - p_c$" )
99100 ax_exp .set_ylabel ("Expected component size" )
100101
101102 ax_isotropic_chi .plot (
102- p_values - 1 / (size - 1 ),
103- [np .mean (isotropic_chis [p ]) for p in p_values ])
103+ p_values - 1 / (size - 1 ),
104+ [np .mean (isotropic_chis [p ]) for p in p_values ])
104105 ax_isotropic_chi .set_xlabel ("$p - p_c$" )
105106 ax_isotropic_chi .set_ylabel ("Susceptibility "
106- "($\\ sum_i s_i^2 - \\ frac{1}{n} \\ sum_i s_i^3$)" )
107+ "($\\ sum_i s_i^2 - \\ frac{1}{n} \\ sum_i s_i^3$)" )
107108
108109 fig .savefig (args .figure )
109110
110-
111111 report = {
112112 "size" : size ,
113113 "p_values" : list (p_values ),
0 commit comments