Skip to content

Commit 4eca25b

Browse files
committed
RIS bug fix
1 parent 034679b commit 4eca25b

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/Classical/weight_dist.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,17 @@ function minimum_words(C::AbstractLinearCode)
10191019
end
10201020
end
10211021

1022+
1023+
# classical version of QDistRnd here
1024+
1025+
1026+
1027+
1028+
1029+
1030+
1031+
1032+
10221033
#############################
10231034
# Weight Enumerators
10241035
#############################

src/CodingTheory.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ include("Quantum/weight_dist.jl")
362362
# export weight_plot_CSS_X, weight_plot_CSS_Z, weight_plot_CSS, minimum_distance_X_Z,
363363
# minimum_distance_X, minimum_distance_Z, is_pure, QDistRndCSS
364364
export minimum_distance_upper_bound!, random_information_set_minimum_distance_bound!,
365-
QDistRand!
365+
QDistRnd!
366366

367367
#############################
368368
# Quantum/product_codes.jl

src/Quantum/weight_dist.jl

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ function random_information_set_minimum_distance_bound!(S::T, which::Symbol = :f
647647
return random_information_set_minimum_distance_bound!(GaugeTrait(T), CSSTrait(T),
648648
LogicalTrait(T), S, which, dressed, max_iters, verbose)
649649
end
650-
QDistRand!(S::T, which::Symbol = :full; dressed::Bool = true, max_iters::Int = 10000,
650+
QDistRnd!(S::T, which::Symbol = :full; dressed::Bool = true, max_iters::Int = 10000,
651651
verbose::Bool = false) where T <: AbstractSubsystemCode =
652652
random_information_set_minimum_distance_bound!(S, which; dressed = dressed, max_iters =
653653
max_iters, verbose = verbose)
@@ -775,7 +775,7 @@ function random_information_set_minimum_distance_bound!(::HasGauges, ::IsCSS, ::
775775
end
776776

777777
uppers, founds = _RIS_bound_loop!(operators_to_reduce, check_against, curr_l_bound,
778-
curr_u_bound, found, max_iterst, n, verbose)
778+
curr_u_bound, found, max_iters, n, verbose)
779779
loc = argmin(uppers)
780780
if dressed
781781
if which == :full
@@ -794,6 +794,7 @@ function random_information_set_minimum_distance_bound!(::HasGauges, ::IsCSS, ::
794794
S.u_bound_dz_bare = uppers[loc]
795795
end
796796
end
797+
verbose && println("Ending $max_iters iterations with an upper bound of $(uppers[loc])")
797798
return uppers[loc], founds[loc]
798799
end
799800

@@ -870,6 +871,7 @@ function random_information_set_minimum_distance_bound!(::HasNoGauges, ::IsCSS,
870871
else
871872
S.u_bound_dz = uppers[loc]
872873
end
874+
verbose && println("Ending $max_iters iterations with an upper bound of $(uppers[loc])")
873875
return uppers[loc], founds[loc]
874876
end
875877

@@ -920,13 +922,14 @@ function random_information_set_minimum_distance_bound!(::HasGauges, ::IsNotCSS,
920922
end
921923

922924
uppers, founds = _RIS_bound_loop!(operators_to_reduce, check_against, curr_l_bound,
923-
curr_u_bound, found, max_iterst, n, verbose)
925+
curr_u_bound, found, max_iters, n, verbose)
924926
loc = argmin(uppers)
925927
if dressed
926928
S.u_bound_dressed = uppers[loc]
927929
else
928930
S.u_bound_bare = uppers[loc]
929931
end
932+
verbose && println("Ending $max_iters iterations with an upper bound of $(uppers[loc])")
930933
return uppers[loc], founds[loc]
931934
end
932935

@@ -959,6 +962,7 @@ function random_information_set_minimum_distance_bound!(::HasNoGauges, ::IsNotCS
959962
curr_u_bound, found, max_iters, n, verbose)
960963
loc = argmin(uppers)
961964
S.u_bound = uppers[loc]
965+
verbose && println("Ending $max_iters iterations with an upper bound of $(uppers[loc])")
962966
return uppers[loc], founds[loc]
963967
end
964968

@@ -977,15 +981,15 @@ function _RIS_bound_loop!(operators_to_reduce, check_against, curr_l_bound::Int,
977981
uppers = [curr_u_bound for _ in 1:num_thrds]
978982
founds = [found for _ in 1:num_thrds]
979983
thread_load = Int(floor(max_iters / num_thrds))
980-
# Threads.@threads for t in 1:num_thrds
981-
for t in 1:num_thrds
984+
Threads.@threads for t in 1:num_thrds
982985
log_test = zeros(Int, size(operators_to_reduce, 1), size(check_against, 2))
983986
for _ in 1:thread_load
984987
if flag[]
985988
perm = shuffle(1:n)
986989
perm2 = [perm; perm .+ n]
987990
perm_ops = operators_to_reduce[:, perm2]
988-
_rref_no_col_swap_binary!(perm_ops)
991+
# modifying this in place is not thread safe (apparently)
992+
perm_ops = _rref_no_col_swap_binary(perm_ops)
989993
ops = perm_ops[:, invperm(perm2)]
990994
LinearAlgebra.mul!(log_test, ops, check_against)
991995
for i in axes(log_test, 1)
@@ -998,12 +1002,11 @@ function _RIS_bound_loop!(operators_to_reduce, check_against, curr_l_bound::Int,
9981002

9991003
if uppers[t] > w
10001004
uppers[t] = w
1001-
# maybe use invpermute! here?
10021005
founds[t] .= ops[i, :]
1003-
verbose && println("Adjusting upper bound: $w")
1006+
verbose && println("Adjusting (thread's local) upper bound: $w")
10041007
if curr_l_bound == w
10051008
verbose && println("Found a logical that matched the lower bound of $curr_l_bound")
1006-
# Threads.atomic_cas!(flag, true, false)
1009+
Threads.atomic_cas!(flag, true, false)
10071010
break
10081011
end
10091012
end
@@ -1039,7 +1042,7 @@ function _RIS_bound_loop!(operators_to_reduce, check_against, curr_l_bound::Int,
10391042
if upper_temp > w
10401043
upper_temp = w
10411044
found_temp .= ops[i, :]
1042-
verbose && println("Adjusting upper bound: $w")
1045+
verbose && println("Adjusting (thread's local) upper bound: $w")
10431046
if curr_l_bound == w
10441047
verbose && println("Found a logical that matched the lower bound of $curr_l_bound")
10451048
flag = false

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ _rref_no_col_swap(M::CTMatrixTypes) = _rref_no_col_swap(M, axes(M, 1), axes(M, 2
436436
function _rref_no_col_swap_binary(A::Union{BitMatrix, Matrix{Bool}, Matrix{<: Integer}},
437437
row_range::UnitRange{Int} = 1:size(A, 1), col_range::UnitRange{Int} = 1:size(A, 2))
438438

439-
B = copy(A)
439+
B = deepcopy(A)
440440
_rref_no_col_swap_binary!(B, row_range, col_range)
441441
return B
442442
end

0 commit comments

Comments
 (0)