*This post is available as an IPython notebook.*

The Tsirelson bound on the Clauser-Horne-Shimony-Holt inequality defines the maximum value on quantum correlations in a bipartite system where the two sites have two measurements each, with two possible outcomes [1].

The problem of finding the maximum quantum violation can be cast as a polynomial optimization problem of noncommuting variables, which in turn is approximated by a hierarchy of semidefinite programming (SDP) relaxations [2]. The probabilities are described by projection operators over normalized states -- we label the projectors by . They pairwise belong to measurements , where and are on one site of the system, and and are on the other site. Hence, for instance, , , and so on. The optimization problem becomes

subject to

We use the latest git version of Ncpol2sdpa to translate the polynomial optimization problem to an SDP [3], and then we solve it with SDPA. To begin with, we import the necessary functions from Ncpol2sdpa:

```
from ncpol2sdpa import generate_variables, SdpRelaxation, solve_sdp,\
projective_measurement_constraints
```

We cast the problem in the form of expectation values to get the familiar value of the maximum violation, . This requires defining a helper function to generate the expectation values given the projectors and the outcomes:

```
def expectation_values(M, outcomes):
exp_values = []
for k in range(len(M)):
exp_value = 0
for i in range(len(M[k])):
exp_value += outcomes[k][i]*M[k][i]
exp_values.append(exp_value)
return exp_values
```

The total number of variables is 8 ( ). We generate the necessary number of Hermitian variables and divide them into the appropriate measurements:

```
n_vars = 8
E = generate_variables(n_vars, name='E', hermitian=True)
M, outcomes = [], []
for i in range(n_vars/2):
M.append([E[2*i], E[2*i+1]])
outcomes.append([1, -1])
A = [M[0], M[1]]
B = [M[2], M[3]]
```

Ncpol2sdpa has a built-in function to generate the constraints for projective measurements. With that, we define the constraints of the optimization problem:

```
inequalities= []
monomial_substitutions, equalities = projective_measurement_constraints(A, B)
```

The objective function uses the expectation values. We have to take the negative of it, as the SDP solver can only minimize a function. The objective for the maximum violation thus becomes:

```
C = expectation_values(M, outcomes)
objective = -(C[0]*C[2] + C[0]*C[3] + C[1]*C[2] - C[1]*C[3])
```

Setting the relaxation level to one, the solution already converges:

```
level = 1
sdpRelaxation = SdpRelaxation(E, verbose=2)
sdpRelaxation.get_relaxation(objective, inequalities, equalities,
monomial_substitutions, level)
print solve_sdp(sdpRelaxation)
```

**References**

[1] Clauser, J. F.; Horne, M. A.; Shimony, A. & Holt, R. A. Proposed Experiment to Test Local Hidden-Variable Theories. *Physical Review Letters*, 1969, 23, 880-884.

[2] Navascués, M.; Pironio, S. & Acín, A. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. *New Journal of Physics*, 2008, 10, 073013.

[3] Wittek, P. Ncpol2sdpa -- Sparse Semidefinite Programming Relaxations for Polynomial Optimization Problems of Noncommuting Variables. *arXiv:1308.6029*, 2013.