Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
araujoms committed Dec 29, 2024
1 parent 750ff5e commit 57ee9f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ incompatibility_robustness_generalized
chsh
cglmp
inn22
gyni
local_bound
tsirelson_bound
seesaw
Expand Down
44 changes: 22 additions & 22 deletions src/nonlocal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ function tensor_collinsgisin(p::AbstractArray{T, N2}, behaviour::Bool = false) w
CG = zeros(T, ins .* (outs .- 1) .+ 1)

if ~behaviour
for invec in CartesianIndices(ins)
for outvec in CartesianIndices(outs)
for outvec2 in Iterators.product(union.(outvec.I, outs)...)
ndiff = abs(sum(outvec.I .!= outs) - sum(outvec2 .!= outs))
CG[cgindex(outvec.I, invec.I)...] += (-1)^ndiff * p[outvec2..., invec]
for x in CartesianIndices(ins)
for a in CartesianIndices(outs)
for a2 in Iterators.product(union.(a.I, outs)...)
ndiff = abs(sum(a.I .!= outs) - sum(a2 .!= outs))
CG[cgindex(a.I, x.I)...] += (-1)^ndiff * p[a2..., x]
end
end
end
else
for invec in CartesianIndices(ins)
for outvec in CartesianIndices(outs)
cgiterators = map((a, b) -> a == b ? (1:b) : (a:a), outvec.I, outs)
for outvec2 in Iterators.product(cgiterators...)
CG[cgindex(outvec.I, invec.I)...] += p[outvec2..., invec] / prod(ins[BitVector(outvec.I .== outs)])
for x in CartesianIndices(ins)
for a in CartesianIndices(outs)
cgiterators = map((i, j) -> i == j ? (1:j) : (i:i), a.I, outs)
for a2 in Iterators.product(cgiterators...)
CG[cgindex(a.I, x.I)...] += p[a2..., x] / prod(ins[BitVector(a.I .== outs)])
end
end
end
Expand All @@ -160,25 +160,25 @@ If `behaviour` is `true` do instead the transformation for behaviours. Doesn't a
"""
function tensor_probability(CG::AbstractArray{T, N}, scenario::AbstractVecOrTuple{<:Integer}, behaviour::Bool = false) where {T, N}
p = zeros(T, scenario...)
outs = scenario[1:N]
ins = scenario[(N + 1):(2 * N)]
outs = Tuple(scenario[1:N])
ins = Tuple(scenario[(N + 1):(2 * N)])
cgindex(a, x) = (a .!= outs) .* (a .+ (x .- 1) .* (outs .- 1)) .+ 1

if ~behaviour
for invec in CartesianIndices(ins)
for outvec in CartesianIndices(outs)
for outvec2 in Iterators.product(union.(outvec.I, outs)...)
p[outvec, invec] += CG[cgindex(outvec2, invec.I)...] / prod(ins[BitVector(outvec2 .== outs)])
for x in CartesianIndices(ins)
for a in CartesianIndices(outs)
for a2 in Iterators.product(union.(a.I, outs)...)
p[a, x] += CG[cgindex(a2, x.I)...] / prod(ins[BitVector(a2 .== outs)])
end
end
end
else
for invec in CartesianIndices(ins)
for outvec in CartesianIndices(outs)
cgiterators = map((a, b) -> a == b ? (1:b) : (a:a), outvec.I, outs)
for outvec2 in Iterators.product(cgiterators...)
ndiff = abs(sum(outvec.I .!= outs) - sum(outvec2 .!= outs))
p[outvec, invec] += (-1)^ndiff * CG[cgindex(outvec2, invec.I)...]
for x in CartesianIndices(ins)
for a in CartesianIndices(outs)
cgiterators = map((i, j) -> i == j ? (1:j) : (i:i), a.I, outs)
for a2 in Iterators.product(cgiterators...)
ndiff = abs(sum(a.I .!= outs) - sum(a2 .!= outs))
p[a, x] += (-1)^ndiff * CG[cgindex(a2, x.I)...]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/tsirelson.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Upper bounds the Tsirelson bound of a multipartite Bell funcional `CG`, written
`level` is an integer or string determining the level of the NPA hierarchy.
"""
function tsirelson_bound(CG::Array{T, N}, scenario::AbstractVecOrTuple{<:Integer}, level; solver = Hypatia.Optimizer{_solver_type(T)}) where {T <: Number, N}
outs = scenario[1:N]
ins = scenario[(N + 1):(2 * N)]
outs = Tuple(scenario[1:N])
ins = Tuple(scenario[(N + 1):(2 * N)])
Π = [[QuantumNPA.projector(n, 1:(outs[n] - 1), 1:ins[n]) [QuantumNPA.Id for _ in 1:(outs[n] - 1)]] for n in 1:N]
cgindex(a, x) = (x .!= (ins .+ 1)) .* (a .+ (x .- 1) .* (outs .- 1)) .+ 1

Expand Down
2 changes: 1 addition & 1 deletion test/nonlocal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]
@test tsirelson_bound(tilted_chsh_fc, 3) 3.80128907501837942169727948014219026
gyni_cg = tensor_collinsgisin(gyni())
@test tsirelson_bound(gyni_cg, 2*ones(Int,6), 3) 0.25
@test tsirelson_bound(gyni_cg, 2*ones(Int,6), 3) 0.25 rtol = 1e-7
for T in [Float64, Double64, Float128, BigFloat]
@test eltype(chsh(T)) <: T
@test eltype(cglmp(T)) <: T
Expand Down

0 comments on commit 57ee9f4

Please sign in to comment.