Skip to content

Commit cfccc28

Browse files
committed
update code/tests to remove expected warnings
1 parent af6e14b commit cfccc28

File tree

6 files changed

+47
-32
lines changed

6 files changed

+47
-32
lines changed

control/robust.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
# External packages and modules
4343
import numpy as np
44+
import warnings
4445
from .exception import *
4546
from .statesp import StateSpace
4647
from .statefbk import *
@@ -357,7 +358,12 @@ def augw(g, w1=None, w2=None, w3=None):
357358
# output indices
358359
oi = np.arange(1, 1 + now1 + now2 + now3 + ny)
359360

360-
p = connect(sysall, q, ii, oi)
361+
# Filter out known warning due to use of connect
362+
with warnings.catch_warnings():
363+
warnings.filterwarnings(
364+
'ignore', message="`connect`", category=DeprecationWarning)
365+
366+
p = connect(sysall, q, ii, oi)
361367

362368
return p
363369

control/sisotool.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
186186
sys_closed = append(sys, -K)
187187
connects = [[1, 3],
188188
[3, 1]]
189-
sys_closed = connect(sys_closed, connects, 2, 2)
189+
# Filter out known warning due to use of connect
190+
with warnings.catch_warnings():
191+
warnings.filterwarnings(
192+
'ignore', message="`connect`", category=DeprecationWarning)
193+
sys_closed = connect(sys_closed, connects, 2, 2)
190194
if tvect is None:
191195
tvect, yout = step_response(sys_closed, T_num=100)
192196
else:

