Skip to content

Commit

Permalink
try tol = 1e-20
Browse files Browse the repository at this point in the history
  • Loading branch information
luk036 committed Dec 22, 2023
1 parent 357e660 commit a00f1e5
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion benches/test_lowpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run_lowpass(use_parallel_cut: bool, duration=0.000001):
omega, Spsq = create_lowpass_case(N)
options = Options()
options.max_iters = 20000
options.tol = 1e-8
options.tol = 1e-20
h, _, num_iters = cutting_plane_optim(omega, ellip, Spsq, options)
time.sleep(duration)
return num_iters, h is not None
Expand Down
2 changes: 1 addition & 1 deletion src/ellalgo/ell_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CutStatus(Enum):
# 1e-8 respectively.
class Options:
max_iters: int = 2000 # maximum number of iterations
tol: float = 1e-8 # error tolerance
tol: float = 1e-20 # error tolerance


# The `CInfo` class represents information about a computation, including whether it is feasible and
Expand Down
6 changes: 4 additions & 2 deletions tests/test_example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from ellalgo.cutting_plane import cutting_plane_optim
from ellalgo.cutting_plane import cutting_plane_optim, Options
from ellalgo.ell import Ell
from ellalgo.ell_typing import OracleFeas, OracleOptim

Expand Down Expand Up @@ -79,8 +79,10 @@ def test_case_feasible():
"""[summary]"""
xinit = np.array([0.0, 0.0]) # initial xinit
ellip = Ell(10.0, xinit)
options = Options()
options.tol = 1e-10
omega = MyOracle()
xbest, _, _ = cutting_plane_optim(omega, ellip, float("-inf"))
xbest, _, _ = cutting_plane_optim(omega, ellip, float("-inf"), options)
assert xbest is not None
# fmt = '{:f} {} {} {}'
# print(fmt.format(fbest, niter, feasible, status))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_lmi_lazy():
([type]): [description]
"""
result = run_lmi(LMIOracle)
assert result == 112
assert result == 281


def test_lmi_old():
Expand All @@ -105,4 +105,4 @@ def test_lmi_old():
([type]): [description]
"""
result = run_lmi(LMIOldOracle)
assert result == 112
assert result == 281
10 changes: 5 additions & 5 deletions tests/test_lowpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def run_lowpass(use_parallel_cut: bool, duration=0.000001):
N = 32
r0 = np.zeros(N) # initial xinit
r0[0] = 0
ellip = Ell(4.0, r0)
ellip = Ell(40.0, r0)
ellip._helper.use_parallel_cut = use_parallel_cut
omega, Spsq = create_lowpass_case(N)
options = Options()
options.max_iters = 20000
options.tol = 1e-8
options.max_iters = 50000
options.tol = 1e-14
h, _, num_iters = cutting_plane_optim(omega, ellip, Spsq, options)
time.sleep(duration)
return num_iters, h is not None
Expand All @@ -37,5 +37,5 @@ def test_lowpass():
"""Test the lowpass case with parallel cut"""
result, feasible = run_lowpass(True)
assert feasible
assert result >= 1075
assert result <= 1194
assert result >= 23000
assert result <= 24000
8 changes: 4 additions & 4 deletions tests/test_profit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ def run_profit_q(E):

def test_profit_ell():
num_iters = run_profit(Ell)
assert num_iters == 36
assert num_iters == 83


def test_profit_ell_stable():
num_iters = run_profit(EllStable)
assert num_iters == 36
assert num_iters == 83


def test_profit_rb_ell():
num_iters = run_profit_rb(Ell)
assert num_iters == 41
assert num_iters == 90


def test_profit_rb_ell_stable():
num_iters = run_profit_rb(EllStable)
assert num_iters == 41
assert num_iters == 90


def test_profit_q_ell():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_quasicvx.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_case_feasible():
omega = MyQuasicvxOracle()
xbest, _, niters = cutting_plane_optim(omega, ellip, 0.0)
assert xbest is not None
assert niters == 35
assert niters == 83
# assert fbest == approx(0.4288673396685956)
# assert xbest[0] * xbest[0] == approx(0.5029823096186075)
# assert math.exp(xbest[1]) == approx(1.6536872634520428)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_quasicvx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def test_case_feasible():
omega = MyQuasicvxOracle()
xbest, fbest, _ = cutting_plane_optim(omega, ellip, 0.0)
assert xbest is not None
assert fbest == approx(-0.4288673396685956)
assert xbest[0] == approx(0.5053830040042219)
assert xbest[1] == approx(1.6576289475891712)
assert fbest == approx(-0.42888194247600586)
assert xbest[0] == approx(0.5000004646814299)
assert xbest[1] == approx(1.6487220368468205)


def test_case_infeasible1():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_quasicvx_stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def test_case_feasible():
omega = MyQuasicvxOracle()
xbest, fbest, _ = cutting_plane_optim(omega, ellip, 0.0)
assert xbest is not None
assert fbest == approx(0.4288673396685956)
assert xbest[0] * xbest[0] == approx(0.5029823096186075)
assert math.exp(xbest[1]) == approx(1.6536872634520428)
assert fbest == approx(0.4288819424771711)
assert xbest[0] * xbest[0] == approx(0.5000021895211592)
assert math.exp(xbest[1]) == approx(1.6487248806185175)


def test_case_infeasible1():
Expand Down

0 comments on commit a00f1e5

Please sign in to comment.