Deciding whether a quantum state is separable or entangled is a hard problem in general. Two practical relaxations get us surprisingly far: the PPT criterion and the symmetric extension hierarchy. This post tests both on a concrete two-qubit example and visualizes how the relaxations behave.
The Problem
A bipartite state $\rho_{AB}$ is separable if it can be written as
$$
\rho_{AB}=\sum_i q_i,\rho_A^{(i)}\otimes\rho_B^{(i)},\qquad q_i\ge 0,\ \sum_i q_i=1 .
$$
Checking this directly is NP-hard, so we use necessary conditions that can be tested with semidefinite programming (SDP).
PPT relaxation. Every separable state has a positive semidefinite partial transpose:
$$
\rho_{AB}\ \text{separable}\ \Rightarrow\ \rho_{AB}^{T_B}\succeq 0 .
$$
Symmetric extension relaxation. A state $\rho_{AB}$ is $k$-extendible if there is a state $\sigma_{AB_1\cdots B_k}$ such that

Separable states are $k$-extendible for every $k$, and conversely, a state that is $k$-extendible for all $k$ is separable. Adding PPT conditions on $\sigma$ gives the stronger PPT symmetric extension test of Doherty, Parrilo and Spedalieri:
$$
\sigma^{T_{B_{k-m+1}\cdots B_k}}\succeq 0,\qquad m=1,\dots,k .
$$
The Example
We use a family of noisy two-qubit entangled states:
$$
\rho(p,\theta)=p,|\Phi_\theta\rangle\langle\Phi_\theta|+(1-p),\frac{I}{4},\qquad
|\Phi_\theta\rangle=\cos\theta,|00\rangle+\sin\theta,|11\rangle .
$$
For $\theta=\pi/4$ this is a Werner-type state built from a Bell state. The partial transpose has the smallest eigenvalue
$$
\lambda_{\min}!\left(\rho^{T_B}\right)=\frac{1-p}{4}-\frac{p,\sin 2\theta}{2},
$$
so for two qubits, where PPT is both necessary and sufficient, the exact separability boundary is
$$
p^\ast(\theta)=\frac{1}{1+2\sin 2\theta},\qquad p^\ast(\pi/4)=\frac13 .
$$
For each $\theta$ and each hierarchy level $k$, we solve the SDP
$$
\max\ p\quad\text{s.t.}\quad \sigma\succeq0,\ \operatorname{Tr}\sigma=1,\ \sigma\ \text{symmetric on }B,\ \operatorname{Tr}_{B_2\cdots B_k}\sigma=p,|\Phi_\theta\rangle\langle\Phi_\theta|+(1-p)\tfrac{I}{4}.
$$
This gives the largest noise-free weight $p$ that still passes the test. The true boundary is $p^\ast$, so a relaxation is tight when it reproduces it.
Source Code
1 | import time |
Code Walkthrough
1. States and the PPT criterion
phi(theta) builds $|\Phi_\theta\rangle=\cos\theta|00\rangle+\sin\theta|11\rangle$ as a length-4 vector, and rho_state(p, theta) mixes its projector with the maximally mixed state $I/4$.
partial_transpose_B reshapes the $4\times4$ matrix into a tensor with indices $(a,b,a’,b’)$ and swaps the two $B$ indices. That is exactly the partial transpose on $B$:

ppt_min_eig returns the smallest eigenvalue, and ppt_threshold implements the closed form $p^\ast(\theta)=1/(1+2\sin2\theta)$ derived above. This is the baseline against which both hierarchy tests are compared.
2. Symmetric extension as an SDP
The extension lives on $n=k+1$ qubits: qubit 0 is $A$ and qubits $1,\dots,k$ are the copies of $B$.
swap_matrix(n, i, j)returns the permutation matrix that exchanges qubits $i$ and $j$. Invariance under all permutations of $B$ is enforced by requiring invariance under the adjacent swaps $(j,j+1)$, which generate the full symmetric group.trace_out_lastremoves the last qubit using $\operatorname{Tr}_{\text{last}}X=\sum_i (I\otimes\langle i|),X,(I\otimes|i\rangle)$. Applying it repeatedly produces the marginal on $AB_1$.transpose_qubitimplements the partial transpose of one qubit as a sum of four terms, using
$$
X^{T_q}=\sum_{i,j}E_{ij},X,E_{ij},\qquad E_{ij}=|i\rangle\langle j| ,
$$
so it only uses affine matrix products. This works in every CVXPY version and does not rely on a built-in partial-transpose function.max_visibilityassembles the SDP. The variable is a real symmetric matrix. Since $\rho(p,\theta)$ is real, this loses no generality: if a complex Hermitian extension exists, its real part is again a valid extension. This halves the number of variables and keeps the solver fast.- The constraint
marg == p * target_pure + (1 - p) * I4is linear in $(\sigma,p)$, so maximizing $p$ is a single SDP and needs no bisection. - With
ppt=True, the code adds $\sigma^{T_{B_{k-m+1}\cdots B_k}}\succeq0$ for $m=1,\dots,k$, which turns the test into the PPT symmetric extension hierarchy. solveuses the Clarabel interior-point solver and falls back to SCS if Clarabel is unavailable.
3. Speed
The SDP matrix has size $2^{k+1}$, so $k\le4$ means at most $32\times32$. The real-symmetric variable, the linear objective (no bisection) and the interior-point solver keep the whole script, including all grids and the figure, to a few seconds. No further acceleration is needed.
4. Example A: the Werner-type state
At $\theta=\pi/4$ the script first prints the minimum eigenvalue of $\rho^{T_B}$ for four values of $p$. It then computes the extension thresholds for $k=1,\dots,4$ and compares them with $(k+2)/(3k)$.
5. Example B: sweeping the entanglement angle
Eight values of $\theta\in[\pi/16,\pi/4]$ are tested at $k=2,3$, both with and without the PPT constraints, and compared with the exact boundary $p^\ast(\theta)$.
6. Visualization
All four panels are drawn in one figure and saved as separability_results.png.
Execution Results
=== Example A: Werner-type state, rho(p) = p|Phi+><Phi+| + (1-p) I/4 === p = 0.2000 min eig of rho^TB = +0.10000 -> PPT (separable) p = 0.3333 min eig of rho^TB = +0.00000 -> PPT (separable) p = 0.5000 min eig of rho^TB = -0.12500 -> NPT (entangled) p = 0.8000 min eig of rho^TB = -0.35000 -> NPT (entangled) Elapsed: 4.2 s k | sym. extension p_max | (k+2)/(3k) | PPT sym. ext. p_max 1 | 1.00000 | 1.00000 | 0.33333 2 | 0.66667 | 0.66667 | 0.33333 3 | 0.55556 | 0.55556 | 0.33333 4 | 0.50000 | 0.50000 | 0.33333 PPT threshold (exact separability limit): 0.33333 === Example B: rho(p, theta) = p|Phi(theta)><Phi(theta)| + (1-p) I/4 === theta/pi | PPT limit | sym k=2 | sym k=3 | PPT-sym k=2 | PPT-sym k=3 0.0625 | 0.56645 | 0.90423 | 0.84031 | 0.56645 | 0.56645 0.0893 | 0.48448 | 0.84405 | 0.75602 | 0.48448 | 0.48448 0.1161 | 0.42869 | 0.78960 | 0.68803 | 0.42869 | 0.42869 0.1429 | 0.39007 | 0.74457 | 0.63663 | 0.39007 | 0.39007 0.1696 | 0.36358 | 0.70998 | 0.59954 | 0.36358 | 0.36358 0.1964 | 0.34629 | 0.68572 | 0.57460 | 0.34629 | 0.34629 0.2232 | 0.33650 | 0.67140 | 0.56024 | 0.33650 | 0.33650 0.2500 | 0.33333 | 0.66667 | 0.55556 | 0.33333 | 0.33333

Reading the Results
Panel 1 (3D): the PPT landscape
The surface shows $\lambda_{\min}(\rho^{T_B})$ over $(\theta,p)$. The gray plane is zero, and the black curve where the surface crosses it is the separability boundary $p^\ast(\theta)$. Below the curve the partial transpose is positive and the state is separable; above it the eigenvalue goes negative and the state is entangled. The surface dips deepest near $\theta=\pi/4$ and $p=1$, the maximally entangled corner, where $\lambda_{\min}=-1/2$.
Panel 2: thresholds against the exact boundary
The black curve is the exact boundary. The plain symmetric extension test ($k=2,3$) sits well above it. States between the black curve and the dashed curves are entangled but still pass the test, so the test fails to detect them. Raising $k$ from 2 to 3 pulls the dashed curve down toward the boundary, which is the hierarchy at work. The PPT symmetric extension curves lie exactly on the black curve, so for two qubits that stronger test is already tight at $k=2$.
Panel 3: the Werner-type state as $k$ grows
For $\theta=\pi/4$, the plain symmetric extension thresholds agree with the formula
$$
p_k=\frac{k+2}{3k}\ :\qquad 1,\ \frac23,\ \frac59,\ \frac12\quad (k=1,2,3,4),
$$
and tend to the separability limit $\lim_{k\to\infty}p_k=\tfrac13$ from above. The convergence is slow: $k=4$ still accepts every state with $p\le 1/2$. The PPT-augmented version stays flat at $1/3$ for every $k$, since adding the PPT conditions already reproduces the exact answer for two qubits.
Panel 4 (3D): the gap
Each bar shows $p_k(\theta)-p^\ast(\theta)$ for the plain symmetric extension test. Bars at $k=3$ are consistently lower than bars at $k=2$, so the extra copy always removes part of the gap. The gap is smallest at small $\theta$ (weakly entangled states) and grows toward $\theta=\pi/4$ for both levels.
Takeaways
- For two qubits, PPT is an exact separability test, and the PPT symmetric extension hierarchy reproduces it already at the first levels.
- The plain symmetric extension hierarchy converges only gradually, with the Werner-type thresholds following $(k+2)/(3k)\to1/3$.
- The same SDP formulation carries over unchanged to higher dimensions, where PPT is no longer sufficient and the hierarchy becomes the practical tool for certifying entanglement.

is the partial trace over the two-dimensional output factor, and the constraint is exactly trace preservation, $\sum_jR_j^\dagger R_j=I_{16}$.
for every pair $(j,k)$ at once. The same function scores every strategy, which keeps the comparison fair: the uncoded qubit uses $R=I$ with $A_k=K_k$, and the coded cases use $16\times2$ operators $A_k$.









. The dark-to-bright scale makes solver-level errors visible.





first and are then pushed further by the logarithmic growth of $x^{*}$. Expensive resources appear mainly at the ridge peaks, and cheap resources also cover the quiet hours.