Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MIS x86 SubspaceMap Int64 instead of Int bug #597

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/BloqadeMIS/src/loss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,30 @@ function rydberg_density_sum end
rydberg_density_sum(x) = rydberg_density_sum(identity, x)

struct SubspaceMap
d::Dict{Int,Int}
d::Dict{Int64,Int64}
end

function SubspaceMap(f, subspace::Subspace)
key = Vector{Int}(undef, length(subspace))
val = Vector{Int}(undef, length(subspace))
key = Vector{Int64}(undef, length(subspace))
val = Vector{Int64}(undef, length(subspace))
origin = vec(subspace)
@inbounds Threads.@threads for idx in 1:length(origin)
cfg = origin[idx]
key[idx] = cfg
val[idx] = to_int64(f(cfg))
end
return SubspaceMap(Dict{Int,Int}(zip(key, val)))
return SubspaceMap(Dict{Int64,Int64}(zip(key, val)))
end

Base.length(map::SubspaceMap) = length(map.d)
Base.getindex(map::SubspaceMap, cfg::Int) = map.d[cfg]
(map::SubspaceMap)(cfg::Int) = map[cfg]
Base.getindex(map::SubspaceMap, cfg::Integer) = map.d[cfg]
(map::SubspaceMap)(cfg::Integer) = map[cfg]

function to_int64(b::BitVector) # workaround type piracy
length(b) <= 64 || throw(ArgumentError("length is larger than 64"))
# NOTE: since we only use this to calculate number of ones
# thus we don't need to check top bit
return reinterpret(Int, b.chunks[1])
return reinterpret(Int64, b.chunks[1])
end

struct ConfigAmplitude{Reg<:YaoAPI.AbstractRegister}
Expand Down