def sls_common_lyapunov(A, B, Q, R, eps_A, eps_B, tau, logger=None):
    '\n    Solves the common Lyapunov relaxation to the robust \n    synthesis problem.\n\n    Taken from\n    lstd-lqr/blob/master/code/policy_iteration.ipynb\n    learning-lqr/experiments/matlab/sls_synth_yalmip/common_lyap_synth_var2_alpha.m\n\n    '
    if (logger is None):
        logger = logging.getLogger(__name__)
    (d, p) = B.shape
    X = cvx.Symmetric(d)
    Z = cvx.Variable(p, d)
    W_11 = cvx.Symmetric(d)
    W_12 = cvx.Variable(d, p)
    W_22 = cvx.Symmetric(p)
    alph = cvx.Variable()
    constraints = []
    mat1 = cvx.bmat([[X, X, Z.T], [X, W_11, W_12], [Z, W_12.T, W_22]])
    constraints.append((mat1 == cvx.Semidef(((2 * d) + p))))
    mat2 = cvx.bmat([[(X - np.eye(d)), ((A * X) + (B * Z)), np.zeros((d, d)), np.zeros((d, p))], [((X * A.T) + (Z.T * B.T)), X, (eps_A * X), (eps_B * Z.T)], [np.zeros((d, d)), (eps_A * X), ((alph * (tau ** 2)) * np.eye(d)), np.zeros((d, p))], [np.zeros((p, d)), (eps_B * Z), np.zeros((p, d)), (((1 - alph) * (tau ** 2)) * np.eye(p))]])
    constraints.append((mat2 == cvx.Semidef(((3 * d) + p))))
    constraints.append((alph >= 0))
    constraints.append((alph <= 1))
    objective = cvx.Minimize((cvx.trace((Q * W_11)) + cvx.trace((R * W_22))))
    prob = cvx.Problem(objective, constraints)
    try:
        obj = prob.solve(solver=cvx.MOSEK)
    except cvx.SolverError:
        logger.warn('SolverError encountered')
        return (False, None, None, None)
    if (prob.status == cvx.OPTIMAL):
        logging.debug('common_lyapunov: found optimal solution')
        X_value = np.array(X.value)
        P_value = scipy.linalg.solve(X_value, np.eye(d), sym_pos=True)
        K_value = np.array(Z.value).dot(P_value)
        return (True, obj, P_value, K_value)
    else:
        logging.debug('common_lyapunov: could not solve (status={})'.format(prob.status))
        return (False, None, None, None)
Solves the common Lyapunov relaxation to the robust 
synthesis problem.

Taken from
lstd-lqr/blob/master/code/policy_iteration.ipynb
learning-lqr/experiments/matlab/sls_synth_yalmip/common_lyap_synth_var2_alpha.m
def sls_common_lyapunov(A, B, Q, R, eps_A, eps_B, tau, logger=None):
    '\n    Solves the common Lyapunov relaxation to the robust \n    synthesis problem.\n\n    Taken from\n    lstd-lqr/blob/master/code/policy_iteration.ipynb\n    learning-lqr/experiments/matlab/sls_synth_yalmip/common_lyap_synth_var2_alpha.m\n\n    '
    if (logger is None):
        logger = logging.getLogger(__name__)
    (d, p) = B.shape
    X = cvx.Symmetric(d)
    Z = cvx.Variable(p, d)
    W_11 = cvx.Symmetric(d)
    W_12 = cvx.Variable(d, p)
    W_22 = cvx.Symmetric(p)
    alph = cvx.Variable()
    constraints = []
    mat1 = cvx.bmat([[X, X, Z.T], [X, W_11, W_12], [Z, W_12.T, W_22]])
    constraints.append((mat1 == cvx.Semidef(((2 * d) + p))))
    mat2 = cvx.bmat([[(X - np.eye(d)), ((A * X) + (B * Z)), np.zeros((d, d)), np.zeros((d, p))], [((X * A.T) + (Z.T * B.T)), X, (eps_A * X), (eps_B * Z.T)], [np.zeros((d, d)), (eps_A * X), ((alph * (tau ** 2)) * np.eye(d)), np.zeros((d, p))], [np.zeros((p, d)), (eps_B * Z), np.zeros((p, d)), (((1 - alph) * (tau ** 2)) * np.eye(p))]])
    constraints.append((mat2 == cvx.Semidef(((3 * d) + p))))
    constraints.append((alph >= 0))
    constraints.append((alph <= 1))
    objective = cvx.Minimize((cvx.trace((Q * W_11)) + cvx.trace((R * W_22))))
    prob = cvx.Problem(objective, constraints)
    try:
        obj = prob.solve(solver=cvx.MOSEK)
    except cvx.SolverError:
        logger.warn('SolverError encountered')
        return (False, None, None, None)
    if (prob.status == cvx.OPTIMAL):
        logging.debug('common_lyapunov: found optimal solution')
        X_value = np.array(X.value)
        P_value = scipy.linalg.solve(X_value, np.eye(d), sym_pos=True)
        K_value = np.array(Z.value).dot(P_value)
        return (True, obj, P_value, K_value)
    else:
        logging.debug('common_lyapunov: could not solve (status={})'.format(prob.status))
        return (False, None, None, None)