from cvxpy.problems.solvers.ecos_intf import ECOS from cvxpy.problems.solvers.ecos_bb_intf import ECOS_BB from cvxpy.problems.solvers.cvxopt_intf import CVXOPT from cvxpy.problems.solvers.glpk_intf import GLPK from cvxpy.problems.solvers.glpk_mi_intf import GLPK_MI from cvxpy.problems.solvers.cbc_intf import CBC from cvxpy.problems.solvers.scs_intf import SCS from cvxpy.problems.solvers.gurobi_intf import GUROBI from cvxpy.problems.solvers.elemental_intf import Elemental from cvxpy.problems.solvers.mosek_intf import MOSEK from cvxpy.problems.solvers.ls_intf import LS from cvxpy.problems.solvers.julia_opt_intf import JuliaOpt from cvxpy.problems.solvers.xpress_intf import XPRESS solver_intf = [ ECOS(), ECOS_BB(), CVXOPT(), GLPK(), GLPK_MI(), CBC(), SCS(), GUROBI(), Elemental(), MOSEK(), LS(), JuliaOpt(), XPRESS() ] SOLVERS = {solver.name(): solver for solver in solver_intf}
the Free Software Foundation, either version 3 of the License, or (at your option) any later version. CVXPY is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CVXPY. If not, see <http://www.gnu.org/licenses/>. """ from cvxpy.problems.solvers.ecos_intf import ECOS from cvxpy.problems.solvers.ecos_bb_intf import ECOS_BB from cvxpy.problems.solvers.cvxopt_intf import CVXOPT from cvxpy.problems.solvers.glpk_intf import GLPK from cvxpy.problems.solvers.scs_intf import SCS solver_intf = [ECOS(), ECOS_BB(), CVXOPT(), GLPK(), SCS()] SOLVERS = {solver.name(): solver for solver in solver_intf} def installed_solvers(): """List the installed solvers. """ installed = [] for name, solver in SOLVERS.items(): if solver.is_installed(): installed.append(name) return installed
import unittest import cvxpy_codegen.tests.utils as tu import cvxpy_codegen as cg import numpy as np import json from cvxpy_codegen.linop_sym.linop_handler_sym import LinOpHandlerSym from jinja2 import Environment, PackageLoader, contextfilter from cvxpy_codegen.utils.utils import render, make_target_dir import scipy.sparse as sp import cvxpy.settings as s from cvxpy.problems.solvers.ecos_intf import ECOS import cvxpy from cvxpy.problems.problem_data.sym_data import SymData from cvxpy_codegen.code_generator import CodeGenerator ECOS = ECOS() HARNESS_C = 'tests/linop_handler/harness.c.jinja' CODEGEN_H = 'tests/linop_handler/codegen.h.jinja' target_dir = tu.TARGET_DIR class TestLinopHandler(tu.CodegenTestCase): # Define some Parameters and Constants to build tests with. def setUp(self): np.random.seed(0) m = 10 n = 20 p = 15 self.m = m
def _test_expr(self, expr, printing=False): # Get Callback param. prob = cg.Problem(cvxpy.Minimize(expr)) obj, constrs = expr.canonicalize() data = ECOS.get_problem_data(obj, constrs, prob._cached_data) true_obj_coeff = data[s.C] true_obj_offset = data[s.OFFSET] true_eq_coeff = data[s.A] true_eq_offset = data[s.B] true_leq_coeff = data[s.G] true_leq_offset = data[s.H] # Do code generation vars = prob.variables() params = prob.parameters() obj, constraints = prob.canonical_form code_generator = CodeGenerator(obj, constraints, vars, params) code_generator.codegen(target_dir) template_vars = code_generator.template_vars # Set up test harness. render(target_dir, template_vars, HARNESS_C, 'harness.c') render(target_dir, template_vars, CODEGEN_H, 'codegen.h') test_data = self._run_test(target_dir) test_obj_coeff = np.array(test_data['obj_coeff']) test_obj_offset = np.array(test_data['obj_offset']) test_eq_coeff = sp.csc_matrix((test_data['eq_nzval'], test_data['eq_rowidx'], test_data['eq_colptr']), shape = (test_data['eq_size0'], test_data['eq_size1'])) test_eq_offset = np.array(test_data['eq_offset']) test_leq_coeff = sp.csc_matrix((test_data['eq_nzval'], test_data['eq_rowidx'], test_data['eq_colptr']), shape = (test_data['eq_size0'], test_data['eq_size1'])) test_leq_offset = np.array(test_data['leq_offset']) if printing: print('\nTest objective coeff :\n', test_obj_coeff) print('\nTrue objective coeff :\n', true_obj_coeff) print('\nTest objective offset :\n', test_obj_offset) print('\nTrue objective offset :\n', true_obj_offset) print('\nTest equality offset :\n', test_eq_coeff) print('\nTrue equality offset :\n', true_eq_coeff) print('\nTest equality offset :\n', test_eq_offset) print('\nTrue equality offset :\n', true_eq_offset) print('\nTest inequality offset :\n', test_leq_coeff) print('\nTrue inequality offset :\n', true_leq_coeff) print('\nTest inequality offset :\n', test_leq_offset) print('\nTrue inequality offset :\n', true_leq_offset) self.assertAlmostEqualMatrices(true_obj_coeff, test_obj_coeff) self.assertAlmostEqualMatrices(true_obj_offset, test_obj_offset) self.assertAlmostEqualMatrices(true_eq_coeff, test_eq_coeff) self.assertAlmostEqualMatrices(true_eq_offset, test_eq_offset) self.assertAlmostEqualMatrices(true_leq_coeff, test_leq_coeff) self.assertAlmostEqualMatrices(true_leq_offset, test_leq_offset)
""" Copyright 2013 Steven Diamond This file is part of CVXPY. CVXPY is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. CVXPY is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with CVXPY. If not, see <http://www.gnu.org/licenses/>. """ from cvxpy.problems.solvers.ecos_intf import ECOS from cvxpy.problems.solvers.cvxopt_intf import CVXOPT from cvxpy.problems.solvers.scs_intf import SCS solver_intf = [ECOS(), CVXOPT(), SCS()] SOLVERS = {solver.name():solver for solver in solver_intf}