Skip to content

Commit cbba92e

Browse files
committed
Demo code successfully picks up postquantumness of 2-outcome example
1 parent 64f3cd1 commit cbba92e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from sympy import sqrt, simplify, binomial, radsimp
2+
from functools import cache
3+
4+
u=sqrt(5+4*sqrt(2))
5+
term_1 = simplify(2/(u-1))
6+
term_2 = simplify(-2/(u+1))
7+
8+
@cache
9+
def expec_line(n: int) -> float:
10+
return simplify(radsimp((term_1**(n-1)-term_2**(n-1)) / u))
11+
@cache
12+
def expec_loop(n: int) -> float:
13+
if n==1:
14+
return 0
15+
else:
16+
return simplify(term_1**(n)+term_2**(n))
17+
18+
def prob_line_s(n: int) -> float:
19+
return sum(binomial(n, k)*expec_line(k) for k in range(0,n+1))/(2**n)
20+
def prob_loop_s(n: int) -> float:
21+
return sum((binomial(n, k) * (expec_line(k) if k<n else expec_loop(n))) for k in range(0, n + 1))/(2**n)
22+
def prob_line(n: int) -> float:
23+
return float(prob_line_s(n))
24+
def prob_loop(n: int) -> float:
25+
return float(prob_loop_s(n))
26+
27+
28+
29+
if __name__ == '__main__':
30+
print([prob_line(n) for n in range(1, 10)])
31+
print([prob_loop(n) for n in range(1, 10)])
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from inflation import InflationProblem, InflationSDP
2+
import numpy as np
3+
4+
5+
def ring_problem(inflation_level: int, nof_outcomes: int = 2) -> InflationProblem:
6+
inf_prob = InflationProblem(
7+
dag={"i1": ["A"],
8+
"i2": ["A"], },
9+
outcomes_per_party=(nof_outcomes,),
10+
settings_per_party=(1,),
11+
classical_sources=None,
12+
inflation_level_per_source=(inflation_level,inflation_level),
13+
order=["A"],
14+
really_just_one_source=True)
15+
return inf_prob
16+
17+
18+
prob = ring_problem(4, 2)
19+
prob.add_symmetries(prob._setting_specific_outcome_relabelling_symmetries)
20+
21+
from postquantum_2outcomes import prob_line, prob_loop
22+
23+
ring_SDP = InflationSDP(prob, verbose=2, include_all_outcomes=False)
24+
ring_SDP.generate_relaxation("physical2")
25+
26+
print("Quantum inflation **nonfanout/commuting** factors:")
27+
print(ring_SDP.physical_atoms)
28+
29+
values={
30+
'P[A^{1,1}=0]': prob_loop(1),
31+
'P[A^{1,2}=0]': prob_line(1),
32+
'P[A^{1,2}=0 A^{2,1}=0]': prob_loop(2),
33+
'P[A^{1,2}=0 A^{2,3}=0]': prob_line(2),
34+
'P[A^{1,2}=0 A^{2,3}=0 A^{3,1}=0]': prob_loop(3),
35+
'P[A^{1,2}=0 A^{2,3}=0 A^{3,4}=0]': prob_line(3),
36+
'P[A^{1,2}=0 A^{2,3}=0 A^{3,4}=0 A^{4,1}=0]': prob_loop(4)
37+
}
38+
ring_SDP.update_values(values=values, only_specified_values=False)
39+
print(ring_SDP.known_moments)
40+
41+
ring_SDP.solve(solve_dual=False)
42+
print(ring_SDP.status)
43+

0 commit comments

Comments
 (0)