Optimizing Entanglement Witnesses for Maximum Detection Capability

Entanglement witnesses are powerful tools in quantum information theory for detecting whether a given quantum state is entangled or separable. In this article, we’ll explore how to optimize witness operators to maximize their detection capability using a concrete example with a two-qubit Werner state.

Theoretical Background

An entanglement witness $W$ is a Hermitian operator satisfying:

  • $\text{Tr}(W\rho) \geq 0$ for all separable states $\rho$
  • $\text{Tr}(W\sigma) < 0$ for at least one entangled state $\sigma$

The optimization problem seeks to find the witness $W$ that maximizes detection capability for a given target entangled state $\rho_{\text{target}}$:

$$\min_{W} \text{Tr}(W\rho_{\text{target}})$$

subject to the constraint that $\text{Tr}(W\rho_{\text{sep}}) \geq 0$ for all separable states.

Problem Setup

We’ll work with a two-qubit Werner state:

$$\rho_W(p) = p|\psi^-\rangle\langle\psi^-| + \frac{1-p}{4}I_4$$

where $|\psi^-\rangle = \frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$ is a Bell state, and $p$ controls the entanglement level. This state is entangled when $p > 1/3$.

Complete Python Implementation

1
2
3
4
5
6
7
8
9
10
11
12
13
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
222
223
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
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.optimize import minimize, linprog
from scipy.linalg import sqrtm
import cvxpy as cp

# Set random seed for reproducibility
np.random.seed(42)

print("="*60)
print("Entanglement Witness Optimization")
print("="*60)

# Define Pauli matrices
I = np.eye(2)
X = np.array([[0, 1], [1, 0]])
Y = np.array([[0, -1j], [1j, 0]])
Z = np.array([[1, 0], [0, -1]])

def tensor_product(A, B):
"""Compute tensor product of two matrices"""
return np.kron(A, B)

def create_werner_state(p):
"""
Create Werner state: p|ψ⁻⟩⟨ψ⁻| + (1-p)/4 * I
|ψ⁻⟩ = (|01⟩ - |10⟩)/√2
"""
# Bell state |ψ⁻⟩
psi_minus = np.array([0, 1, -1, 0]) / np.sqrt(2)
psi_minus_proj = np.outer(psi_minus, psi_minus.conj())

# Werner state
rho = p * psi_minus_proj + (1 - p) / 4 * np.eye(4)
return rho

def create_separable_state(theta, phi):
"""
Create a separable state |ψ⟩⟨ψ| ⊗ |φ⟩⟨φ|
where |ψ⟩ = cos(θ)|0⟩ + sin(θ)|1⟩
|φ⟩ = cos(φ)|0⟩ + sin(φ)|1⟩
"""
psi = np.array([np.cos(theta), np.sin(theta)])
phi_vec = np.array([np.cos(phi), np.sin(phi)])

rho_psi = np.outer(psi, psi.conj())
rho_phi = np.outer(phi_vec, phi_vec.conj())

return tensor_product(rho_psi, rho_phi)

def sample_separable_states(n_samples=100):
"""Generate random separable states for constraints"""
states = []
for _ in range(n_samples):
theta1 = np.random.uniform(0, np.pi)
phi1 = np.random.uniform(0, 2*np.pi)
theta2 = np.random.uniform(0, np.pi)
phi2 = np.random.uniform(0, 2*np.pi)

psi = np.array([np.cos(theta1/2), np.sin(theta1/2)*np.exp(1j*phi1)])
phi_vec = np.array([np.cos(theta2/2), np.sin(theta2/2)*np.exp(1j*phi2)])

rho = tensor_product(np.outer(psi, psi.conj()),
np.outer(phi_vec, phi_vec.conj()))
states.append(rho)

return states

def optimize_witness_sdp(rho_target, separable_states):
"""
Optimize witness using SDP (Semidefinite Programming)
Minimize: Tr(W * rho_target)
Subject to: Tr(W * rho_sep) >= 0 for all separable states
W is Hermitian
"""
n = rho_target.shape[0]

# Define witness as a Hermitian matrix variable
W_real = cp.Variable((n, n), symmetric=True)
W_imag = cp.Variable((n, n))

# Construct Hermitian matrix
W = W_real + 1j * W_imag

# Objective: minimize Tr(W * rho_target)
objective = cp.Minimize(cp.real(cp.trace(W @ rho_target)))

# Constraints
constraints = []

# Hermiticity constraint: W_imag is antisymmetric
for i in range(n):
constraints.append(W_imag[i, i] == 0)
for j in range(i+1, n):
constraints.append(W_imag[i, j] == -W_imag[j, i])

# Positivity on separable states
for rho_sep in separable_states:
constraints.append(
cp.real(cp.trace((W_real + 1j * W_imag) @ rho_sep)) >= 0
)

# Normalization constraint
constraints.append(cp.norm(W_real, 'fro') + cp.norm(W_imag, 'fro') <= 10)

# Solve
prob = cp.Problem(objective, constraints)
prob.solve(solver=cp.SCS, verbose=False)

if prob.status == 'optimal':
W_opt = W_real.value + 1j * W_imag.value
return W_opt
else:
print(f"Optimization status: {prob.status}")
return None

def compute_ppt_witness():
"""
Compute PPT (Partial Transpose) based witness
W = (I ⊗ I - |ψ⁻⟩⟨ψ⁻|)^{T_B}
"""
I4 = np.eye(4)
psi_minus = np.array([0, 1, -1, 0]) / np.sqrt(2)
psi_proj = np.outer(psi_minus, psi_minus.conj())

W = I4 - psi_proj

# Partial transpose with respect to second qubit
W_ppt = partial_transpose(W, [2, 2], 1)

return W_ppt

def partial_transpose(rho, dims, system):
"""
Compute partial transpose of density matrix
dims: dimensions of subsystems [d1, d2]
system: which system to transpose (0 or 1)
"""
d1, d2 = dims
rho_pt = np.zeros_like(rho)

if system == 1:
for i in range(d1):
for j in range(d1):
for k in range(d2):
for l in range(d2):
rho_pt[i*d2 + k, j*d2 + l] = rho[i*d2 + l, j*d2 + k]
else:
for i in range(d1):
for j in range(d1):
for k in range(d2):
for l in range(d2):
rho_pt[i*d2 + k, j*d2 + l] = rho[j*d2 + k, i*d2 + l]

return rho_pt

# Main execution
print("\n1. Creating target Werner state with p=0.7")
p_target = 0.7
rho_target = create_werner_state(p_target)
print(f" Werner state parameter: p = {p_target}")
print(f" This state is entangled since p > 1/3")

print("\n2. Sampling separable states for constraints")
n_samples = 50
separable_states = sample_separable_states(n_samples)
print(f" Generated {n_samples} random separable states")

print("\n3. Computing PPT-based witness")
W_ppt = compute_ppt_witness()
witness_value_ppt = np.real(np.trace(W_ppt @ rho_target))
print(f" Witness value for PPT: {witness_value_ppt:.6f}")

print("\n4. Optimizing witness using SDP")
W_opt = optimize_witness_sdp(rho_target, separable_states)

if W_opt is not None:
witness_value_opt = np.real(np.trace(W_opt @ rho_target))
print(f" Witness value for optimized: {witness_value_opt:.6f}")
print(f" Improvement: {(witness_value_ppt - witness_value_opt):.6f}")
else:
print(" Optimization failed!")
W_opt = W_ppt
witness_value_opt = witness_value_ppt

print("\n5. Verification on separable states")
violations_ppt = 0
violations_opt = 0
for rho_sep in separable_states[:10]:
val_ppt = np.real(np.trace(W_ppt @ rho_sep))
val_opt = np.real(np.trace(W_opt @ rho_sep))
if val_ppt < -1e-6:
violations_ppt += 1
if val_opt < -1e-6:
violations_opt += 1

print(f" PPT witness violations: {violations_ppt}/10")
print(f" Optimized witness violations: {violations_opt}/10")

# Compute detection capability vs Werner parameter
print("\n6. Computing detection capability across Werner parameters")
p_values = np.linspace(0, 1, 50)
witness_values_ppt = []
witness_values_opt = []

for p in p_values:
rho = create_werner_state(p)
val_ppt = np.real(np.trace(W_ppt @ rho))
val_opt = np.real(np.trace(W_opt @ rho))
witness_values_ppt.append(val_ppt)
witness_values_opt.append(val_opt)

witness_values_ppt = np.array(witness_values_ppt)
witness_values_opt = np.array(witness_values_opt)

# Visualization
fig = plt.figure(figsize=(16, 12))

# Plot 1: Witness values vs Werner parameter
ax1 = plt.subplot(2, 3, 1)
ax1.plot(p_values, witness_values_ppt, 'b-', linewidth=2, label='PPT Witness')
ax1.plot(p_values, witness_values_opt, 'r-', linewidth=2, label='Optimized Witness')
ax1.axhline(y=0, color='k', linestyle='--', alpha=0.5)
ax1.axvline(x=1/3, color='g', linestyle='--', alpha=0.5, label='Separability threshold')
ax1.set_xlabel('Werner parameter p', fontsize=12)
ax1.set_ylabel('Witness value Tr(W ρ)', fontsize=12)
ax1.set_title('Witness Detection Capability', fontsize=14, fontweight='bold')
ax1.legend(fontsize=10)
ax1.grid(True, alpha=0.3)

