{ "cells": [ { "cell_type": "markdown", "id": "f9e70ddb", "metadata": {}, "source": [ "In order to run this script, you need to have cvxpy installed for your python environment. The easiest way to do this is to run\n", "'pip install cvxpy'\n", "or\n", "'conda install cvxpy'\n", "if you use anaconda." ] }, { "cell_type": "code", "execution_count": 1, "id": "8a8366da", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import cvxpy as cp" ] }, { "cell_type": "markdown", "id": "a41da1b4", "metadata": {}, "source": [ "Run the following test SDP to check whether everything is working." ] }, { "cell_type": "code", "execution_count": 2, "id": "48159068", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The optimal value is 2.654348022627943\n", "A solution X is\n", "[[ 1.60807406 -0.59771741 -0.69576939]\n", " [-0.59771741 0.22229521 0.24691094]\n", " [-0.69576939 0.24691094 1.39682315]]\n" ] } ], "source": [ "# Generate a random SDP.\n", "n = 3\n", "p = 3\n", "np.random.seed(1)\n", "C = np.random.randn(n, n)\n", "A = []\n", "b = []\n", "for i in range(p):\n", " A.append(np.random.randn(n, n))\n", " b.append(np.random.randn())\n", "\n", "# Define and solve the CVXPY problem.\n", "# Create a symmetric matrix variable.\n", "X = cp.Variable((n,n), symmetric=True)\n", "# The operator >> denotes matrix inequality.\n", "constraints = [X >> 0]\n", "constraints += [\n", " cp.trace(A[i] @ X) == b[i] for i in range(p)\n", "]\n", "prob = cp.Problem(cp.Minimize(cp.trace(C @ X)),\n", " constraints)\n", "prob.solve()\n", "\n", "# Print result.\n", "print(\"The optimal value is\", prob.value)\n", "print(\"A solution X is\")\n", "print(X.value)" ] }, { "cell_type": "markdown", "id": "c501b1a1", "metadata": {}, "source": [ "If that did not give any errors, we can start making our own SDP to find the maximal violation of a Bell inequality that quantum physics can achieve. \n", "\n", "Classically, given binary measurements A0, A1 for Alice and B0, B1 for Bob, the following inequality, known as the CHSH inequality, holds" ] }, { "cell_type": "raw", "id": "598f2411", "metadata": {}, "source": [ " + + - <= 2." ] }, { "cell_type": "markdown", "id": "153cf442", "metadata": {}, "source": [ "We will use the moment matrix formalism to give an upper bound for this inequality in the case of quantum observables. First, we will index the rows and columns in terms of the binary measurements (and the identity), ordered as (Id, A0, A1, B0, B1). This gives a moment matrix of the form" ] }, { "cell_type": "raw", "id": "5a86c4bd", "metadata": {}, "source": [ " \n", " \n", "M = \n", " \n", " " ] }, { "cell_type": "markdown", "id": "1153d990", "metadata": {}, "source": [ "This matrix M should be positive semidefinite and symmetric. We can choose it to be real as well without loss of generality. Let's see how far we get with just that information." ] }, { "cell_type": "markdown", "id": "f598bca1", "metadata": {}, "source": [ "Create a variable M that is a real, symmetric 5x5 matrix." ] }, { "cell_type": "code", "execution_count": null, "id": "e4d63008", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "6318db98", "metadata": {}, "source": [ "Create the constraints on M. Recall that the expectation values are supposed to be with respect to a quantum state." ] }, { "cell_type": "code", "execution_count": null, "id": "e45d5289", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "5c6cff58", "metadata": {}, "source": [ "Create the SDP problem and solve it. Extract the solution and the variable if possible." ] }, { "cell_type": "code", "execution_count": null, "id": "18f548f6", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "6928e109", "metadata": {}, "source": [ "Oops... The problem is unbounded. We need to add more information. Luckily there are more constraints to add: The variables are binary. What does that imply for e.g. ?\n", "Try running the SDP again with these additional constraints." ] }, { "cell_type": "code", "execution_count": null, "id": "241dca3d", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "f11af01b", "metadata": {}, "source": [ "With some guess work, we can actually find a pretty good quantum solution that breaks the inequality. This is done by choosing A0 = Z, A1 = X, B0 = (X + Z)/sqrt(2), B1 = (X - Z)/sqrt(2), and taking the expectation value with respect to the antisymmetric Bell state" ] }, { "cell_type": "raw", "id": "95e877c6", "metadata": {}, "source": [ "|psi> = ( |01> - |10> ) / sqrt(2)" ] }, { "cell_type": "markdown", "id": "5e0896bc", "metadata": {}, "source": [ "What is the value you get for the CHSH expression? Compare it to the optimal value you got from the SDP. How well did we do?" ] }, { "cell_type": "code", "execution_count": null, "id": "598dd0c5", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.13" } }, "nbformat": 4, "nbformat_minor": 5 }