-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding base linear nonclassicality function and test
- Loading branch information
1 parent
9c02c67
commit 510a860
Showing
4 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
linear_nonclassicality_witness( | ||
vertices :: Vector{Vector{T}} where T <: Real, | ||
test_behavior :: Vector{<:Real}; | ||
verbose=false :: Bool | ||
) :: Vector{Float64} | ||
Implements a linear program that obtains a linear inequality that witnesses the nonclassciality of | ||
the provided `test_behavior` (see https://arxiv.org/abs/1303.2849 Eq. 19). A complete set of | ||
enumerated vertices are required as input. The optimized facet inequality is returned in vector | ||
form with the classical bound being appended to the end. | ||
""" | ||
function linear_nonclassicality_witness( | ||
vertices :: Vector{Vector{T}} where T <: Real, | ||
test_behavior :: Vector{<:Real}; | ||
verbose=false :: Bool | ||
) :: Vector{Float64} | ||
dim_v = length(vertices[1]) + 1 | ||
|
||
# initializing model | ||
model = Model(HiGHS.Optimizer) | ||
set_attribute(model, MOI.Silent(), !verbose) | ||
|
||
# adding variable for inequality | ||
@variable(model, s[1:dim_v]) | ||
|
||
# adding constraints to model | ||
for v in vertices | ||
va = [v..., -1] | ||
@constraint(model, sum(s.*va) <= 0) | ||
end | ||
|
||
@constraint(model, c, sum(s.*[test_behavior..., -1]) <= 1) | ||
|
||
# defining the optimization objective | ||
@objective(model, Max, sum(s.*[test_behavior..., -1])) | ||
|
||
# optimizing | ||
optimize!(model) | ||
|
||
# return optimized linear inequality in vector form | ||
return value.(s) | ||
end |
50 changes: 50 additions & 0 deletions
50
test/unit/LocalPolytope/linear_nonclassicality_witnesses.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Test | ||
|
||
@testset "./src/LocalPolytope/linear_nonclassicality_witnesses.jl" begin | ||
|
||
using BellScenario | ||
|
||
@testset "linear_nonclassicality_witness" begin | ||
@testset "CHSH Inequality Correlation Vertices" begin | ||
|
||
chsh_correlation_vertices = [ | ||
[-1, -1, -1, -1, 1, 1, 1, 1], | ||
[-1, -1, -1, 1, 1, -1, 1, -1], | ||
[-1, -1, 1, -1, -1, 1, -1, 1], | ||
[-1, -1, 1, 1, -1, -1, -1, -1], | ||
[-1, 1, -1, -1, 1, 1, -1, -1], | ||
[-1, 1, -1, 1, 1, -1, -1, 1], | ||
[-1, 1, 1, -1, -1, 1, 1, -1], | ||
[-1, 1, 1, 1, -1, -1, 1, 1], | ||
[ 1, -1, -1, -1, -1, -1, 1, 1], | ||
[ 1, -1, -1, 1, -1, 1, 1, -1], | ||
[ 1, -1, 1, -1, 1, -1, -1, 1], | ||
[ 1, -1, 1, 1, 1, 1, -1, -1], | ||
[ 1, 1, -1, -1, -1, -1, -1, -1], | ||
[ 1, 1, -1, 1, -1, 1, -1, 1], | ||
[ 1, 1, 1, -1, 1, -1, 1, -1], | ||
[ 1, 1, 1, 1, 1, 1, 1, 1], | ||
] | ||
|
||
pr_box_test_behavior = [0, 0, 0, 0, 1, 1, 1, -1] | ||
|
||
facet_vec = LocalPolytope.linear_nonclassicality_witness(chsh_correlation_vertices, pr_box_test_behavior[:]) | ||
|
||
@test facet_vec ≈ [0, 0, 0, 0, 0.5, 0.5, 0.5, -0.5, 1] # [A0, A1, B0, B1, AB00, AB01, AB10, AB11] | ||
end | ||
|
||
@testset "CH Inequality Probability Vertices" begin | ||
chsh_scenario = BipartiteNonSignaling(2, 2, 2, 2) | ||
|
||
chsh_vertices = LocalPolytope.vertices(chsh_scenario, "non-signaling") | ||
|
||
pr_box_test_behavior = [1, 1, 1, 1, 1, 1, 1, 0] / 2 | ||
|
||
facet_vec = LocalPolytope.linear_nonclassicality_witness(chsh_vertices, pr_box_test_behavior[:]) | ||
|
||
# -2*PA(0|0) - 2*PB(0|0) + 2*PAB(00|00) + 2*PAB(01|00) + 2*PAB(10|00) - 2*PAB(11|00) <= 0 | ||
@test facet_vec ≈ [-2, 0, -2, 0, 2, 2, 2, -2, 0] | ||
end | ||
end | ||
|
||
end |