control/tests/flatsys_test.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ def test_kinematic_car_ocp(
194194
else:
195195
initial_guess = None
196196

197-
# Solve the optimal trajectory
198-
traj_ocp = fs.solve_flat_ocp(
199-
vehicle_flat, timepts, x0, u0,
200-
cost=traj_cost, constraints=input_constraints,
201-
terminal_cost=terminal_cost, basis=basis,
202-
initial_guess=initial_guess,
203-
minimize_kwargs={'method': method},
204-
)
197+
# Solve the optimal trajectory (allow warnings)
198+
with warnings.catch_warnings():
199+
warnings.filterwarnings(
200+
'ignore', message="unable to solve", category=UserWarning)
201+
traj_ocp = fs.solve_flat_ocp(
202+
vehicle_flat, timepts, x0, u0,
203+
cost=traj_cost, constraints=input_constraints,
204+
terminal_cost=terminal_cost, basis=basis,
205+
initial_guess=initial_guess,
206+
minimize_kwargs={'method': method},
207+
)
205208
xd, ud = traj_ocp.eval(timepts)
206209

207210
if not traj_ocp.success:

control/tests/freqresp_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from control.statesp import StateSpace
1717
from control.xferfcn import TransferFunction
1818
from control.matlab import ss, tf, bode, rss
19-
from control.freqplot import bode_plot, nyquist_plot, singular_values_plot
19+
from control.freqplot import bode_plot, nyquist_plot, nyquist_response, \
20+
singular_values_plot, singular_values_response
2021
from control.tests.conftest import slycotonly
2122

2223
pytestmark = pytest.mark.usefixtures("mplcleanup")
@@ -97,19 +98,17 @@ def test_nyquist_basic(ss_siso):
9798
tf_siso = tf(ss_siso)
9899
nyquist_plot(ss_siso)
99100
nyquist_plot(tf_siso)
100-
count, contour = nyquist_plot(
101-
tf_siso, plot=False, return_contour=True, omega_num=20)
102-
assert len(contour) == 20
101+
response = nyquist_response(tf_siso, omega_num=20)
102+
assert len(response.contour) == 20
103103

104104
with pytest.warns(UserWarning, match="encirclements was a non-integer"):
105105
count, contour = nyquist_plot(
106106
tf_siso, plot=False, omega_limits=(1, 100), return_contour=True)
107107
assert_allclose(contour[0], 1j)
108108
assert_allclose(contour[-1], 100j)
109109

110-
count, contour = nyquist_plot(
111-
tf_siso, plot=False, omega=np.logspace(-1, 1, 10), return_contour=True)
112-
assert len(contour) == 10
110+
response = nyquist_response(tf_siso, omega=np.logspace(-1, 1, 10))
111+
assert len(response.contour) == 10
113112

114113

115114
@pytest.mark.usefixtures("legacy_plot_signature")
@@ -200,7 +199,7 @@ def test_bode_margin(dB, maginfty1, maginfty2, gminv,
200199
den = [1, 25, 100, 0]
201200
sys = ctrl.tf(num, den)
202201
plt.figure()
203-
ctrl.bode_plot(sys, margins=True, dB=dB, deg=deg, Hz=Hz)
202+
ctrl.bode_plot(sys, display_margins=True, dB=dB, deg=deg, Hz=Hz)
204203
fig = plt.gcf()
205204
allaxes = fig.get_axes()
206205

@@ -655,21 +654,22 @@ def tsystem(request, ss_mimo_ct, ss_miso_ct, ss_simo_ct, ss_siso_ct, ss_mimo_dt)
655654
def test_singular_values_plot(tsystem):
656655
sys = tsystem.sys
657656
for omega_ref, sigma_ref in zip(tsystem.omegas, tsystem.sigmas):
658-
sigma, _ = singular_values_plot(sys, omega_ref, plot=False)
657+
response = singular_values_response(sys, omega_ref)
658+
sigma = np.real(response.fresp[:, 0, :])
659659
np.testing.assert_almost_equal(sigma, sigma_ref)
660660

661661

662662
def test_singular_values_plot_mpl_base(ss_mimo_ct, ss_mimo_dt):
663663
sys_ct = ss_mimo_ct.sys
664664
sys_dt = ss_mimo_dt.sys
665665
plt.figure()
666-
singular_values_plot(sys_ct, plot=True)
666+
singular_values_plot(sys_ct)
667667
fig = plt.gcf()
668668
allaxes = fig.get_axes()
669669
assert(len(allaxes) == 1)
670670
assert(allaxes[0].get_label() == 'control-sigma')
671671
plt.figure()
672-
singular_values_plot([sys_ct, sys_dt], plot=True, Hz=True, dB=True, grid=False)
672+
singular_values_plot([sys_ct, sys_dt], Hz=True, dB=True, grid=False)
673673
fig = plt.gcf()
674674
allaxes = fig.get_axes()
675675
assert(len(allaxes) == 1)
@@ -679,10 +679,10 @@ def test_singular_values_plot_mpl_base(ss_mimo_ct, ss_mimo_dt):
679679
def test_singular_values_plot_mpl_superimpose_nyq(ss_mimo_ct, ss_mimo_dt):
680680
sys_ct = ss_mimo_ct.sys
681681
sys_dt = ss_mimo_dt.sys
682-
omega_all = np.logspace(-3, 2, 1000)
682+
omega_all = np.logspace(-3, int(math.log10(2 * math.pi/sys_dt.dt)), 1000)
683683
plt.figure()
684-
singular_values_plot(sys_ct, omega_all, plot=True)
685-
singular_values_plot(sys_dt, omega_all, plot=True)
684+
singular_values_plot(sys_ct, omega_all)
685+
singular_values_plot(sys_dt, omega_all)
686686
fig = plt.gcf()
687687
allaxes = fig.get_axes()
688688
assert(len(allaxes) == 1)

control/tests/optimal_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,15 @@ def vehicle_output(t, x, u, params):
745745
initial_guess = (state_guess, input_guess)
746746

747747
# Solve the optimal control problem
748-
result = opt.solve_ocp(
749-
vehicle, timepts, x0, traj_cost, constraints,
750-
terminal_cost=term_cost, initial_guess=initial_guess,
751-
trajectory_method=method,
752-
# minimize_method='COBYLA', # SLSQP',
753-
)
748+
with warnings.catch_warnings():
749+
warnings.filterwarnings(
750+
'ignore', message="unable to solve", category=UserWarning)
751+
result = opt.solve_ocp(
752+
vehicle, timepts, x0, traj_cost, constraints,
753+
terminal_cost=term_cost, initial_guess=initial_guess,
754+
trajectory_method=method,
755+
# minimize_method='COBYLA', # SLSQP',
756+
)
754757

755758
if fail == 'xfail':
756759
assert not result.success

control/tests/sisotool_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def test_sisotool(self, tsys):
7979
'omega_limits': None,
8080
'omega_num': None,
8181
'ax': np.array([[ax_mag], [ax_phase]]),
82-
'margins': True,
83-
'margin_info': True,
82+
'display_margins': 'overlay',
8483
}
8584

8685
# Check that the xaxes of the bode plot are shared before the rlocus click

0 commit comments

Comments
 (0)