-
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.
Merge pull request #20 from ChitambarLab/v0-1-3
V0.1.3
- Loading branch information
Showing
17 changed files
with
201 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ docs/Manifest.toml | |
|
||
porta_tmp | ||
porta.log | ||
Highs.log |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
[deps] | ||
BellScenario = "4e58fcc1-4405-48af-b0f2-42df636d9190" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
QBase = "e52e8ede-12bf-4731-8af7-b01f6064cb11" | ||
XPORTA = "8c143463-af6f-456f-8aed-72447cb569d2" | ||
|
||
[compat] | ||
Documenter = "0.25.5" | ||
Documenter = "1" |
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
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,76 @@ | ||
""" | ||
linear_nonclassicality_witness( | ||
vertices :: Vector{Vector{T}} where T <: Real, | ||
test_behavior :: Vector{<:Real}; | ||
verbose=false :: Bool | ||
) :: Vector{Float64} | ||
Obtains a linear inequality ``(\\mathbf{G}^\\star, \\beta^\\star)`` bounding the convex hull of the | ||
set of `vertices` (``\\mathcal{V}``) and is violated by the `test_behavior` ``(\\mathbf{P}\\notin \\text{Conv}(\\mathcal{V}))``. | ||
This task is achieved using the linear program described by Brunner et al. in Eq. 19 of | ||
[https://arxiv.org/abs/1303.2849](https://arxiv.org/abs/1303.2849). The linear program is | ||
```math | ||
\\begin{align} | ||
\\min_{(\\mathbf{G}, \\beta)} \\quad & \\langle \\mathbf{G},\\mathbf{P}\\rangle - \\beta & \\notag\\\\ | ||
\\text{s.t.} \\quad & \\langle \\mathbf{G}, \\mathbf{V} \\rangle - \\beta \\leq 0 & \\quad \\forall \\;\\; \\mathbf{V} \\in \\mathcal{V} \\notag\\\\ | ||
& \\langle \\mathbf{G}, \\mathbf{P} \\rangle \\leq 1 & \\notag\\\\ | ||
\\end{align} | ||
``` | ||
The solution to the linear program is a linear nonclassicality witness ``(\\mathbf{G}^\\star, \\beta^\\star)`` becuase the | ||
constraint ``\\lange\\mathbf{G}^\\star, \\mathbf{V} \\rangle - \\beta^\\star \\leq 0`` ensures that no behavior in the polytope | ||
``\\text{Conv}(\\mathcal{V})`` can violate the inequality. Provided that ``\\mathbf{P} \\notin \\text{Conv}(\\mathcal{V})`` | ||
technique the output linear inequality witnesses the nonclassicality of the `test_behavior`. | ||
The optimized facet inequality ``(\\mathbf{G}^\\star, \\beta^\\star)`` is returned as a vector ``(G^\\star_{0,0}, \\dots, G^\\star_{Y,X}, -\\beta^\\star)`` | ||
where ``G^\\star_{y,x}`` are the elements of ``\\mathbf{G}^\\star``. | ||
!!! note "Supporting Software" | ||
The linear programming is performed using [HiGHS](https://highs.dev/) | ||
solver via the [`JuMP`](https://jump.dev/JuMP.jl/stable/) | ||
interface. Please refer to the source code for more details. | ||
!!! note "Converting Output into Bell Game" | ||
The linear programming software outputs numerical values that have numerical error. Moreover, the linear inequality is | ||
scaled such that the classical bound is zero and the `test_behavior` score is one. In order to convert the output | ||
inequality into a `BellGame`, care must be taken to obtain the correct scaling factor to ensure that elements are integers. | ||
!!! note "Classical Test Behavior" | ||
If the `test_behavior` ``\\mathbf{P}`` is classical, meaning it satisfies ``\\mathbf{P}\\in\\text{Conv}(\\mathcal{V})``, | ||
then the zero vector is returned as the optimal solution. Note that if all elements of ``\\mathbf{G}^\\star`` | ||
satisfy ``G^\\star_{y,x}=0``, then all behaviors ``\\mathbf{P} \\in \\text{Conv}(\\mathcal{V})`` are trivially optimal | ||
as ``\\langle\\mathbf{G}^{\\star}, \\mathbf{P} \\rangle - \\beta^\\star \\leq 0``. | ||
""" | ||
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 |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using Test, Polyhedra | ||
using Test, XPORTA | ||
|
||
@testset "./src/LocalPolytope/facets.jl" begin | ||
|
||
|
53 changes: 53 additions & 0 deletions
53
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,53 @@ | ||
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 # nonlocal test behavior | ||
local_test_behavior = [1/2, 1/2, 1/2, 1/2, 1/4, 1/4, 1/4, 1/4] # white noise behavior | ||
|
||
chsh_facet_vec = LocalPolytope.linear_nonclassicality_witness(chsh_vertices, pr_box_test_behavior[:]) | ||
local_game_vec = LocalPolytope.linear_nonclassicality_witness(chsh_vertices, local_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 chsh_facet_vec ≈ [-2, 0, -2, 0, 2, 2, 2, -2, 0] | ||
@test local_game_vec ≈ [0, 0, 0, 0, 0, 0, 0, 0, 0] # zero vector returned as optimal solution. | ||
end | ||
end | ||
|
||
end |
Oops, something went wrong.
8561043
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
8561043
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/96621
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: