"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "benchmarks/benchmarks/optimize_linprog.py" between
scipy-1.6.2.tar.xz and scipy-1.6.3.tar.xz

About: SciPy are tools for mathematics, science, and engineering (for Python).

optimize_linprog.py  (scipy-1.6.2.tar.xz):optimize_linprog.py  (scipy-1.6.3.tar.xz)
import os import os
import numpy as np import numpy as np
from numpy.testing import suppress_warnings from numpy.testing import suppress_warnings
from .common import Benchmark, is_xslow, safe_import from .common import Benchmark, is_xslow, safe_import
with safe_import(): with safe_import():
from scipy.optimize import linprog, OptimizeWarning from scipy.optimize import linprog, OptimizeWarning
with safe_import() as exc: with safe_import():
from scipy.optimize.tests.test_linprog import lpgen_2d, magic_square from scipy.optimize.tests.test_linprog import lpgen_2d, magic_square
from scipy.optimize._remove_redundancy import (
_remove_redundancy_svd,
_remove_redundancy_pivot_sparse,
_remove_redundancy_pivot_dense,
_remove_redundancy_id
)
from scipy.optimize._linprog_util import (
_presolve,
_clean_inputs,
_LPProblem
)
if exc.error:
_remove_redundancy_svd = None
_remove_redundancy_pivot_sparse = None
_remove_redundancy_pivot_dense = None
_remove_redundancy_id = None
with safe_import(): with safe_import():
from scipy.linalg import toeplitz from scipy.linalg import toeplitz
with safe_import(): methods = [("highs-ipm", {})]
from scipy.sparse import csc_matrix, csr_matrix, issparse
methods = [("interior-point", {"sparse": True}),
("interior-point", {"sparse": False}),
("revised simplex", {}),
("highs-ipm", {}),
("highs-simplex", {})]
rr_methods = [_remove_redundancy_svd, _remove_redundancy_pivot_sparse,
_remove_redundancy_pivot_dense, _remove_redundancy_id]
presolve_methods = ['sparse', 'dense']
problems = ['25FV47', '80BAU3B', 'ADLITTLE', 'AFIRO', 'AGG', 'AGG2', 'AGG3', problems = ['25FV47', '80BAU3B', 'ADLITTLE', 'AFIRO', 'AGG', 'AGG2', 'AGG3',
'BANDM', 'BEACONFD', 'BLEND', 'BNL1', 'BNL2', 'BORE3D', 'BRANDY', 'BANDM', 'BEACONFD', 'BLEND', 'BNL1', 'BNL2', 'BORE3D', 'BRANDY',
'CAPRI', 'CYCLE', 'CZPROB', 'D6CUBE', 'DEGEN2', 'DEGEN3', 'E226', 'CAPRI', 'CYCLE', 'CZPROB', 'D2Q06C', 'D6CUBE', 'DEGEN2', 'DEGEN3',
'ETAMACRO', 'FFFFF800', 'FINNIS', 'FIT1D', 'FIT1P', 'GANGES', 'DFL001', 'E226', 'ETAMACRO', 'FFFFF800', 'FINNIS', 'FIT1D',
'GFRD-PNC', 'GROW15', 'GROW22', 'GROW7', 'ISRAEL', 'KB2', 'LOTFI', 'FIT1P', 'FIT2D', 'FIT2P', 'GANGES', 'GFRD-PNC', 'GREENBEA',
'MAROS', 'MODSZK1', 'PEROLD', 'PILOT', 'PILOT-WE', 'PILOT4', 'GREENBEB', 'GROW15', 'GROW22', 'GROW7', 'ISRAEL', 'KB2', 'LOTFI',
'PILOTNOV', 'QAP8', 'RECIPE', 'SC105', 'SC205', 'SC50A', 'SC50B', 'MAROS', 'MAROS-R7', 'MODSZK1', 'PEROLD', 'PILOT', 'PILOT4',
'SCAGR25', 'SCAGR7', 'SCFXM1', 'SCFXM2', 'SCFXM3', 'SCORPION', 'PILOT87', 'PILOT-JA', 'PILOTNOV', 'PILOT-WE', 'QAP8', 'QAP12',
'SCRS8', 'SCSD1', 'SCSD6', 'SCSD8', 'SCTAP1', 'SCTAP2', 'SCTAP3', 'QAP15', 'RECIPE', 'SC105', 'SC205', 'SC50A', 'SC50B', 'SCAGR25',
'SHARE1B', 'SHARE2B', 'SHELL', 'SHIP04L', 'SHIP04S', 'SHIP08L', 'SCAGR7', 'SCFXM1', 'SCFXM2', 'SCFXM3', 'SCORPION', 'SCRS8',
'SHIP08S', 'SHIP12L', 'SHIP12S', 'SIERRA', 'STAIR', 'STANDATA', 'SCSD1', 'SCSD6', 'SCSD8', 'SCTAP1', 'SCTAP2', 'SCTAP3', 'SHARE1B',
'STANDMPS', 'STOCFOR1', 'STOCFOR2', 'TRUSS', 'TUFF', 'VTP-BASE', 'SHARE2B', 'SHELL', 'SHIP04L', 'SHIP04S', 'SHIP08L', 'SHIP08S',
'SHIP12L', 'SHIP12S', 'SIERRA', 'STAIR', 'STANDATA', 'STANDMPS',
'STOCFOR1', 'STOCFOR2', 'STOCFOR3', 'TRUSS', 'TUFF', 'VTP-BASE',
'WOOD1P', 'WOODW'] 'WOOD1P', 'WOODW']
presolve_problems = problems
rr_problems = ['AFIRO', 'BLEND', 'FINNIS', 'RECIPE', 'SCSD6', 'VTP-BASE',
'BORE3D', 'CYCLE', 'DEGEN2', 'DEGEN3', 'ETAMACRO', 'PILOTNOV',
'QAP8', 'RECIPE', 'SCORPION', 'SHELL', 'SIERRA', 'WOOD1P']
infeasible_problems = ['bgdbg1', 'bgetam', 'bgindy', 'bgprtr', 'box1', infeasible_problems = ['bgdbg1', 'bgetam', 'bgindy', 'bgprtr', 'box1',
'ceria3d', 'chemcom', 'cplex1', 'cplex2', 'ex72a', 'ceria3d', 'chemcom', 'cplex1', 'cplex2', 'ex72a',
'ex73a', 'forest6', 'galenet', 'gosh', 'gran', 'ex73a', 'forest6', 'galenet', 'gosh', 'gran',
'itest2', 'itest6', 'klein1', 'klein2', 'klein3', 'itest2', 'itest6', 'klein1', 'klein2', 'klein3',
'mondou2', 'pang', 'pilot4i', 'qual', 'reactor', 'mondou2', 'pang', 'pilot4i', 'qual', 'reactor',
'refinery', 'vol1', 'woodinfe'] 'refinery', 'vol1', 'woodinfe']
if not is_xslow(): if not is_xslow():
enabled_problems = ['ADLITTLE', 'AFIRO', 'BLEND', 'BEACONFD', 'GROW7', enabled_problems = ['ADLITTLE', 'AFIRO', 'BLEND', 'BEACONFD', 'GROW7',
'LOTFI', 'SC105', 'SCTAP1', 'SHARE2B', 'STOCFOR1'] 'LOTFI', 'SC105', 'SCTAP1', 'SHARE2B', 'STOCFOR1']
enabled_presolve_problems = enabled_problems
enabled_rr_problems = ['AFIRO', 'BLEND', 'FINNIS', 'RECIPE', 'SCSD6',
'VTP-BASE', 'DEGEN2', 'ETAMACRO', 'RECIPE']
enabled_infeasible_problems = ['bgdbg1', 'bgprtr', 'box1', 'chemcom', enabled_infeasible_problems = ['bgdbg1', 'bgprtr', 'box1', 'chemcom',
'cplex2', 'ex72a', 'ex73a', 'forest6', 'cplex2', 'ex72a', 'ex73a', 'forest6',
'galenet', 'itest2', 'itest6', 'klein1', 'galenet', 'itest2', 'itest6', 'klein1',
'refinery', 'woodinfe'] 'refinery', 'woodinfe']
else: else:
enabled_problems = problems enabled_problems = problems
enabled_presolve_problems = enabled_problems
enabled_rr_problems = rr_problems
enabled_infeasible_problems = infeasible_problems enabled_infeasible_problems = infeasible_problems
def klee_minty(D): def klee_minty(D):
A_1 = np.array([2**(i + 1) if i > 0 else 1 for i in range(D)]) A_1 = np.array([2**(i + 1) if i > 0 else 1 for i in range(D)])
A1_ = np.zeros(D) A1_ = np.zeros(D)
A1_[0] = 1 A1_[0] = 1
A_ub = toeplitz(A_1, A1_) A_ub = toeplitz(A_1, A1_)
b_ub = np.array([5**(i + 1) for i in range(D)]) b_ub = np.array([5**(i + 1) for i in range(D)])
c = -np.array([2**(D - i - 1) for i in range(D)]) c = -np.array([2**(D - i - 1) for i in range(D)])
xf = np.zeros(D) xf = np.zeros(D)
skipping to change at line 217 skipping to change at line 184
options=options) options=options)
self.fun = res.fun self.fun = res.fun
def track_netlib(self, meth, prob): def track_netlib(self, meth, prob):
if self.fun is None: if self.fun is None:
self.time_netlib(meth, prob) self.time_netlib(meth, prob)
self.abs_error = np.abs(self.fun - self.obj) self.abs_error = np.abs(self.fun - self.obj)
self.rel_error = np.abs((self.fun - self.obj)/self.obj) self.rel_error = np.abs((self.fun - self.obj)/self.obj)
return min(self.abs_error, self.rel_error) return min(self.abs_error, self.rel_error)
class Netlib_RR(Benchmark):
params = [
rr_methods,
rr_problems
]
param_names = ['method', 'problems']
# sparse routine returns incorrect matrix on BORE3D and PILOTNOV
# SVD fails (doesn't converge) on QAP8
known_fails = {('_remove_redundancy_svd', 'QAP8'),
('_remove_redundancy_pivot_sparse', 'BORE3D'),
('_remove_redundancy_pivot_sparse', 'PILOTNOV')}
def setup(self, meth, prob):
if prob not in enabled_rr_problems:
raise NotImplementedError("skipped")
if (meth.__name__, prob) in self.known_fails:
raise NotImplementedError("Known issues with these benchmarks.")
dir_path = os.path.dirname(os.path.realpath(__file__))
datafile = os.path.join(dir_path, "linprog_benchmark_files",
prob + ".npz")
data = np.load(datafile, allow_pickle=True)
c, A_eq, A_ub, b_ub, b_eq = (data["c"], data["A_eq"], data["A_ub"],
data["b_ub"], data["b_eq"])
bounds = np.squeeze(data["bounds"])
x0 = np.zeros(c.shape)
lp = _LPProblem(c, A_ub, b_ub, A_eq, b_eq, bounds, x0)
lp_cleaned = _clean_inputs(lp)
# rr_method is None here because we're not using RR
res = _presolve(lp_cleaned, rr=False, rr_method=None, tol=1e-9)[0]
self.A_eq, self.b_eq = res.A_eq, res.b_eq
self.true_rank = np.linalg.matrix_rank(self.A_eq)
if meth == _remove_redundancy_pivot_sparse:
self.A_eq = csc_matrix(self.A_eq)
self.rr_A = None
def time_netlib_rr(self, meth, prob):
self.rr_A, b, status, message = meth(self.A_eq, self.b_eq)
def track_netlib_rr(self, meth, prob):
if self.rr_A is None:
self.time_netlib_rr(meth, prob)
if meth == _remove_redundancy_pivot_sparse:
self.rr_A = self.rr_A.todense()
rr_rank = np.linalg.matrix_rank(self.rr_A)
rr_rows = self.rr_A.shape[0]
self.error1 = rr_rank - self.true_rank
self.error2 = rr_rows - self.true_rank
if abs(self.error1) > abs(self.error2):
return float(self.error1)
else:
return float(self.error2)
class Netlib_presolve(Benchmark):
params = [
presolve_methods,
presolve_problems
]
param_names = ['method', 'problems']
def setup(self, meth, prob):
if prob not in enabled_presolve_problems:
raise NotImplementedError("skipped")
dir_path = os.path.dirname(os.path.realpath(__file__))
datafile = os.path.join(dir_path, "linprog_benchmark_files",
prob + ".npz")
data = np.load(datafile, allow_pickle=True)
c, A_eq, A_ub, b_ub, b_eq = (data["c"], data["A_eq"], data["A_ub"],
data["b_ub"], data["b_eq"])
bounds = np.squeeze(data["bounds"])
x0 = np.zeros(c.shape)
if meth == "sparse":
A_eq = csr_matrix(A_eq)
A_ub = csr_matrix(A_ub)
lp = _LPProblem(c, A_ub, b_ub, A_eq, b_eq, bounds, x0)
self.lp_cleaned = _clean_inputs(lp)
def time_netlib_presolve(self, meth, prob):
_presolve(self.lp_cleaned, rr=False, rr_method=None, tol=1e-9)
class Netlib_infeasible(Benchmark): class Netlib_infeasible(Benchmark):
params = [ params = [
methods, methods,
infeasible_problems infeasible_problems
] ]
param_names = ['method', 'problems'] param_names = ['method', 'problems']
def setup(self, meth, prob): def setup(self, meth, prob):
if prob not in enabled_infeasible_problems: if prob not in enabled_infeasible_problems:
raise NotImplementedError("skipped") raise NotImplementedError("skipped")
 End of changes. 8 change blocks. 
139 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)