66@authors: Emanuel-Cristian Boghiu, Elie Wolfe, Alejandro Pozas-Kerstjens
77"""
88import warnings
9- from functools import reduce , cached_property
9+ from functools import cached_property
1010from itertools import (chain ,
1111 combinations_with_replacement ,
1212 permutations )
@@ -888,8 +888,7 @@ def factorize_monomial_1d(self,
888888 ###########################################################################
889889 # FUNCTIONS PERTAINING TO SYMMETRIES #
890890 ###########################################################################
891- @cached_property
892- def inflation_symmetries (self ) -> np .ndarray :
891+ def inflation_generators (self ) -> np .ndarray :
893892 """Calculates all the symmetries pertaining to the set of generating
894893 monomials due to copy index relabelling. The new set of operators is a
895894 permutation of the old. The function outputs a list of all permutations.
@@ -903,39 +902,59 @@ def inflation_symmetries(self) -> np.ndarray:
903902 sources_with_copies = [source for source , inf_level
904903 in enumerate (self .inflation_level_per_source )
905904 if inf_level > 1 ]
905+
906+ identity_perm = np .arange (self ._nr_operators , dtype = np .intc )
907+ symmetries = [identity_perm ]
906908 if len (sources_with_copies ):
907909 permutation_failed = False
908- symmetries = []
909- identity_perm = np .arange (self ._nr_operators , dtype = np .intc )
910910 for source in tqdm (sources_with_copies ,
911911 disable = not self .verbose ,
912912 desc = "Calculating symmetries " ,
913913 leave = True ,
914914 position = 0 ):
915- one_source_symmetries = [identity_perm ]
915+ one_source_symmetries = []
916916 inf_level = self .inflation_level_per_source [source ]
917- perms = format_permutations (list (
918- permutations (range (inf_level )))[1 :])
919- for permutation in perms :
920- adjusted_ops = apply_source_perm (self ._lexorder ,
921- source ,
922- permutation )
923- try :
917+ raw_permutations = [list (range ())]
918+ # add the cycle
919+ if inf_level > 1 :
920+ raw_permutations [0 ][0 ] = 1
921+ raw_permutations [0 ][1 ] = 0
922+ if inf_level > 2 :
923+ raw_permutations .append (np .roll (list (range (inf_level )), 1 ).tolist ())
924+ if inf_level > 1 :
925+ perms = format_permutations (raw_permutations )
926+ for permutation in perms :
927+ adjusted_ops = apply_source_perm (self ._lexorder ,
928+ source ,
929+ permutation )
930+
924931 new_order = np .fromiter (
925932 (self ._lexorder_lookup [op .tobytes ()]
926- for op in adjusted_ops ),
927- dtype = np .intc
928- )
933+ for op in adjusted_ops ),
934+ dtype = np .intc )
929935 one_source_symmetries .append (new_order )
930- except KeyError :
931- permutation_failed = True
932- symmetries .append (np .asarray (one_source_symmetries ,
933- dtype = np .intc ))
934- if permutation_failed and (self .verbose > 0 ):
935- warn ("The generating set is not closed under source swaps."
936- + " Some symmetries will not be implemented." )
937- return reduce (perm_combiner , symmetries )
938- return np .arange (self ._nr_operators , dtype = np .intc )[np .newaxis ]
936+ symmetries .extend (np .asarray (one_source_symmetries ,
937+ dtype = np .intc ))
938+ if len (symmetries ) >= 2 :
939+ return symmetries [1 :]
940+ else :
941+ return symmetries
942+ return symmetries
943+
944+
945+ @cached_property
946+ def inflation_symmetries (self ) -> np .ndarray :
947+ """Calculates all the symmetries pertaining to the set of generating
948+ monomials due to copy index relabelling. The new set of operators is a
949+ permutation of the old. The function outputs a list of all permutations.
950+
951+ Returns
952+ -------
953+ numpy.ndarray[int]
954+ The permutations of the lexicographic order implied by the inflation
955+ symmetries.
956+ """
957+ return group_elements_from_generators (self .inflation_generators )
939958
940959 def add_symmetries (self ,
941960 new_symmetries : Union [np .ndarray , List [np .ndarray ]]
0 commit comments