@@ -64,6 +64,7 @@ cdef inline OrbitPartition *OP_new(int n) noexcept:
6464 OP_clear(OP)
6565 return OP
6666
67+
6768cdef inline void OP_dealloc(OrbitPartition * OP) noexcept:
6869 if OP is not NULL :
6970 sig_free(OP.parent)
@@ -72,6 +73,7 @@ cdef inline void OP_dealloc(OrbitPartition *OP) noexcept:
7273 sig_free(OP.size)
7374 sig_free(OP)
7475
76+
7577cdef OP_string(OrbitPartition * OP):
7678 """
7779 Return a string representation of the OrbitPartition.
@@ -232,6 +234,7 @@ cdef inline PartitionStack *PS_new(int n, bint unit_partition) noexcept:
232234 PS_unit_partition(PS)
233235 return PS
234236
237+
235238cdef void PS_unit_partition(PartitionStack * PS) noexcept:
236239 """
237240 Set partition stack to a single partition with a single cell.
@@ -244,6 +247,7 @@ cdef void PS_unit_partition(PartitionStack *PS) noexcept:
244247 PS.entries[n- 1 ] = n - 1
245248 PS.levels[n- 1 ] = - 1
246249
250+
247251cdef inline PartitionStack * PS_copy(PartitionStack * PS) noexcept:
248252 """
249253 Allocate and return a pointer to a copy of PartitionStack PS. Return a null
@@ -263,11 +267,13 @@ cdef inline PartitionStack *PS_copy(PartitionStack *PS) noexcept:
263267 PS_copy_from_to(PS, PS2)
264268 return PS2
265269
270+
266271cdef inline void PS_dealloc(PartitionStack * PS) noexcept:
267272 if PS is not NULL :
268273 sig_free(PS.entries)
269274 sig_free(PS)
270275
276+
271277cdef PartitionStack * PS_from_list(list L) noexcept:
272278 """
273279 Allocate and return a pointer to a PartitionStack representing L. Return a
@@ -293,6 +299,7 @@ cdef PartitionStack *PS_from_list(list L) noexcept:
293299 PS.degree = n
294300 return PS
295301
302+
296303cdef PS_print(PartitionStack * PS):
297304 """
298305 Print a visual representation of PS.
@@ -301,6 +308,7 @@ cdef PS_print(PartitionStack *PS):
301308 for i in range (PS.depth + 1 ):
302309 PS_print_partition(PS, i)
303310
311+
304312cdef PS_print_partition(PartitionStack * PS, int k):
305313 """
306314 Print the partition at depth k.
@@ -315,6 +323,7 @@ cdef PS_print_partition(PartitionStack *PS, int k):
315323 s = s[:- 1 ] + ' )'
316324 print (s)
317325
326+
318327cdef int PS_first_smallest(PartitionStack * PS, bitset_t b, int * second_pos = NULL ) noexcept:
319328 """
320329 Find the first occurrence of the smallest cell of size greater than one,
@@ -379,7 +388,7 @@ cdef int PS_all_new_cells(PartitionStack *PS, bitset_t** nonsingletons_ptr) noex
379388 bitset_init(nonsingletons[count- 1 ], n)
380389 bitset_copy(nonsingletons[count- 1 ], scratch)
381390 else :
382- if beg== 0 :
391+ if beg == 0 :
383392 nonsingletons = < bitset_t* > sig_realloc(nonsingletons, sizeof(bitset_t))
384393 if nonsingletons is NULL :
385394 raise MemoryError (" Memory error in PS_all_new_cells" )
@@ -391,6 +400,7 @@ cdef int PS_all_new_cells(PartitionStack *PS, bitset_t** nonsingletons_ptr) noex
391400 nonsingletons_ptr[0 ] = nonsingletons
392401 return count
393402
403+
394404cdef int PS_find_element(PartitionStack * PS, bitset_t b, int x) except - 1 :
395405 """
396406 Find the cell containing x, store its entries to b and return the location
@@ -414,6 +424,7 @@ cdef int PS_find_element(PartitionStack *PS, bitset_t b, int x) except -1:
414424 i += 1
415425 return location
416426
427+
417428cdef list PS_singletons(PartitionStack * part):
418429 """
419430 Return the list of all singletons in the ``PartitionStack``.
@@ -583,6 +594,7 @@ cdef enum:
583594 default_num_gens = 8
584595 default_num_bits = 64
585596
597+
586598cdef StabilizerChain * SC_new(int n, bint init_gens = True ) noexcept:
587599 """
588600 Allocate and return a pointer to a new StabilizerChain of degree n. Return
@@ -653,6 +665,7 @@ cdef StabilizerChain *SC_new(int n, bint init_gens=True) noexcept:
653665
654666 return SC
655667
668+
656669cdef inline int SC_realloc_gens(StabilizerChain * SC, int level, int size) noexcept:
657670 """
658671 Reallocate generator array at level `level` to size `size`.
@@ -675,6 +688,7 @@ cdef inline int SC_realloc_gens(StabilizerChain *SC, int level, int size) noexce
675688 SC.array_size[level] = size
676689 return 0
677690
691+
678692cdef inline void SC_dealloc(StabilizerChain * SC) noexcept:
679693 cdef int i, n
680694 if SC is not NULL :
@@ -683,13 +697,14 @@ cdef inline void SC_dealloc(StabilizerChain *SC) noexcept:
683697 for i in range (n):
684698 sig_free(SC.generators[i])
685699 sig_free(SC.gen_inverses[i])
686- sig_free(SC.generators) # frees int_ptrs
687- sig_free(SC.orbit_sizes) # frees int_array
700+ sig_free(SC.generators) # frees int_ptrs
701+ sig_free(SC.orbit_sizes) # frees int_array
688702 sig_free(SC.gen_used.bits)
689703 sig_free(SC.gen_is_id.bits)
690704 OP_dealloc(SC.OP_scratch)
691705 sig_free(SC)
692706
707+
693708cdef StabilizerChain * SC_symmetric_group(int n) noexcept:
694709 """
695710 Return a stabilizer chain for the symmetric group on {0, 1, ..., n-1}.
@@ -724,13 +739,14 @@ cdef StabilizerChain *SC_symmetric_group(int n) noexcept:
724739 SC.parents[i][i+ j] = b
725740 SC.labels[i][i+ j] = j
726741 for j in range (n - i - 1 ):
727- # j-th generator sends i+j+1 to b
742+ # j-th generator sends i+j+1 to b
728743 memcpy(SC.generators[i] + n* j, id_perm, n * sizeof(int ) )
729744 SC.generators[i][n* j + i+ j+ 1 ] = b
730745 SC.generators[i][n* j + b] = i+ j+ 1
731746 memcpy(SC.gen_inverses[i] + n* j, SC.generators[i] + n* j, n * sizeof(int ) )
732747 return SC
733748
749+
734750cdef StabilizerChain * SC_alternating_group(int n) noexcept:
735751 """
736752 Return a stabilizer chain for the alternating group on {0, 1, ..., n-1}.
@@ -767,14 +783,15 @@ cdef StabilizerChain *SC_alternating_group(int n) noexcept:
767783 SC.labels[i][i+ j] = j
768784 SC.labels[i][n- 1 ] = - (n- i- 2 )
769785 for j in range (n - i - 2 ):
770- # j-th generator sends i+j+1 to b, i+j+2 to i+j+1, and b to i+j+2
786+ # j-th generator sends i+j+1 to b, i+j+2 to i+j+1, and b to i+j+2
771787 memcpy(SC.generators[i] + n* j, id_perm, n * sizeof(int ) )
772788 SC.generators[i][n* j + i+ j+ 1 ] = b
773789 SC.generators[i][n* j + b ] = i+ j+ 2
774790 SC.generators[i][n* j + i+ j+ 2 ] = i+ j+ 1
775791 SC_invert_perm(SC.gen_inverses[i] + n* j, SC.generators[i] + n* j, n)
776792 return SC
777793
794+
778795cdef int SC_realloc_bitsets(StabilizerChain * SC, unsigned long size) noexcept:
779796 """
780797 If size is larger than current allocation, double the size of the bitsets
@@ -804,11 +821,14 @@ cdef int SC_realloc_bitsets(StabilizerChain *SC, unsigned long size) noexcept:
804821 SC.gen_used.size = new_size
805822 SC.gen_is_id.size = new_size
806823 SC.gen_used.bits[size_old >> index_shift] &= limb_lower_bits_down(size_old)
807- memset(SC.gen_used.bits + (size_old >> index_shift) + 1 , 0 , (limbs - (size_old >> index_shift) - 1 ) * sizeof(unsigned long ))
824+ memset(SC.gen_used.bits + (size_old >> index_shift) + 1 , 0 ,
825+ (limbs - (size_old >> index_shift) - 1 ) * sizeof(unsigned long ))
808826 SC.gen_is_id.bits[size_old >> index_shift] &= limb_lower_bits_down(size_old)
809- memset(SC.gen_is_id.bits + (size_old >> index_shift) + 1 , 0 , (limbs - (size_old >> index_shift) - 1 ) * sizeof(unsigned long ))
827+ memset(SC.gen_is_id.bits + (size_old >> index_shift) + 1 , 0 ,
828+ (limbs - (size_old >> index_shift) - 1 ) * sizeof(unsigned long ))
810829 return 0
811830
831+
812832cdef StabilizerChain * SC_copy(StabilizerChain * SC, int level) noexcept:
813833 """
814834 Create a copy of the first `level` levels of SC. Must have 0 < level.
@@ -834,15 +854,16 @@ cdef StabilizerChain *SC_copy(StabilizerChain *SC, int level) noexcept:
834854 SC_dealloc(SCC)
835855 return NULL
836856 SCC.array_size[i] = default_num_gens
837- SC_copy_nomalloc(SCC, SC, level) # no chance for memory error here...
857+ SC_copy_nomalloc(SCC, SC, level) # no chance for memory error here...
838858 return SCC
839859
860+
840861cdef int SC_copy_nomalloc(StabilizerChain * SC_dest, StabilizerChain * SC, int level) noexcept:
841862 cdef int i, n = SC.degree
842863 level = min (level, SC.base_size)
843864 SC_dest.base_size = level
844- memcpy(SC_dest.orbit_sizes, SC.orbit_sizes, 2 * n * sizeof(int ) ) # copies orbit_sizes, num_gens
845- memcpy(SC_dest.base_orbits[0 ], SC.base_orbits[0 ], 3 * n* n * sizeof(int ) ) # copies base_orbits, parents, labels
865+ memcpy(SC_dest.orbit_sizes, SC.orbit_sizes, 2 * n * sizeof(int ) ) # copies orbit_sizes, num_gens
866+ memcpy(SC_dest.base_orbits[0 ], SC.base_orbits[0 ], 3 * n* n * sizeof(int ) ) # copies base_orbits, parents, labels
846867 for i in range (level):
847868 if SC.num_gens[i] > SC_dest.array_size[i]:
848869 if SC_realloc_gens(SC_dest, i, max (SC.num_gens[i], 2 * SC_dest.array_size[i])):
@@ -851,6 +872,7 @@ cdef int SC_copy_nomalloc(StabilizerChain *SC_dest, StabilizerChain *SC, int lev
851872 memcpy(SC_dest.gen_inverses[i], SC.gen_inverses[i], SC.num_gens[i]* n * sizeof(int ) )
852873 return 0
853874
875+
854876cdef SC_print_level(StabilizerChain * SC, int level):
855877 cdef int i, j, n = SC.degree
856878 if level < SC.base_size:
@@ -890,6 +912,7 @@ cdef StabilizerChain *SC_new_base(StabilizerChain *SC, int *base, int base_len)
890912 return NULL
891913 return NEW
892914
915+
893916cdef int SC_new_base_nomalloc(StabilizerChain * SC_dest, StabilizerChain * SC, int * base, int base_len) noexcept:
894917 cdef int i
895918 SC_dest.base_size = 0
@@ -900,6 +923,7 @@ cdef int SC_new_base_nomalloc(StabilizerChain *SC_dest, StabilizerChain *SC, int
900923 return 1
901924 return 0
902925
926+
903927cdef int SC_update(StabilizerChain * dest, StabilizerChain * source, int level) noexcept:
904928 cdef mpz_t src_order, dst_order
905929 cdef int * perm = dest.perm_scratch
@@ -934,6 +958,7 @@ cdef int SC_update(StabilizerChain *dest, StabilizerChain *source, int level) no
934958 mpz_clear(dst_order)
935959 return 0
936960
961+
937962cdef StabilizerChain * SC_insert_base_point(StabilizerChain * SC, int level, int p) noexcept:
938963 """
939964 Insert the point ``p`` as a base point on level ``level``. Return a new
@@ -961,6 +986,7 @@ cdef StabilizerChain *SC_insert_base_point(StabilizerChain *SC, int level, int p
961986 return NULL
962987 return NEW
963988
989+
964990cdef int SC_insert_base_point_nomalloc(StabilizerChain * SC_dest, StabilizerChain * SC, int level, int p) noexcept:
965991 cdef int i, b
966992 SC_copy_nomalloc(SC_dest, SC, level)
@@ -973,6 +999,7 @@ cdef int SC_insert_base_point_nomalloc(StabilizerChain *SC_dest, StabilizerChain
973999 return 1
9741000 return 0
9751001
1002+
9761003cdef int SC_re_tree(StabilizerChain * SC, int level, int * perm, int x) noexcept:
9771004 """
9781005 Return values:
@@ -1014,6 +1041,7 @@ cdef int SC_re_tree(StabilizerChain *SC, int level, int *perm, int x) noexcept:
10141041 i += 1
10151042 return 0
10161043
1044+
10171045cdef int SC_sift(StabilizerChain * SC, int level, int x, int * gens, int num_gens, int * new_gens) noexcept:
10181046 """
10191047 Apply Schreier's subgroup lemma[1] as follows. Given a level, a point x, and
@@ -1035,8 +1063,8 @@ cdef int SC_sift(StabilizerChain *SC, int level, int x, int *gens, int num_gens,
10351063
10361064 # copy a representative taking base to the point x to each of these
10371065 cdef int i
1038- cdef int * temp = SC.gen_inverses[level] + n* SC.num_gens[level] # one more scratch space
1039- # (available since num_gens > 0)
1066+ cdef int * temp = SC.gen_inverses[level] + n* SC.num_gens[level] # one more scratch space
1067+ # (available since num_gens > 0)
10401068 cdef int * rep_inv = temp
10411069 SC_identify(rep_inv, n)
10421070 SC_compose_up_to_base(SC, level, x, rep_inv)
@@ -1060,6 +1088,7 @@ cdef int SC_sift(StabilizerChain *SC, int level, int x, int *gens, int num_gens,
10601088 SC_mult_perms(perm, perm, perm_rep_inv, n)
10611089 return SC_insert(SC, level+ 1 , new_gens, num_gens)
10621090
1091+
10631092cdef int SC_insert_and_sift(StabilizerChain * SC, int level, int * pi, int num_perms, bint sift) noexcept:
10641093 cdef int i, j, b, n = SC.degree
10651094 cdef int perm_gen_index
@@ -1109,7 +1138,7 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
11091138 bitset_set(& SC.gen_used, perm_gen_index)
11101139 if SC_re_tree(SC, level, perm, x):
11111140 return 1
1112- start_over = 1 # we must look anew
1141+ start_over = 1 # we must look anew
11131142 break
11141143 if start_over:
11151144 break
@@ -1121,7 +1150,7 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
11211150 # now we have an x which maps to a new point under perm,
11221151 if SC_re_tree(SC, level, perm, x):
11231152 return 1
1124- start_over = 1 # we must look anew
1153+ start_over = 1 # we must look anew
11251154 break
11261155 if start_over:
11271156 break
@@ -1132,7 +1161,7 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
11321161 # now we have an x which maps to a new point under perm,
11331162 if SC_re_tree(SC, level, perm, x):
11341163 return 1
1135- start_over = 1 # we must look anew
1164+ start_over = 1 # we must look anew
11361165 break
11371166 if not sift:
11381167 return 0
@@ -1167,6 +1196,7 @@ cdef int SC_insert_and_sift(StabilizerChain *SC, int level, int *pi, int num_per
11671196 section += 1
11681197 return 0
11691198
1199+
11701200cdef bint SC_is_giant(int n, int num_perms, int * perms, float p, bitset_t support) noexcept:
11711201 """
11721202 Test whether the group generated by the input permutations is a giant, i.e.,
@@ -1692,6 +1722,7 @@ cdef int sort_by_function(PartitionStack *PS, int start, int *degrees) noexcept:
16921722 j += 1
16931723 return max_location
16941724
1725+
16951726cdef int refine_by_orbits(PartitionStack * PS, StabilizerChain * SC, int * perm_stack, int * cells_to_refine_by, int * ctrb_len) noexcept:
16961727 """
16971728 Given a stabilizer chain SC, refine the partition stack PS so that each cell
@@ -1732,6 +1763,7 @@ cdef int refine_by_orbits(PartitionStack *PS, StabilizerChain *SC, int *perm_sta
17321763 start += i
17331764 return invariant
17341765
1766+
17351767cdef int compute_relabeling(StabilizerChain * group, StabilizerChain * scratch_group,
17361768 int * permutation, int * relabeling) noexcept:
17371769 """
0 commit comments