Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions toqito/matrix_props/is_k_incoherent.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ def is_k_incoherent(mat: np.ndarray, k: int, rtol: float = 1e-05, atol: float =
elif k == 2:
return False

# [@johnston2022absolutely] (8): Check if the purity trace(mat mat^dagger) <= 1/(d - 1) (for k > 2). For a
# Hermitian density matrix this equals trace(mat^2); using the conjugate transpose keeps it correct (and real)
# for complex inputs.
if k > 2 and np.real(np.trace(mat @ mat.conj().T)) <= 1 / (d - 1):
# [@johnston2022absolutely] (8): Check if the normalized purity trace(mat mat^dagger) <= trace(mat)^2 / (d - 1)
# (for k > 2). Scaling by trace(mat)^2 preserves invariance under positive scaling of unnormalized PSD inputs;
# using the conjugate transpose keeps it correct (and real) for complex inputs.
trace_val = np.real(np.trace(mat))
if k > 2 and trace_val > 0 and np.real(np.trace(mat @ mat.conj().T)) <= (trace_val**2) / (d - 1):
return True

# Hierarchical recursion: for k >= 2 check incoherence for k-1.
Expand Down
7 changes: 7 additions & 0 deletions toqito/matrix_props/tests/test_is_k_incoherent.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,10 @@ def test_is_k_incoherent_solver_returns_none(monkeypatch):
# This 4x4 matrix reaches the SDP fallback; with the guard it must not raise.
mat = np.array([[0.35, 0.30, 0.0, 0.0], [0.30, 0.25, 0.0, 0.0], [0.0, 0.0, 0.25, 0.05], [0.0, 0.0, 0.05, 0.15]])
assert is_k_incoherent(mat, 3) is False


@pytest.mark.parametrize("scale", [0.1, 0.5, 2.0])
def test_is_k_incoherent_positive_scaling(scale):
"""Positive scaling must not change k-incoherence via the purity bound."""
rho = np.full((4, 4), 0.25)
assert is_k_incoherent(scale * rho, 3) is False
Loading