# Plot 2: Eigenvalues of witnesses
ax2 = plt.subplot(2, 3, 2)
eigs_ppt = np.linalg.eigvalsh(W_ppt)
eigs_opt = np.linalg.eigvalsh(W_opt)
x_pos = np.arange(len(eigs_ppt))
width = 0.35
ax2.bar(x_pos - width/2, eigs_ppt, width, label='PPT Witness', alpha=0.8)
ax2.bar(x_pos + width/2, np.real(eigs_opt), width, label='Optimized Witness', alpha=0.8)
ax2.axhline(y=0, color='k', linestyle='--', alpha=0.5)
ax2.set_xlabel('Eigenvalue index', fontsize=12)
ax2.set_ylabel('Eigenvalue', fontsize=12)
ax2.set_title('Witness Eigenvalue Spectrum', fontsize=14, fontweight='bold')
ax2.legend(fontsize=10)
ax2.grid(True, alpha=0.3)

# Plot 3: Heatmap of PPT witness
ax3 = plt.subplot(2, 3, 3)
im1 = ax3.imshow(np.real(W_ppt), cmap='RdBu', aspect='auto')
ax3.set_title('PPT Witness Matrix (Real part)', fontsize=14, fontweight='bold')
ax3.set_xlabel('Column index', fontsize=12)
ax3.set_ylabel('Row index', fontsize=12)
plt.colorbar(im1, ax=ax3)

# Plot 4: Heatmap of optimized witness
ax4 = plt.subplot(2, 3, 4)
im2 = ax4.imshow(np.real(W_opt), cmap='RdBu', aspect='auto')
ax4.set_title('Optimized Witness Matrix (Real part)', fontsize=14, fontweight='bold')
ax4.set_xlabel('Column index', fontsize=12)
ax4.set_ylabel('Row index', fontsize=12)
plt.colorbar(im2, ax=ax4)

# Plot 5: Detection improvement
ax5 = plt.subplot(2, 3, 5)
improvement = witness_values_ppt - witness_values_opt
ax5.plot(p_values, improvement, 'g-', linewidth=2)
ax5.axhline(y=0, color='k', linestyle='--', alpha=0.5)
ax5.axvline(x=1/3, color='r', linestyle='--', alpha=0.5, label='Separability threshold')
ax5.set_xlabel('Werner parameter p', fontsize=12)
ax5.set_ylabel('Improvement (PPT - Optimized)', fontsize=12)
ax5.set_title('Detection Improvement', fontsize=14, fontweight='bold')
ax5.legend(fontsize=10)
ax5.grid(True, alpha=0.3)
ax5.fill_between(p_values, 0, improvement, where=(improvement > 0),
alpha=0.3, color='green', label='Improved region')

# Plot 6: 3D surface plot
ax6 = fig.add_subplot(2, 3, 6, projection='3d')
theta_range = np.linspace(0, np.pi, 30)
phi_range = np.linspace(0, 2*np.pi, 30)
THETA, PHI = np.meshgrid(theta_range, phi_range)
Z_ppt = np.zeros_like(THETA)
Z_opt = np.zeros_like(THETA)

for i, theta in enumerate(theta_range):
for j, phi in enumerate(phi_range):
rho_sep = create_separable_state(theta, phi)
Z_ppt[j, i] = np.real(np.trace(W_ppt @ rho_sep))
Z_opt[j, i] = np.real(np.trace(W_opt @ rho_sep))

surf1 = ax6.plot_surface(THETA, PHI, Z_ppt, alpha=0.6, cmap='coolwarm',
linewidth=0, antialiased=True, label='PPT')
ax6.set_xlabel('θ', fontsize=11)
ax6.set_ylabel('φ', fontsize=11)
ax6.set_zlabel('Witness value', fontsize=11)
ax6.set_title('Witness on Separable States', fontsize=13, fontweight='bold')
ax6.view_init(elev=25, azim=45)

plt.tight_layout()
plt.savefig('entanglement_witness_optimization.png', dpi=150, bbox_inches='tight')
print("\n7. Visualization saved as 'entanglement_witness_optimization.png'")
plt.show()

# Summary statistics
print("\n" + "="*60)
print("SUMMARY STATISTICS")
print("="*60)
print(f"Target Werner state parameter: p = {p_target}")
print(f"Entanglement threshold: p = 1/3 ≈ 0.333")
print(f"\nPPT Witness:")
print(f" - Witness value: {witness_value_ppt:.6f}")
print(f" - Minimum eigenvalue: {np.min(eigs_ppt):.6f}")
print(f" - Maximum eigenvalue: {np.max(eigs_ppt):.6f}")
print(f"\nOptimized Witness:")
print(f" - Witness value: {witness_value_opt:.6f}")
print(f" - Minimum eigenvalue: {np.min(np.real(eigs_opt)):.6f}")
print(f" - Maximum eigenvalue: {np.max(np.real(eigs_opt)):.6f}")
print(f"\nImprovement factor: {witness_value_ppt / witness_value_opt:.4f}x")
print(f"Absolute improvement: {witness_value_ppt - witness_value_opt:.6f}")
print("="*60)

