Help: Illegal operation: {real affine} - {invalid}

One time through the outer loop, CVX failed, which resulted in CVX variables being NaN. These NaN variables were used the next time through the outer loop, which resulted in invalid.

Follow the advice at
CVXQUAD: How to use CVXQUAD's Pade Approximant instead of CVX's unreliable Successive Approximation for GP mode, log, exp, entr, rel_entr, kl_div, log_det, det_rootn, exponential cone. CVXQUAD's Quantum (Matrix) Entropy & Matrix Log related functions . Maybe CVX won’t fail. But it still might. Try to make the problem as well-scaled as you can. Using Successive Convex Approximation in a crude way, such as you have, often doesn’t work out. Given the semidefinite declaration, perhaps your original problem is actually a Nonlinear Semidefinite Programming problem, which is very difficult to solve - your best best on that might be using BMIBNB under YALMIP, which may or may not succeed.