npa_hierarchy
¶
Generates the NPA constraints.
npa_constraints
¶
npa_constraints(
assemblage: dict[tuple[int, int], Variable],
k: int | str = 1,
referee_dim: int = 1,
no_signaling: bool = True,
) -> list[Constraint]
Generate the constraints specified by the NPA hierarchy up to a finite level.
You can determine the level of the hierarchy by a positive integer or a string of a form like "1+ab+aab", which indicates that an intermediate level of the hierarchy should be used, where this example uses all products of 1 measurement, all products of one Alice and one Bob measurement, and all products of two Alice and one Bob measurement.
The commuting measurement assemblage operator must be given as a dictionary. The keys are tuples of Alice and Bob questions \(x, y\) and the values are cvxpy Variables which are matrices with entries:
Parameters:
-
assemblage(dict[tuple[int, int], Variable]) –The commuting measurement assemblage operator.
-
k(int | str, default:1) –The level of the NPA hierarchy to use (default=1).
-
referee_dim(int, default:1) –The dimension of the referee's quantum system (default=1).
-
no_signaling(bool, default:True) –bool
Returns:
-
list[Constraint]–A list of cvxpy constraints.
References
1 Navascués, Miguel and Pironio, Stefano and Acín, Antonio. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. New Journal of Physics. vol. 10(7). (2008). doi:10.1088/1367-2630/10/7/073013.
Source code in toqito/state_opt/npa_hierarchy.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
bell_npa_constraints
¶
Generate NPA hierarchy constraints for Bell inequalities 1.
The constraints are based on the positivity of a moment matrix constructed from measurement operators. This function generates constraints for a CVXPY variable representing probabilities or correlations in the Collins-Gisin notation. 2
The level of the hierarchy k can be an integer (standard NPA level) or a string specifying
intermediate levels (e.g., "1+ab", "2+aab").
The input p_var is a CVXPY variable representing the probabilities in the Collins-Gisin (CG)
notation. It should have dimensions \(((oa-1) \times ma+1, (ob-1) \times mb+1)\),
where \(oa, ob\) are the number of outputs and \(ma, mb\) are the number of inputs for Alice
and Bob, respectively, as specified in desc = [\(oa\), \(ob\), \(ma\), \(mb\)].
The entries of p_var correspond to:
- p_var[0, 0]: The overall probability (should be 1).
- p_var[i, 0] (for \(i > 0\)): Marginal probabilities/correlations for Alice.
- p_var[0, j] (for \(j > 0\)): Marginal probabilities/correlations for Bob.
- p_var[i, j] (for \(i > 0, j > 0\)): Joint probabilities/correlations for Alice and Bob.
The mapping from indices \((i, j)\) to specific operators depends on the ordering defined by desc.
Specifically, if \(i = (oa-1) \times x + a + 1\) and \(j = (ob-1) \times y + b + 1\)
p_var[i, 0]corresponds to the expectation of Alice's operator \(A_{a|x}\) (using \(0\) to \(oa-2\) for \(a\)).p_var[0, j]corresponds to the expectation of Bob's operator \(B_{b|y}\) (using \(0\) to \(ob-2\) for \(b\)).p_var[i, j]corresponds to the expectation of the product \(A_{a|x} B_{b|y}\).
Parameters:
-
p_var(Variable) –A CVXPY Variable representing probabilities/correlations in Collins-Gisin notation. Shape: \(((oa-1) \times ma+1, (ob-1) \times mb+1)\).
-
desc(list[int]) –A list [\(oa\), \(ob\), \(ma\), \(mb\)] specifying outputs and inputs for Alice and Bob.
-
k(int | str, default:1) –The level of the NPA hierarchy (integer or string like "1+ab"). Default is 1.
Returns:
-
list[Constraint]–A list of CVXPY constraints.
Raises:
-
ValueError–If internal identity mapping fails.
Examples:
Consider the CHSH inequality scenario with desc = [2, 2, 2, 2]. We want to generate the NPA level 1
constraints.
import cvxpy
import numpy as np
from toqito.state_opt.npa_hierarchy import bell_npa_constraints
desc = [2, 2, 2, 2]
oa, ob, ma, mb = desc
p_var_dim = ((oa - 1) * ma + 1, (ob - 1) * mb + 1)
p_var = cvxpy.Variable(p_var_dim, name="p_cg")
constraints = bell_npa_constraints(p_var, desc, k=1)
print(len(constraints))
print(constraints[0])
We can also use intermediate levels, like "1+ab":
constraints_1ab = bell_npa_constraints(p_var, desc, k="1+ab")
print(len(constraints_1ab))
print(constraints_1ab[0])
For the CGLMP inequality with dim=3, desc = [3, 3, 2, 2], level 1:
import cvxpy
import numpy as np
from toqito.state_opt.npa_hierarchy import bell_npa_constraints
desc_cglmp = [3, 3, 2, 2]
oa_c, ob_c, ma_c, mb_c = desc_cglmp
p_var_dim_c = ((oa_c - 1) * ma_c + 1, (ob_c - 1) * mb_c + 1)
p_var_c = cvxpy.Variable(p_var_dim_c, name="p_cglmp")
constraints_c = bell_npa_constraints(p_var_c, desc_cglmp, k=1)
print(len(constraints_c))
print(constraints_c[0])
References
1 Navascués, Miguel and Pironio, Stefano and Acín, Antonio. A convergent hierarchy of semidefinite programs characterizing the set of quantum correlations. New Journal of Physics. vol. 10(7). (2008). doi:10.1088/1367-2630/10/7/073013.
2 Collins, Daniel and Gisin, Nicolas. A relevant two qubit Bell inequality inequivalent to the CHSH inequality. Journal of Physics A: Mathematical and General. vol. 37(5). (2004). doi:10.1088/0305-4470/37/5/021.
Source code in toqito/state_opt/npa_hierarchy.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | |