@@ -657,124 +657,49 @@ function random_information_set_minimum_distance_bound!(::HasGauges, ::IsCSS, ::
657657 # this is a CSS subsystem code
658658
659659 n = S. n
660- if dressed
661- if which == :full
662- verbose && println (" Bounding the full dressed distance" )
663- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
664- _rref_no_col_swap_binary! (stabs)
665- stabs = _remove_empty (stabs, :rows )
666- gauges = _Flint_matrix_to_Julia_T_matrix (gauges_matrix (S), Int)
667- logs = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S), Int)
668- operators_to_reduce = vcat (stabs, gauges, logs)
669- check_against = permutedims (logs[:, [n + 1 : 2 n; 1 : n]])
670- curr_l_bound = S. l_bound_dressed
671- verbose && println (" Starting lower bound: $curr_l_bound " )
672-
673- # this is done in the constructor but the logical is not stored at the time
674- # so must redo here
675- mat = _rref_no_col_swap_binary (operators_to_reduce)
676- anti = mat * check_against
677- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
678- found = operators_to_reduce[index, :]
679- verbose && println (" Starting upper bound: $curr_u_bound " )
680- elseif which == :X
681- verbose && println (" Bounding the dressed X-distance" )
682- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
683- _rref_no_col_swap_binary! (stabs)
684- stabs = _remove_empty (stabs, :rows )
685- gauges = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[1 ][:, 1 : n] for log in S. gauge_ops]), Int)
686- logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]), Int)
687- operators_to_reduce = vcat (stabs, gauges, logs)
688- check_against = permutedims (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals])[:, [n + 1 : 2 n; 1 : n]])
689- curr_l_bound = S. l_bound_dx_dressed
690- verbose && println (" Starting lower bound: $curr_l_bound " )
691-
692- # this is done in the constructor but the logical is not stored at the time
693- # so must redo here
694- mat = _rref_no_col_swap_binary (operators_to_reduce)
695- anti = mat * check_against
696- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
697- found = operators_to_reduce[index, :]
698- verbose && println (" Starting upper bound: $curr_u_bound " )
660+ if which == :full
661+ upperx, foundx = random_information_set_minimum_distance_bound! (HasGauges (), IsCSS (), HasLogicals (), S, :X , dressed, max_iters, verbose)
662+ upperz, foundz = random_information_set_minimum_distance_bound! (HasGauges (), IsCSS (), HasLogicals (), S, :Z , dressed, max_iters, verbose)
663+ if upperx <= upperz
664+ if dressed
665+ S. u_bound_dressed = min (upperx, S. u_bound_dressed)
666+ else
667+ S. u_bound_bare = min (upperx, S. u_bound_bare)
668+ end
669+ return upperx, foundx
699670 else
700- verbose && println (" Bounding the dressed Z-distance" )
701- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
702- _rref_no_col_swap_binary! (stabs)
703- stabs = _remove_empty (stabs, :rows )
704- gauges = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. gauge_ops]), Int)
705- logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals]), Int)
706- operators_to_reduce = vcat (stabs, gauges, logs)
707- check_against = permutedims (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]))
708- curr_l_bound = S. l_bound_dz_dressed
709- verbose && println (" Starting lower bound: $curr_l_bound " )
710-
711- # this is done in the constructor but the logical is not stored at the time
712- # so must redo here
713- mat = _rref_no_col_swap_binary (operators_to_reduce)
714- anti = mat * check_against
715- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
716- found = operators_to_reduce[index, :]
717- verbose && println (" Starting upper bound: $curr_u_bound " )
671+ if dressed
672+ S. u_bound_dressed = min (upperz, S. u_bound_dressed)
673+ else
674+ S. u_bound_bare = min (upperz, S. u_bound_bare)
675+ end
676+ return upperz, foundz
718677 end
719678 else
720- if which == :full
721- verbose && println (" Bounding the full bare distance" )
722- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
723- _rref_no_col_swap_binary! (stabs)
724- stabs = _remove_empty (stabs, :rows )
725- logs = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S), Int)
726- operators_to_reduce = vcat (stabs, logs)
727- check_against = permutedims (logs[:, [n + 1 : 2 n; 1 : n]])
728- curr_l_bound = S. l_bound_bare
729- verbose && println (" Starting lower bound: $curr_l_bound " )
730-
731- # this is done in the constructor but the logical is not stored at the time
732- # so must redo here
733- mat = _rref_no_col_swap_binary (operators_to_reduce)
734- anti = mat * check_against
735- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
736- found = operators_to_reduce[index, :]
737- verbose && println (" Starting upper bound: $curr_u_bound " )
738- elseif which == :X
739- verbose && println (" Bounding the bare X-distance" )
740- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
741- _rref_no_col_swap_binary! (stabs)
742- stabs = _remove_empty (stabs, :rows )
743- logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]), Int)
744- operators_to_reduce = vcat (stabs, logs)
745- check_against = permutedims (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals])[:, [n + 1 : 2 n; 1 : n]])
746- curr_l_bound = S. l_bound_dx_bare
747- verbose && println (" Starting lower bound: $curr_l_bound " )
748-
749- # this is done in the constructor but the logical is not stored at the time
750- # so must redo here
751- mat = _rref_no_col_swap_binary (operators_to_reduce)
752- anti = mat * check_against
753- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
754- found = operators_to_reduce[index, :]
755- verbose && println (" Starting upper bound: $curr_u_bound " )
679+ stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S)[:, (which == :X ? (1 : n) : (n + 1 : 2 n))], UInt8)
680+ if dressed
681+ gauges = _Flint_matrix_to_Julia_T_matrix (gauge_operators_matrix (S)[:, (which == :X ? (1 : n) : (n + 1 : 2 n))], UInt8)
682+ stabs = [stabs; gauges]
683+ end
684+ _rref_no_col_swap_binary! (stabs)
685+ stabs = _remove_empty (stabs, :rows )
686+ logs = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S)[:, (which == :X ? (1 : n) : (n + 1 : 2 n))], UInt8)
687+ logs = _remove_empty (logs, :rows )
688+ operators_to_reduce = vcat (stabs, logs)
689+ check_against = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S)[:, (which == :X ? (n + 1 : 2 n) : (1 : n))], UInt8)
690+ check_against = permutedims (_remove_empty (check_against, :rows ))
691+ curr_l_bound = if dressed
692+ which == :X ? S. l_bound_dx_dressed : S. l_bound_dz_dressed
756693 else
757- verbose && println (" Bounding the bare Z-distance" )
758- stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
759- _rref_no_col_swap_binary! (stabs)
760- stabs = _remove_empty (stabs, :rows )
761- logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals]), Int)
762- operators_to_reduce = vcat (stabs, logs)
763- check_against = permutedims (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]))
764- curr_l_bound = S. l_bound_dx_bare
765- verbose && println (" Starting lower bound: $curr_l_bound " )
766-
767- # this is done in the constructor but the logical is not stored at the time
768- # so must redo here
769- mat = _rref_no_col_swap_binary (operators_to_reduce)
770- anti = mat * check_against
771- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
772- found = operators_to_reduce[index, :]
773- verbose && println (" Starting upper bound: $curr_u_bound " )
694+ which == :X ? S. l_bound_dx_bare : S. l_bound_dz_bare
774695 end
696+ verbose && println (" Starting lower bound: $curr_l_bound " )
697+ curr_u_bound, index = findmin (count (! iszero, logs[i, :]) for i in 1 : size (logs, 1 ))
698+ found = logs[index, :]
699+ verbose && println (" Starting upper bound: $curr_u_bound " )
775700 end
776701
777- uppers, founds = _RIS_bound_loop_symp ! (operators_to_reduce, check_against, curr_l_bound,
702+ uppers, founds = _RIS_bound_loop ! (operators_to_reduce, check_against, curr_l_bound,
778703 curr_u_bound, found, max_iters, n, verbose)
779704 loc = argmin (uppers)
780705 if dressed
@@ -795,7 +720,14 @@ function random_information_set_minimum_distance_bound!(::HasGauges, ::IsCSS, ::
795720 end
796721 end
797722 verbose && println (" Ending $max_iters iterations with an upper bound of $(uppers[loc]) " )
798- return uppers[loc], founds[loc]
723+ flint_mat_found = if which == :full
724+ matrix (field (S), permutedims (founds[loc]))
725+ elseif which == :X
726+ matrix (field (S), [permutedims (founds[loc]) zeros (Int, 1 , n)])
727+ else
728+ matrix (field (S), [zeros (Int, 1 , n) permutedims (founds[loc])])
729+ end
730+ return uppers[loc], flint_mat_found
799731end
800732
801733function random_information_set_minimum_distance_bound! (:: HasNoGauges , :: IsCSS , :: HasLogicals ,
@@ -979,7 +911,8 @@ function _RIS_bound_loop_symp!(operators_to_reduce, check_against, curr_l_bound:
979911 shuffle! (perm)
980912 _col_permutation_symp! (perm_ops, orig_ops, perm)
981913 # modifying this in place is not thread safe (apparently)
982- perm_ops = _rref_no_col_swap_binary (perm_ops)
914+ # perm_ops = _rref_no_col_swap_binary(perm_ops)
915+ _rref_no_col_swap_binary! (perm_ops)
983916 _col_permutation_symp! (ops, perm_ops, invperm (perm))
984917 LinearAlgebra. mul! (log_test, ops, check_against)
985918 for i in axes (log_test, 1 )
0 commit comments