Skip to content

Commit 9509dfd

Browse files
authored
Merge pull request #955 from murrayrm/fixwarnings-23Dec2023
Fix CI warnings
2 parents eb0f3f9 + dc74493 commit 9509dfd

File tree

13 files changed

+62
-41
lines changed

13 files changed

+62
-41
lines changed

control/flatsys/linflat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ def forward(self, x, u, params):
119119
x = np.reshape(x, (-1, 1))
120120
u = np.reshape(u, (1, -1))
121121
zflag = [np.zeros(self.nstates + 1)]
122-
zflag[0][0] = self.Cf @ x
122+
zflag[0][0] = (self.Cf @ x).item()
123123
H = self.Cf # initial state transformation
124124
for i in range(1, self.nstates + 1):
125-
zflag[0][i] = H @ (self.A @ x + self.B @ u)
125+
zflag[0][i] = (H @ (self.A @ x + self.B @ u)).item()
126126
H = H @ self.A # derivative for next iteration
127127
return zflag
128128

control/freqplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def bode_plot(
473473
if ax is None:
474474
with plt.rc_context(_freqplot_rcParams):
475475
ax_array = fig.subplots(nrows, ncols, squeeze=False)
476-
fig.set_tight_layout(True)
476+
fig.set_layout_engine('tight')
477477
fig.align_labels()
478478

479479
# Set up default sharing of axis limits if not specified

control/optimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def solve_ocp(
956956
transpose=None, return_states=True, print_summary=True, log=False,
957957
**kwargs):
958958

959-
"""Compute the solution to an optimal control problem.
959+
r"""Compute the solution to an optimal control problem.
960960
961961
The optimal trajectory (states and inputs) is computed so as to
962962
approximately mimimize a cost function of the following form (for

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
@@ -228,7 +228,11 @@ def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
228228
sys_closed = append(sys, -K)
229229
connects = [[1, 3],
230230
[3, 1]]
231-
sys_closed = connect(sys_closed, connects, 2, 2)
231+
# Filter out known warning due to use of connect
232+
with warnings.catch_warnings():
233+
warnings.filterwarnings(
234+
'ignore', message="`connect`", category=DeprecationWarning)
235+
sys_closed = connect(sys_closed, connects, 2, 2)
232236
if tvect is None:
233237
tvect, yout = step_response(sys_closed, T_num=100)
234238
else:

control/stochsys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,14 @@ def lqe(*args, **kwargs):
183183

184184
# contributed by Sawyer B. Fuller <minster@uw.edu>
185185
def dlqe(*args, **kwargs):
186-
"""dlqe(A, G, C, QN, RN, [, N])
186+
r"""dlqe(A, G, C, QN, RN, [, N])
187187
188188
Linear quadratic estimator design (Kalman filter) for discrete-time
189189
systems. Given the system
190190
191191
.. math::
192192
193-
x[n+1] &= Ax[n] + Bu[n] + Gw[n] \\\\
193+
x[n+1] &= Ax[n] + Bu[n] + Gw[n] \\
194194
y[n] &= Cx[n] + Du[n] + v[n]
195195
196196
with unbiased process noise w and measurement noise v with covariances

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy