print "lambda=", lambd, ": ctrl.alpha=", ctrl.alpha XEmb = El.LeastSquares(AEmb, D, ctrl) X = XEmb[0:n0 * n1, 0:numRHS] Y = XEmb[n0 * n1:n0 * n1 + numColsB, 0:numRHS] El.Scale(lambd, X) YNorm = El.FrobeniusNorm(Y) if worldRank == 0: print "lambda=", lambd, ": || Y ||_F =", YNorm El.Copy(D, E) El.Multiply(El.NORMAL, -1., A, X, 1., E) El.Multiply(El.NORMAL, -1., B, Y, 1., E) residNorm = El.FrobeniusNorm(E) if worldRank == 0: print "lambda=", lambd, ": || D - A X - B Y ||_F / || D ||_F =", residNorm / DNorm SolveWeighted(A, B, D, 1) SolveWeighted(A, B, D, 10) SolveWeighted(A, B, D, 100) SolveWeighted(A, B, D, 1000) SolveWeighted(A, B, D, 10000) SolveWeighted(A, B, D, 100000) # Require the user to press a button before the figures are closed El.Finalize() if worldSize == 1: raw_input('Press Enter to exit')
def solve(self, objective, constraints, cached_data, warm_start, verbose, solver_opts): """Returns the result of the call to the solver. Parameters ---------- objective : LinOp The canonicalized objective. constraints : list The list of canonicalized cosntraints. cached_data : dict A map of solver name to cached problem data. warm_start : bool Not used. verbose : bool Should the solver print output? solver_opts : dict Additional arguments for the solver. Returns ------- tuple (status, optimal value, primal, equality dual, inequality dual) """ import El data = self.get_problem_data(objective, constraints, cached_data) El.Initialize() # Package data. c = self.distr_vec(data["c"], El.dTag) A = self.distr_mat(data["A"]) b = self.distr_vec(data["b"], El.dTag) G = self.distr_mat(data["G"]) h = self.distr_vec(data["h"], El.dTag) dims = data["dims"] # Cone information. offset = 0 orders = [] firstInds = [] for i in range(dims[s.LEQ_DIM]): orders.append(1) firstInds.append(offset) offset += 1 for cone_len in dims[s.SOC_DIM]: for i in range(cone_len): orders.append(cone_len) firstInds.append(offset) offset += cone_len orders = self.distr_vec(np.array(orders), El.iTag) firstInds = self.distr_vec(np.array(firstInds), El.iTag) # Initialize empty vectors for solutions. x = El.DistMultiVec() y = El.DistMultiVec() z = El.DistMultiVec() s_var = El.DistMultiVec() if verbose: ctrl = El.SOCPAffineCtrl_d() ctrl.mehrotraCtrl.progress = True ctrl.mehrotraCtrl.time = True else: ctrl = None El.SOCPAffine(A, G, b, c, h, orders, firstInds, x, y, z, s_var, ctrl) local_c = data['c'] local_x = self.local_vec(x) local_y = self.local_vec(y) local_z = self.local_vec(z) El.Finalize() results_dict = { 'info': { 'exitFlag': 0, 'pcost': local_c.dot(local_x) }, 'x': local_x, 'y': local_y, 'z': local_z } return self.format_results(results_dict, data, cached_data)