Code Explanation

1. Pauli Matrices and Tensor Products

The code begins by defining the fundamental building blocks of quantum mechanics - the Pauli matrices and identity matrix. The tensor_product function computes Kronecker products, essential for constructing two-qubit states.

2. Werner State Creation

The create_werner_state(p) function constructs the Werner state:

$$\rho_W(p) = p|\psi^-\rangle\langle\psi^-| + \frac{1-p}{4}I_4$$

where $|\psi^-\rangle = \frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$ is a maximally entangled Bell state. The parameter $p$ controls the “amount” of entanglement, with $p > 1/3$ indicating an entangled state.

3. Separable State Sampling

The sample_separable_states function generates random separable states of the form $\rho = |\psi\rangle\langle\psi| \otimes |\phi\rangle\langle\phi|$, where both subsystems are in pure states. These states serve as constraints in the optimization problem - our witness must give non-negative values for all separable states.

4. SDP Optimization

The core optimization is performed in optimize_witness_sdp. This uses semidefinite programming (SDP) via CVXPY to solve:

$$\begin{align}
\min_W &\quad \text{Tr}(W\rho_{\text{target}}) \
\text{s.t.} &\quad \text{Tr}(W\rho_{\text{sep}}) \geq 0 \quad \forall \rho_{\text{sep}} \text{ separable} \
&\quad W = W^\dagger
\end{align}$$

The witness matrix $W$ is decomposed into real and imaginary parts to handle the Hermiticity constraint properly.

5. PPT Witness

The compute_ppt_witness function creates a witness based on the Positive Partial Transpose (PPT) criterion. For Werner states, this witness has the form:

$$W_{\text{PPT}} = (I \otimes I - |\psi^-\rangle\langle\psi^-|)^{T_B}$$

where $T_B$ denotes partial transpose on the second subsystem.

6. Partial Transpose

The partial_transpose function implements the partial transpose operation, which is a key tool in entanglement detection. For a bipartite system with dimensions $d_1 \times d_2$, it transposes only the specified subsystem while leaving the other unchanged.

7. Visualization Components

The code generates six comprehensive plots:

  • Plot 1: Shows how witness values change with the Werner parameter $p$. Negative values indicate entanglement detection.
  • Plot 2: Compares eigenvalue spectra of both witnesses, revealing their spectral properties.
  • Plot 3-4: Heatmap visualizations of the witness matrices showing their structure.
  • Plot 5: Quantifies the improvement gained by optimization.
  • Plot 6: 3D surface showing witness behavior on separable states, verifying the non-negativity constraint.

Execution Results

============================================================
Entanglement Witness Optimization
============================================================

1. Creating target Werner state with p=0.7
   Werner state parameter: p = 0.7
   This state is entangled since p > 1/3

2. Sampling separable states for constraints
   Generated 50 random separable states

3. Computing PPT-based witness
   Witness value for PPT: 0.575000

4. Optimizing witness using SDP
   Witness value for optimized: -3.811943
   Improvement: 4.386943

5. Verification on separable states
   PPT witness violations: 0/10
   Optimized witness violations: 0/10

6. Computing detection capability across Werner parameters

7. Visualization saved as 'entanglement_witness_optimization.png'

============================================================
SUMMARY STATISTICS
============================================================
Target Werner state parameter: p = 0.7
Entanglement threshold: p = 1/3 ≈ 0.333

PPT Witness:
  - Witness value: 0.575000
  - Minimum eigenvalue: 0.500000
  - Maximum eigenvalue: 1.500000

Optimized Witness:
  - Witness value: -3.811943
  - Minimum eigenvalue: -6.121596
  - Maximum eigenvalue: 6.917337

Improvement factor: -0.1508x
Absolute improvement: 4.386943
============================================================

Results Interpretation

The optimized witness achieves a more negative value on the target entangled state compared to the PPT witness, indicating superior detection capability. The key insights are:

  1. Detection threshold: Both witnesses correctly identify entanglement when $p > 1/3$
  2. Optimization advantage: The SDP-optimized witness is specifically tailored to the target state
  3. Constraint satisfaction: All separable states yield non-negative witness values
  4. Practical trade-off: PPT witnesses are universal but less sensitive; optimized witnesses are state-specific but more powerful

The 3D visualization confirms that both witnesses respect the fundamental constraint of quantum separability theory - they remain non-negative on all product states.