From df43616f7440c99dacce9831d1dd9ce6252ecdbd Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Sun, 15 Oct 2023 20:16:55 -0500 Subject: [PATCH 1/6] xor_game errors --- toqito/nonlocal_games/xor_game.py | 70 +++++++++++++++---------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/toqito/nonlocal_games/xor_game.py b/toqito/nonlocal_games/xor_game.py index f2e570302..4253a145b 100644 --- a/toqito/nonlocal_games/xor_game.py +++ b/toqito/nonlocal_games/xor_game.py @@ -150,7 +150,7 @@ def __init__( q_0, q_1 = self.prob_mat.shape if tol is None: - self.tol = np.finfo(float).eps * q_0 ** 2 * q_1 ** 2 + self.tol = np.finfo(float).eps * q_0**2 * q_1**2 else: self.tol = tol @@ -175,45 +175,44 @@ def __init__( def quantum_value(self) -> float: r""" - Compute the quantum value of the XOR game. - - To obtain the quantum value of the XOR game, we calculate the following - simplified dual problem of the semidefinite program from the set of - notes: https://cs.uwaterloo.ca/~watrous/CS867.Winter2017/Notes/06.pdf - - .. math:: - \begin{equation} - \begin{aligned} - \text{minimize:} \quad & \frac{1}{2} \sum_{x \in X} u(x) + - \frac{1}{2} \sum_{y \in Y} v(y) \\ - \text{subject to:} \quad & - \begin{pmatrix} - \text{Diag}(u) & -D \\ - -D^* & \text{Diag}(v) - \end{pmatrix} \geq 0, \\ - & u \in \mathbb{R}^X, \ - v \in \mathbb{R}^Y. - \end{aligned} - \end{equation} - - where :math:`D` is the matrix defined to be - - .. math:: - D(x,y) = \pi(x, y) (-1)^{f(x,y)} - - In other words, :math:`\pi(x, y)` corresponds to :code:`prob_mat[x, y]`, - and :math:`f(x,y)` corresponds to :code:`pred_mat[x, y]`. - - :return: A value between [0, 1] representing the quantum value. - """ + Compute the quantum value of the XOR game. + + To obtain the quantum value of the XOR game, we calculate the following + simplified dual problem of the semidefinite program from the set of + notes: https://cs.uwaterloo.ca/~watrous/CS867.Winter2017/Notes/06.pdf + + .. math:: + \begin{equation} + \begin{aligned} + \text{minimize:} \quad & \frac{1}{2} \sum_{x \in X} u(x) + + \frac{1}{2} \sum_{y \in Y} v(y) \\ + \text{subject to:} \quad & + \begin{pmatrix} + \text{Diag}(u) & -D \\ + -D^* & \text{Diag}(v) + \end{pmatrix} \geq 0, \\ + & u \in \mathbb{R}^X, \ + v \in \mathbb{R}^Y. + \end{aligned} + \end{equation} + + where :math:`D` is the matrix defined to be + + .. math:: + D(x,y) = \pi(x, y) (-1)^{f(x,y)} + + In other words, :math:`\pi(x, y)` corresponds to :code:`prob_mat[x, y]`, + and :math:`f(x,y)` corresponds to :code:`pred_mat[x, y]`. + + :return: A value between [0, 1] representing the quantum value. + """ alice_in, bob_in = self.prob_mat.shape d_mat = np.zeros([alice_in, bob_in]) for x_alice in range(alice_in): for y_bob in range(bob_in): - d_mat[x_alice, y_bob] = self.prob_mat[x_alice, y_bob] * (-1) ** ( - self.pred_mat[x_alice, y_bob] - ) + d_mat[x_alice, y_bob] = self.prob_mat[x_alice, y_bob] * \ + (-1) ** (self.pred_mat[x_alice, y_bob]) u_vec = cvxpy.Variable(alice_in, complex=False) v_vec = cvxpy.Variable(bob_in, complex=False) @@ -247,7 +246,6 @@ def classical_value(self) -> float: :return: A value between [0, 1] representing the classical value. """ - return self.to_nonlocal_game().classical_value() def nonsignaling_value(self) -> float: From f5b110779810eb8930971b9d763166fe6dea8bd5 Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Sun, 15 Oct 2023 20:17:11 -0500 Subject: [PATCH 2/6] completely_bounded trace_norm errors --- toqito/channel_metrics/completely_bounded_trace_norm.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toqito/channel_metrics/completely_bounded_trace_norm.py b/toqito/channel_metrics/completely_bounded_trace_norm.py index 07cf018e2..a2d54a6ed 100644 --- a/toqito/channel_metrics/completely_bounded_trace_norm.py +++ b/toqito/channel_metrics/completely_bounded_trace_norm.py @@ -9,8 +9,10 @@ def completely_bounded_trace_norm(phi: np.ndarray) -> float: r""" - Compute the completely bounded trace norm / diamond norm of a quantum - channel [WatCNorm18]_. The algorithm in p.11 of [WatSDP09] with + Find the completely bounded trace norm of a quantum channel. + + Also known as the completely bounded diamond norm of a quantum + channel[WatCNorm18]_. The algorithm in p.11 of [WatSDP09] with implementation in QETLAB [JohQET] is used. References From 7dd8ab31246803c87f34c786f2e9c8bfaa4f2c62 Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Sun, 15 Oct 2023 20:31:50 -0500 Subject: [PATCH 3/6] matrix_ops errors --- toqito/matrix_ops/inner_product.py | 3 +-- toqito/matrix_ops/outer_product.py | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/toqito/matrix_ops/inner_product.py b/toqito/matrix_ops/inner_product.py index 0b246eb64..7929e84a7 100644 --- a/toqito/matrix_ops/inner_product.py +++ b/toqito/matrix_ops/inner_product.py @@ -1,4 +1,4 @@ -"""Inner product operation""" +"""Inner product operation.""" import numpy as np @@ -36,7 +36,6 @@ def inner_product(v1: np.ndarray, v2: np.ndarray) -> float: :param args: v1 and v2, both vectors of dimenstions :math:`(n,1)` where :math:`n>1`. :return: The computed inner product. """ - # Check for dimensional validity if not (v1.shape[0] == v2.shape[0] and v1.shape[0] > 1 and len(v1.shape) == 1): raise ValueError("Dimension mismatch") diff --git a/toqito/matrix_ops/outer_product.py b/toqito/matrix_ops/outer_product.py index 7609a8111..65521f0fe 100644 --- a/toqito/matrix_ops/outer_product.py +++ b/toqito/matrix_ops/outer_product.py @@ -1,13 +1,12 @@ -"""Outer product operation""" +"""Outer product operation.""" import numpy as np def outer_product(v1: np.ndarray, v2: np.ndarray) -> np.ndarray: r""" Compute the outer product :math:`|v_1\rangle\langle v_2|` of two vectors. - [WikOuter]_ - The outer product is calculated as follows: + The outer product is calculated as follows [WikOuter]_: .. math:: \left|\begin{pmatrix}a_1\\\vdots\\a_n\end{pmatrix}\right\rangle\left\langle\begin{pmatrix}b_1\\\vdots\\b_n\end{pmatrix}\right|=\begin{pmatrix}a_1\\\vdots\\a_n\end{pmatrix}\begin{pmatrix}b_1&\cdots&b_n\end{pmatrix}=\begin{pmatrix}a_1b_1&\cdots&a_1b_n\\\vdots&\ddots&\vdots\\a_1b_n&\cdots&a_nb_n\end{pmatrix} @@ -34,10 +33,11 @@ def outer_product(v1: np.ndarray, v2: np.ndarray) -> np.ndarray: ========== .. [WikOuter] Wikipedia: Outer Product https://en.wikipedia.org/wiki/Outer_product - + :raises ValueError: Vector dimensions are mismatched. :param args: v1 and v2, both vectors of dimensions :math:`(n,1)` where :math:`n>1`. - :return: The computed outer product.""" + :return: The computed outer product. + """ # Check for dimensional validity if not (v1.shape[0] == v2.shape[0] and v1.shape[0] > 1 and len(v1.shape) == 1): raise ValueError("Dimension mismatch") From 37c69b6652b3a0970803402d1f4571266cb6ce5a Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Sun, 15 Oct 2023 20:39:13 -0500 Subject: [PATCH 4/6] matrix_props --- toqito/matrix_props/is_diagonally_dominant.py | 56 +++++++++---------- toqito/matrix_props/trace_norm.py | 5 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/toqito/matrix_props/is_diagonally_dominant.py b/toqito/matrix_props/is_diagonally_dominant.py index 120053408..1312ec2ae 100644 --- a/toqito/matrix_props/is_diagonally_dominant.py +++ b/toqito/matrix_props/is_diagonally_dominant.py @@ -5,16 +5,16 @@ def is_diagonally_dominant(mat: np.ndarray, is_strict: bool = True) -> bool: r""" - Check if matrix is diagnal dominant (DD) [WikDD]_. + Check if matrix is diagnal dominant (DD) [WikDD]_. - A matrix is diagonally dominant if the matrix is square - and if for every row of the matrix, the magnitude of the diagonal entry in a row is greater - than or equal to the sum of the magnitudes of all the other (non-diagonal) entries in that row. + A matrix is diagonally dominant if the matrix is square + and if for every row of the matrix, the magnitude of the diagonal entry in a row is greater + than or equal to the sum of the magnitudes of all the other (non-diagonal) entries in that row. - Examples - ========== + Examples + ========== - The following is an example of a 3-by-3 diagonal matrix: + The following is an example of a 3-by-3 diagonal matrix: .. math:: A = \begin{pmatrix} @@ -23,15 +23,15 @@ def is_diagonally_dominant(mat: np.ndarray, is_strict: bool = True) -> bool: 0 & -1 & 2 \end{pmatrix} - our function indicates that this is indeed a diagonally dominant matrix. + our function indicates that this is indeed a diagonally dominant matrix. - >>> from toqito.matrix_props import is_diagonally_dominant - >>> import numpy as np - >>> A = np.array([[2, -1, 0], [0, 2, -1], [0, -1, 2]]) - >>> is_diagonally_dominant(A) - True + >>> from toqito.matrix_props import is_diagonally_dominant + >>> import numpy as np + >>> A = np.array([[2, -1, 0], [0, 2, -1], [0, -1, 2]]) + >>> is_diagonally_dominant(A) + True - Alternatively, the following example matrix :math:`B` defined as + Alternatively, the following example matrix :math:`B` defined as .. math:: B = \begin{pmatrix} @@ -39,23 +39,23 @@ def is_diagonally_dominant(mat: np.ndarray, is_strict: bool = True) -> bool: -1 & -1 \end{pmatrix} - is not diagonally dominant. + is not diagonally dominant. - >>> from toqito.matrix_props import is_diagonally_dominant - >>> import numpy as np - >>> B = np.array([[-1, 2], [-1, -1]]) - >>> is_diagonally_dominant(B) - False + >>> from toqito.matrix_props import is_diagonally_dominant + >>> import numpy as np + >>> B = np.array([[-1, 2], [-1, -1]]) + >>> is_diagonally_dominant(B) + False - References - ========== - .. [WikDD] Wikipedia: Diagonally dominant matrix. - https://en.wikipedia.org/wiki/Diagonally_dominant_matrix + References + ========== + .. [WikDD] Wikipedia: Diagonally dominant matrix. + https://en.wikipedia.org/wiki/Diagonally_dominant_matrix - :param mat: Matrix to check. - :param is_strict: Whether the inequality is strict. - :return: Return :code:`True` if matrix is diagnally dominant, and :code:`False` otherwise. - """ + :param mat: Matrix to check. + :param is_strict: Whether the inequality is strict. + :return: Return :code:`True` if matrix is diagnally dominant, and :code:`False` otherwise. + """ if not is_square(mat): return False diff --git a/toqito/matrix_props/trace_norm.py b/toqito/matrix_props/trace_norm.py index 97609145c..df7443f4e 100644 --- a/toqito/matrix_props/trace_norm.py +++ b/toqito/matrix_props/trace_norm.py @@ -4,8 +4,9 @@ def trace_norm(rho: np.ndarray) -> float: r""" - Compute the trace norm of the state [WikTn]_ - as well as the operator 1-norm when inputting an operator. + Compute the trace norm of the state [WikTn]_. + + Also computes the operator 1-norm when inputting an operator. The trace norm :math:`||\rho||_1` of a density matrix :math:`\rho` is the sum of the singular values of :math:`\rho`. The singular values are the roots of the eigenvalues of From 03e25c763a44483d6407381adeb940bcc5df8460 Mon Sep 17 00:00:00 2001 From: Purva Thakre Date: Sun, 15 Oct 2023 20:40:17 -0500 Subject: [PATCH 5/6] state_opt --- toqito/state_opt/state_exclusion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toqito/state_opt/state_exclusion.py b/toqito/state_opt/state_exclusion.py index 0be066087..e45b663a7 100644 --- a/toqito/state_opt/state_exclusion.py +++ b/toqito/state_opt/state_exclusion.py @@ -98,7 +98,7 @@ def state_exclusion( def _min_error_primal(vectors: list[np.ndarray], probs: list[float] = None, solver: str = "cvxopt"): - """The primal problem for minimum-error quantum state exclusion SDP.""" + """Find the primal problem for minimum-error quantum state exclusion SDP.""" n, dim = len(vectors), vectors[0].shape[0] if probs is None: probs = [1 / len(vectors)] * len(vectors) @@ -125,7 +125,7 @@ def _min_error_primal(vectors: list[np.ndarray], probs: list[float] = None, solv def _min_error_dual( vectors: list[np.ndarray], probs: list[float] = None, solver: str = "cvxopt" ) -> float: - """The dual problem for minimum-error quantum state exclusion SDP.""" + """Find the dual problem for minimum-error quantum state exclusion SDP.""" dim = vectors[0].shape[0] if probs is None: probs = [1 / len(vectors)] * len(vectors) From 4155796f8e56c6b59b72e6ef71c07f5a17297a74 Mon Sep 17 00:00:00 2001 From: Purva Thakre <66048318+purva-thakre@users.noreply.github.com> Date: Sun, 15 Oct 2023 20:56:25 -0500 Subject: [PATCH 6/6] Update toqito/channel_metrics/completely_bounded_trace_norm.py --- toqito/channel_metrics/completely_bounded_trace_norm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toqito/channel_metrics/completely_bounded_trace_norm.py b/toqito/channel_metrics/completely_bounded_trace_norm.py index a2d54a6ed..77eb4e4ee 100644 --- a/toqito/channel_metrics/completely_bounded_trace_norm.py +++ b/toqito/channel_metrics/completely_bounded_trace_norm.py @@ -12,7 +12,7 @@ def completely_bounded_trace_norm(phi: np.ndarray) -> float: Find the completely bounded trace norm of a quantum channel. Also known as the completely bounded diamond norm of a quantum - channel[WatCNorm18]_. The algorithm in p.11 of [WatSDP09] with + channel [WatCNorm18]_. The algorithm in p.11 of [WatSDP09] with implementation in QETLAB [JohQET] is used. References