41
41
from sage .rings .polynomial .polydict import ETuple
42
42
from sage .rings .qqbar import AA , QQbar , number_field_elements_from_algebraics
43
43
44
+
44
45
class FMatrix (SageObject ):
45
46
r"""
46
47
An F-matrix for a :class:`FusionRing`.
@@ -297,7 +298,7 @@ def __init__(self, fusion_ring, fusion_label="f", var_prefix='fx', inject_variab
297
298
self .pool = None
298
299
299
300
#######################
300
- ### Class utilities ## #
301
+ # Class utilities #
301
302
#######################
302
303
303
304
def _repr_ (self ):
@@ -434,35 +435,31 @@ def fmat(self, a, b, c, d, x, y, data=True):
434
435
(-zeta60^14 + zeta60^6 + zeta60^4 - 1),
435
436
(zeta60^14 - zeta60^6 - zeta60^4 + 1)]
436
437
"""
437
- if (self ._FR .Nk_ij (a , b , x ) == 0 or self ._FR .Nk_ij (x , c , d ) == 0
438
- or self ._FR .Nk_ij (b , c , y ) == 0 or self ._FR .Nk_ij (a , y , d ) == 0 ):
438
+ if (self ._FR .Nk_ij (a , b , x ) == 0
439
+ or self ._FR .Nk_ij (x , c , d ) == 0
440
+ or self ._FR .Nk_ij (b , c , y ) == 0
441
+ or self ._FR .Nk_ij (a , y , d ) == 0 ):
439
442
return 0
440
443
441
444
# Some known zero F-symbols
442
445
if a == self ._FR .one ():
443
- if x == b and y == d :
444
- return 1
445
- else :
446
- return 0
446
+ return 1 if x == b and y == d else 0
447
+
447
448
if b == self ._FR .one ():
448
- if x == a and y == c :
449
- return 1
450
- else :
451
- return 0
449
+ return 1 if x == a and y == c else 0
450
+
452
451
if c == self ._FR .one ():
453
- if x == d and y == b :
454
- return 1
455
- else :
456
- return 0
452
+ return 1 if x == d and y == b else 0
453
+
457
454
if data :
458
455
# Better to use try/except for speed. Somewhat trivial, but worth
459
456
# hours when method is called ~10^11 times
460
457
try :
461
458
return self ._fvars [a , b , c , d , x , y ]
462
459
except KeyError :
463
460
return 0
464
- else :
465
- return (a , b , c , d , x , y )
461
+
462
+ return (a , b , c , d , x , y )
466
463
467
464
def fmatrix (self , a , b , c , d ):
468
465
r"""
@@ -583,7 +580,7 @@ def findcases(self, output=False):
583
580
idx_map = {}
584
581
ret = {}
585
582
id_anyon = self ._FR .one ()
586
- for ( a , b , c , d ) in product (self ._FR .basis (), repeat = 4 ):
583
+ for a , b , c , d in product (self ._FR .basis (), repeat = 4 ):
587
584
if a == id_anyon or b == id_anyon or c == id_anyon :
588
585
continue
589
586
for x in self .f_from (a , b , c , d ):
@@ -593,10 +590,8 @@ def findcases(self, output=False):
593
590
ret [(a , b , c , d , x , y )] = v
594
591
idx_map [i ] = (a , b , c , d , x , y )
595
592
i += 1
596
- if output :
597
- return idx_map , ret
598
- else :
599
- return i
593
+
594
+ return (idx_map , ret ) if output else i
600
595
601
596
def f_from (self , a , b , c , d ):
602
597
r"""
@@ -649,7 +644,7 @@ def f_to(self, a, b, c, d):
649
644
if self ._FR .Nk_ij (b , c , y ) != 0 and self ._FR .Nk_ij (a , y , d ) != 0 ]
650
645
651
646
####################
652
- ### Data getters ## #
647
+ # Data getters #
653
648
####################
654
649
655
650
def get_fvars (self ):
@@ -855,7 +850,7 @@ def get_radical_expression(self):
855
850
return {sextuple : val .radical_expression () for sextuple , val in self .get_fvars_in_alg_field ().items ()}
856
851
857
852
#######################
858
- ### Private helpers ## #
853
+ # Private helpers #
859
854
#######################
860
855
861
856
def _get_known_vals (self ):
@@ -894,12 +889,12 @@ def _get_known_nonz(self):
894
889
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100)
895
890
"""
896
891
nonz = {idx : 100 for idx in self ._singles }
897
- for idx , v in self ._ks .items ():
892
+ for idx , _ in self ._ks .items ():
898
893
nonz [idx ] = 100
899
894
return ETuple (nonz , self ._poly_ring .ngens ())
900
895
901
896
##############################
902
- ### Variables partitioning ## #
897
+ # Variables partitioning #
903
898
##############################
904
899
905
900
def largest_fmat_size (self ):
@@ -967,7 +962,7 @@ def get_fvars_by_size(self, n, indices=False):
967
962
return var_set
968
963
969
964
############################
970
- ### Checkpoint utilities ## #
965
+ # Checkpoint utilities #
971
966
############################
972
967
973
968
def save_fvars (self , filename ):
@@ -1009,12 +1004,10 @@ def save_fvars(self, filename):
1009
1004
True
1010
1005
sage: os.remove(filename)
1011
1006
"""
1012
- final_state = [
1013
- self ._fvars ,
1014
- self ._non_cyc_roots ,
1015
- self .get_coerce_map_from_fr_cyclotomic_field (),
1016
- self ._qqbar_embedding ,
1017
- ]
1007
+ final_state = [self ._fvars ,
1008
+ self ._non_cyc_roots ,
1009
+ self .get_coerce_map_from_fr_cyclotomic_field (),
1010
+ self ._qqbar_embedding ]
1018
1011
with open (filename , 'wb' ) as f :
1019
1012
pickle .dump (final_state , f )
1020
1013
@@ -1212,7 +1205,7 @@ def _restore_state(self, filename):
1212
1205
self ._update_reduction_params ()
1213
1206
1214
1207
#################
1215
- ### MapReduce ## #
1208
+ # MapReduce #
1216
1209
#################
1217
1210
1218
1211
def start_worker_pool (self , processes = None ):
@@ -1275,7 +1268,7 @@ class methods.
1275
1268
self ._reset_solver_state ()
1276
1269
# Set up shared memory resource handlers
1277
1270
n_proc = cpu_count () if processes is None else processes
1278
- self ._pid_list = shared_memory .ShareableList ([0 ]* (n_proc + 1 ))
1271
+ self ._pid_list = shared_memory .ShareableList ([0 ] * (n_proc + 1 ))
1279
1272
pids_name = self ._pid_list .shm .name
1280
1273
self ._solved = shared_memory .ShareableList (self ._solved )
1281
1274
s_name = self ._solved .shm .name
@@ -1304,7 +1297,7 @@ def init(fmats_id, solved_name, vd_name, ks_names, fvar_names, n_proc, pids_name
1304
1297
self .pool = Pool (processes = n_proc , initializer = init , initargs = args )
1305
1298
self ._pid_list [0 ] = getpid ()
1306
1299
for i , p in enumerate (self .pool ._pool ):
1307
- self ._pid_list [i + 1 ] = p .pid
1300
+ self ._pid_list [i + 1 ] = p .pid
1308
1301
# return True
1309
1302
1310
1303
def shutdown_worker_pool (self ):
@@ -1394,7 +1387,7 @@ def _map_triv_reduce(self, mapper, input_iter, worker_pool=None, chunksize=None,
1394
1387
return results
1395
1388
1396
1389
########################
1397
- ### Equations set up ## #
1390
+ # Equations set up #
1398
1391
########################
1399
1392
1400
1393
def get_orthogonality_constraints (self , output = True ):
@@ -1494,7 +1487,9 @@ def get_defining_equations(self, option, output=True):
1494
1487
self ._reset_solver_state ()
1495
1488
n_proc = self .pool ._processes if self .pool is not None else 1
1496
1489
params = [(child_id , n_proc , output ) for child_id in range (n_proc )]
1497
- eqns = self ._map_triv_reduce ('get_reduced_' + option , params , worker_pool = self .pool , chunksize = 1 , mp_thresh = 0 )
1490
+ eqns = self ._map_triv_reduce ('get_reduced_' + option , params ,
1491
+ worker_pool = self .pool , chunksize = 1 ,
1492
+ mp_thresh = 0 )
1498
1493
if output :
1499
1494
F = self ._field
1500
1495
for i , eq_tup in enumerate (eqns ):
@@ -1503,7 +1498,7 @@ def get_defining_equations(self, option, output=True):
1503
1498
self .ideal_basis .extend (eqns )
1504
1499
1505
1500
############################
1506
- ### Equations processing ## #
1501
+ # Equations processing #
1507
1502
############################
1508
1503
1509
1504
def _tup_to_fpoly (self , eq_tup ):
@@ -1611,7 +1606,7 @@ def _triangular_elim(self, eqns=None, verbose=True):
1611
1606
self .ideal_basis = eqns
1612
1607
1613
1608
#####################
1614
- ### Graph methods ## #
1609
+ # Graph methods #
1615
1610
#####################
1616
1611
1617
1612
def equations_graph (self , eqns = None ):
@@ -1820,7 +1815,7 @@ def _get_component_variety(self, var, eqns):
1820
1815
return [{inv_idx_map [i ]: value for i , (key , value ) in enumerate (sorted (soln .items ()))} for soln in var_in_R ]
1821
1816
1822
1817
#######################
1823
- ### Solution method ## #
1818
+ # Solution method #
1824
1819
#######################
1825
1820
1826
1821
# TODO: this can probably be improved by constructing a set of defining polynomials
@@ -1919,7 +1914,7 @@ def _get_explicit_solution(self, eqns=None, verbose=True):
1919
1914
for fx , rhs in self ._ks .items ():
1920
1915
if not self ._solved [fx ]:
1921
1916
lt = (ETuple ({fx : 2 }, n ), one )
1922
- eqns .append ((( lt , (ETuple ({}, n ), - rhs ) )))
1917
+ eqns .append ((lt , (ETuple ({}, n ), - rhs )))
1923
1918
eqns_partition = self ._partition_eqns (verbose = verbose )
1924
1919
1925
1920
F = self ._field
@@ -1956,20 +1951,20 @@ def _get_explicit_solution(self, eqns=None, verbose=True):
1956
1951
if self .attempt_number_field_computation ():
1957
1952
if verbose :
1958
1953
print ("Computing appropriate NumberField..." )
1959
- roots = [self ._FR .field ().gen ()]+ [r [1 ] for r in non_cyclotomic_roots ]
1954
+ roots = [self ._FR .field ().gen ()] + [r [1 ] for r in non_cyclotomic_roots ]
1960
1955
self ._field , bf_elts , self ._qqbar_embedding = number_field_elements_from_algebraics (roots , minimal = True )
1961
1956
else :
1962
1957
self ._field = QQbar
1963
1958
bf_elts = [self ._qqbar_embedding (F .gen ())]
1964
1959
bf_elts += [rhs for fx , rhs in non_cyclotomic_roots ]
1965
- self ._qqbar_embedding = lambda x : x
1960
+ self ._qqbar_embedding = lambda x : x
1966
1961
self ._non_cyc_roots = bf_elts [1 :]
1967
1962
1968
1963
# Embed cyclotomic field into newly constructed base field
1969
1964
cyc_gen_as_bf_elt = bf_elts .pop (0 )
1970
1965
phi = self ._FR .field ().hom ([cyc_gen_as_bf_elt ], self ._field )
1971
1966
self ._coerce_map_from_cyc_field = phi
1972
- numeric_fvars = {k : phi (v ) for k , v in numeric_fvars .items ()}
1967
+ numeric_fvars = {k : phi (v ) for k , v in numeric_fvars .items ()}
1973
1968
for i , elt in enumerate (bf_elts ):
1974
1969
numeric_fvars [non_cyclotomic_roots [i ][0 ]] = elt
1975
1970
# Update polynomial ring
@@ -2114,7 +2109,7 @@ def find_orthogonal_solution(self, checkpoint=False, save_results="", warm_start
2114
2109
print ("Set up {} hex and orthogonality constraints..." .format (len (self .ideal_basis )))
2115
2110
2116
2111
# Unzip _fvars and link to shared_memory structure if using multiprocessing
2117
- if use_mp :# and loads_shared_memory:
2112
+ if use_mp : # and loads_shared_memory:
2118
2113
self ._fvars = self ._shared_fvars
2119
2114
else :
2120
2115
n = self ._poly_ring .ngens ()
@@ -2164,12 +2159,12 @@ def find_orthogonal_solution(self, checkpoint=False, save_results="", warm_start
2164
2159
self ._chkpt_status = 7
2165
2160
self .clear_equations ()
2166
2161
if checkpoint :
2167
- remove ("fmatrix_solver_checkpoint_" + self .get_fr_str ()+ ".pickle" )
2162
+ remove ("fmatrix_solver_checkpoint_" + self .get_fr_str () + ".pickle" )
2168
2163
if save_results :
2169
2164
self .save_fvars (save_results )
2170
2165
2171
2166
#########################
2172
- ### Cyclotomic method ## #
2167
+ # Cyclotomic method #
2173
2168
#########################
2174
2169
2175
2170
def _fix_gauge (self , algorithm = "" ):
@@ -2202,8 +2197,8 @@ def _fix_gauge(self, algorithm=""):
2202
2197
break
2203
2198
2204
2199
# Fix var = 1, substitute, and solve equations
2205
- self .ideal_basis .add (var - 1 )
2206
- print ("adding equation..." , var - 1 )
2200
+ self .ideal_basis .add (var - 1 )
2201
+ print ("adding equation..." , var - 1 )
2207
2202
self .ideal_basis = set (Ideal (list (self .ideal_basis )).groebner_basis (algorithm = algorithm ))
2208
2203
self ._substitute_degree_one ()
2209
2204
self ._update_equations ()
@@ -2336,7 +2331,7 @@ def find_cyclotomic_solution(self, equations=None, algorithm="", verbose=True, o
2336
2331
if equations is None :
2337
2332
if verbose :
2338
2333
print ("Setting up hexagons and pentagons..." )
2339
- equations = self .get_defining_equations ("hexagons" )+ self .get_defining_equations ("pentagons" )
2334
+ equations = self .get_defining_equations ("hexagons" ) + self .get_defining_equations ("pentagons" )
2340
2335
if verbose :
2341
2336
print ("Finding a Groebner basis..." )
2342
2337
self .ideal_basis = set (Ideal (equations ).groebner_basis (algorithm = algorithm ))
@@ -2352,7 +2347,7 @@ def find_cyclotomic_solution(self, equations=None, algorithm="", verbose=True, o
2352
2347
return self ._fvars
2353
2348
2354
2349
#####################
2355
- ### Verifications ## #
2350
+ # Verifications #
2356
2351
#####################
2357
2352
2358
2353
def fmats_are_orthogonal (self ):
0 commit comments