@@ -637,19 +637,22 @@ is returned, and if `dressed = false` then the bound is for the bare distance. R
637637iterations and stops early if a logical of weight `d_lower_bound` is found.
638638"""
639639# here want to branch for graph states
640- function random_information_set_minimum_distance_bound (S:: T , which:: Symbol = :full ;
640+ function random_information_set_minimum_distance_bound! (S:: T , which:: Symbol = :full ;
641641 dressed:: Bool = true , max_iters:: Int = 10000 , verbose:: Bool = false ) where T <: AbstractSubsystemCode
642642
643643 which ∈ (:full , :X , :Z ) || throw (DomainError (which, " Must choose `:full`, `:X` or `:Z`." ))
644644 # order(field(S)) == 2 || throw(DomainError(S, "Currently only implemented for binary codes."))
645645 is_positive (max_iters) || throw (DomainError (max_iters, " The number of iterations must be a positive integer." ))
646646
647- return random_information_set_minimum_distance_bound (GaugeTrait (T), CSSTrait (T),
647+ return random_information_set_minimum_distance_bound! (GaugeTrait (T), CSSTrait (T),
648648 LogicalTrait (T), S, which, dressed, max_iters, verbose)
649649end
650- QDistRand (S:: T , which:: Symbol = :full ; dressed:: Bool = true , max_iters:: Int = 10000 , verbose:: Bool = false ) where T <: AbstractSubsystemCode = random_information_set_minimum_distance_bound (S, which; dressed = dressed, max_iters = max_iters, verbose = verbose)
650+ QDistRand! (S:: T , which:: Symbol = :full ; dressed:: Bool = true , max_iters:: Int = 10000 ,
651+ verbose:: Bool = false ) where T <: AbstractSubsystemCode =
652+ random_information_set_minimum_distance_bound! (S, which; dressed = dressed, max_iters =
653+ max_iters, verbose = verbose)
651654
652- function random_information_set_minimum_distance_bound (:: HasGauges , :: IsCSS , :: HasLogicals ,
655+ function random_information_set_minimum_distance_bound! (:: HasGauges , :: IsCSS , :: HasLogicals ,
653656 S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int , verbose:: Bool )
654657 # this is a CSS subsystem code
655658
@@ -752,7 +755,7 @@ function random_information_set_minimum_distance_bound(::HasGauges, ::IsCSS, ::H
752755 end
753756 end
754757
755- uppers, founds = _RIS_bound_loop (operators_to_reduce, check_against, curr_l_bound,
758+ uppers, founds = _RIS_bound_loop! (operators_to_reduce, check_against, curr_l_bound,
756759 curr_u_bound, found, max_iterst, n, verbose)
757760 loc = argmin (uppers)
758761 if dressed
@@ -775,33 +778,38 @@ function random_information_set_minimum_distance_bound(::HasGauges, ::IsCSS, ::H
775778 return uppers[loc], founds[loc]
776779end
777780
778- function random_information_set_minimum_distance_bound (:: HasNoGauges , :: IsCSS , :: HasLogicals ,
779- S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int )
781+ function random_information_set_minimum_distance_bound! (:: HasNoGauges , :: IsCSS , :: HasLogicals ,
782+ S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int , verbose :: Bool )
780783 # CSS stabilizer code
781784
785+ n = S. n
782786 if which == :full
783787 verbose && println (" Bounding the full distance" )
784- stabs = _remove_empty (_rref_no_col_swap! (_Flint_matrix_to_Julia_T_matrix (
785- stabilizers (S), UInt8)), :rows )
786- logs = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S), UInt8)
788+ # println(_rref_no_col_swap!(_Flint_matrix_to_Julia_T_matrix(stabilizers(S), Bool)))
789+ stabs = _Flint_matrix_to_Julia_T_matrix (stabilizers (S), Int)
790+ _rref_no_col_swap! (stabs)
791+ stabs = _remove_empty (stabs, :rows )
792+ logs = _Flint_matrix_to_Julia_T_matrix (logicals_matrix (S), Int)
787793 operators_to_reduce = vcat (stabs, logs)
788794 check_against = permutedims (logs[:, [n + 1 : 2 n; 1 : n]])
789- curr_l_bound = S. l_bound_bare
795+ curr_l_bound = S. l_bound
796+ verbose && println (" Starting lower bound: $curr_l_bound " )
790797
791798 # this is done in the constructor but the logical is not stored at the time
792799 # so must redo here
793- _, mat = _rref_no_col_swap! (operators_to_reduce)
800+ mat = _rref_no_col_swap (operators_to_reduce)
794801 anti = mat * check_against
795- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i: i , :]) for i in axes (anti, 1 )), :]))
802+ curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
796803 found = operators_to_reduce[index, :]
804+ verbose && println (" Starting upper bound: $curr_u_bound " )
797805 elseif which == :X
798806 verbose && println (" Bounding the X-distance" )
799807 stabs = _remove_empty (_rref_no_col_swap! (_Flint_matrix_to_Julia_T_matrix (
800808 X_stabilizers (S), UInt8)), :rows )
801809 logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]), UInt8)
802810 operators_to_reduce = vcat (stabs, logs)
803811 check_against = permutedims (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals])[:, [n + 1 : 2 n; 1 : n]])
804- curr_l_bound = S. l_bound_dx_bare
812+ curr_l_bound = S. l_bound_dx
805813
806814 # this is done in the constructor but the logical is not stored at the time
807815 # so must redo here
@@ -816,7 +824,7 @@ function random_information_set_minimum_distance_bound(::HasNoGauges, ::IsCSS, :
816824 logs = _Flint_matrix_to_Julia_T_matrix (reduce (vcat, [log[2 ][:, n + 1 : end ] for log in S. logicals]), UInt8)
817825 operators_to_reduce = vcat (stabs, logs)
818826 check_against = permutedims (reduce (vcat, [log[1 ][:, 1 : n] for log in S. logicals]))
819- curr_l_bound = S. l_bound_dx_bare
827+ curr_l_bound = S. l_bound_dx
820828
821829 # this is done in the constructor but the logical is not stored at the time
822830 # so must redo here
@@ -826,8 +834,8 @@ function random_information_set_minimum_distance_bound(::HasNoGauges, ::IsCSS, :
826834 found = operators_to_reduce[index, :]
827835 end
828836
829- uppers, founds = _RIS_bound_loop (operators_to_reduce, check_against, curr_l_bound,
830- curr_u_bound, found, max_iterst , n, verbose)
837+ uppers, founds = _RIS_bound_loop! (operators_to_reduce, check_against, curr_l_bound,
838+ curr_u_bound, found, max_iters , n, verbose)
831839 loc = argmin (uppers)
832840 if which == :full
833841 S. u_bound = uppers[loc]
@@ -839,8 +847,8 @@ function random_information_set_minimum_distance_bound(::HasNoGauges, ::IsCSS, :
839847 return uppers[loc], founds[loc]
840848end
841849
842- function random_information_set_minimum_distance_bound (:: HasGauges , :: IsNotCSS , :: HasLogicals ,
843- S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int )
850+ function random_information_set_minimum_distance_bound! (:: HasGauges , :: IsNotCSS , :: HasLogicals ,
851+ S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int , verbose :: Bool )
844852 # subsystem code
845853
846854 which == :full || throw (ArguementError (which, " Parameter is not valid for non-CSS codes." ))
@@ -859,7 +867,7 @@ function random_information_set_minimum_distance_bound(::HasGauges, ::IsNotCSS,
859867 # so must redo here
860868 _, mat = _rref_no_col_swap! (operators_to_reduce)
861869 anti = mat * check_against
862- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i: i , :]) for i in axes (anti, 1 )), :]))
870+ curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
863871 found = operators_to_reduce[index, :]
864872 else
865873 verbose && println (" Bounding the full bare distance" )
@@ -874,11 +882,11 @@ function random_information_set_minimum_distance_bound(::HasGauges, ::IsNotCSS,
874882 # so must redo here
875883 _, mat = _rref_no_col_swap! (operators_to_reduce)
876884 anti = mat * check_against
877- curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i: i , :]) for i in axes (anti, 1 )), :]))
885+ curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i, :]) for i in axes (anti, 1 )), :]))
878886 found = operators_to_reduce[index, :]
879887 end
880888
881- uppers, founds = _RIS_bound_loop (operators_to_reduce, check_against, curr_l_bound,
889+ uppers, founds = _RIS_bound_loop! (operators_to_reduce, check_against, curr_l_bound,
882890 curr_u_bound, found, max_iterst, n, verbose)
883891 loc = argmin (uppers)
884892 if dressed
@@ -889,8 +897,8 @@ function random_information_set_minimum_distance_bound(::HasGauges, ::IsNotCSS,
889897 return uppers[loc], founds[loc]
890898end
891899
892- function random_information_set_minimum_distance_bound (:: HasNoGauges , :: IsNotCSS , :: HasLogicals ,
893- S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int )
900+ function random_information_set_minimum_distance_bound! (:: HasNoGauges , :: IsNotCSS , :: HasLogicals ,
901+ S:: AbstractSubsystemCode , which:: Symbol , dressed:: Bool , max_iters:: Int , verbose :: Bool )
894902 # stabilizer code
895903
896904 which == :full || throw (ArguementError (which, " Parameter is not valid for non-CSS codes." ))
@@ -902,29 +910,31 @@ function random_information_set_minimum_distance_bound(::HasNoGauges, ::IsNotCSS
902910 operators_to_reduce = vcat (stabs, logs)
903911 check_against = permutedims (logs[:, [n + 1 : 2 n; 1 : n]])
904912 curr_l_bound = S. l_bound
913+ verbose && println (" Starting lower bound: $curr_l_bound " )
905914
906915 # this is done in the constructor but the logical is not stored at the time
907916 # so must redo here
908917 _, mat = _rref_no_col_swap! (operators_to_reduce)
909918 anti = mat * check_against
910919 curr_u_bound, index = findmin (row_wts_symplectic (mat[findall (! iszero (anti[i: i, :]) for i in axes (anti, 1 )), :]))
911920 found = operators_to_reduce[index, :]
921+ verbose && println (" Starting upper bound: $curr_u_bound " )
912922
913- uppers, founds = _RIS_bound_loop (operators_to_reduce, check_against, curr_l_bound,
914- curr_u_bound, found, max_iterst , n, verbose)
923+ uppers, founds = _RIS_bound_loop! (operators_to_reduce, check_against, curr_l_bound,
924+ curr_u_bound, found, max_iters , n, verbose)
915925 loc = argmin (uppers)
916926 S. u_bound = uppers[loc]
917927 return uppers[loc], founds[loc]
918928end
919929
920930# TODO rewrite all for graph states
921931# function random_information_set_minimum_distance_bound(::Union{HasGauges, HasNoGauges},
922- # ::Union{IsCSS, IsNotCSS}, ::HasNoLogicals, S::AbstractSubsystemCode, which::Symbol, dressed::Bool, max_iters::Int)
932+ # ::Union{IsCSS, IsNotCSS}, ::HasNoLogicals, S::AbstractSubsystemCode, which::Symbol, dressed::Bool, max_iters::Int, verbose::Bool )
923933# # graph state
924934
925935# end
926936
927- function _RIS_bound_loop (operators_to_reduce, check_against, curr_l_bound:: Int , curr_u_bound:: Int , found, max_iters:: Int , n:: Int , verbose:: Bool )
937+ function _RIS_bound_loop! (operators_to_reduce, check_against, curr_l_bound:: Int , curr_u_bound:: Int , found, max_iters:: Int , n:: Int , verbose:: Bool )
928938 num_thrds = Threads. nthreads ()
929939 verbose && println (" Detected $num_thrds threads." )
930940
@@ -933,7 +943,7 @@ function _RIS_bound_loop(operators_to_reduce, check_against, curr_l_bound::Int,
933943 founds = [found for _ in 1 : num_thrds]
934944 thread_load = Int (floor (max_iters / num_thrds))
935945 Threads. @threads for t in 1 : num_thrds
936- log_test = zeros (Int, size (check_against, 2 ))
946+ log_test = zeros (Int, size (operators_to_reduce, 1 ), size ( check_against, 2 ))
937947 for _ in 1 : thread_load
938948 if flag[]
939949 perm = shuffle (1 : n)
@@ -946,12 +956,13 @@ function _RIS_bound_loop(operators_to_reduce, check_against, curr_l_bound::Int,
946956 if any (! iszero, log_test[i, :])
947957 w = 0
948958 @inbounds for j in 1 : n
949- iszero (perm_ops[i. j]) && iszero (perm_ops[i, j + n]) || (w += 1 ;)
959+ iszero (perm_ops[i, j] % 2 ) && iszero (perm_ops[i, j + n] % 2 ) || (w += 1 ;)
950960 end
951961
952962 if uppers[t] > w
953963 uppers[t] = w
954- founds[t] .= perm_ops[i, invperm! (perm2)]
964+ # maybe use invpermute! here?
965+ founds[t] .= perm_ops[i, invperm (perm2)]
955966 verbose && println (" Adjusting upper bound: $w " )
956967 if curr_l_bound == w
957968 verbose && println (" Found a logical that matched the lower bound of $curr_l_bound " )
0 commit comments