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
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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
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
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |