Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix CI warnings#955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
murrayrm merged 4 commits intopython-control:mainfrommurrayrm:fixwarnings-23Dec2023
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionscontrol/flatsys/linflat.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -119,10 +119,10 @@ def forward(self, x, u, params):
x = np.reshape(x, (-1, 1))
u = np.reshape(u, (1, -1))
zflag = [np.zeros(self.nstates + 1)]
zflag[0][0] = self.Cf @ x
zflag[0][0] =(self.Cf @ x).item()
H = self.Cf # initial state transformation
for i in range(1, self.nstates + 1):
zflag[0][i] = H @ (self.A @ x + self.B @ u)
zflag[0][i] =(H @ (self.A @ x + self.B @ u)).item()
H = H @ self.A # derivative for next iteration
return zflag

Expand Down
2 changes: 1 addition & 1 deletioncontrol/freqplot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -473,7 +473,7 @@ def bode_plot(
if ax is None:
with plt.rc_context(_freqplot_rcParams):
ax_array = fig.subplots(nrows, ncols, squeeze=False)
fig.set_tight_layout(True)
fig.set_layout_engine('tight')
fig.align_labels()

# Set up default sharing of axis limits if not specified
Expand Down
2 changes: 1 addition & 1 deletioncontrol/optimal.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -956,7 +956,7 @@ def solve_ocp(
transpose=None, return_states=True, print_summary=True, log=False,
**kwargs):

"""Compute the solution to an optimal control problem.
r"""Compute the solution to an optimal control problem.

The optimal trajectory (states and inputs) is computed so as to
approximately mimimize a cost function of the following form (for
Expand Down
8 changes: 7 additions & 1 deletioncontrol/robust.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,6 +41,7 @@

# External packages and modules
import numpy as np
import warnings
from .exception import *
from .statesp import StateSpace
from .statefbk import *
Expand DownExpand Up@@ -357,7 +358,12 @@ def augw(g, w1=None, w2=None, w3=None):
# output indices
oi = np.arange(1, 1 + now1 + now2 + now3 + ny)

p = connect(sysall, q, ii, oi)
# Filter out known warning due to use of connect
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message="`connect`", category=DeprecationWarning)

p = connect(sysall, q, ii, oi)

return p

Expand Down
6 changes: 5 additions & 1 deletioncontrol/sisotool.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,7 +186,11 @@ def _SisotoolUpdate(sys, fig, K, bode_plot_params, tvect=None):
sys_closed = append(sys, -K)
connects = [[1, 3],
[3, 1]]
sys_closed = connect(sys_closed, connects, 2, 2)
# Filter out known warning due to use of connect
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message="`connect`", category=DeprecationWarning)
sys_closed = connect(sys_closed, connects, 2, 2)
if tvect is None:
tvect, yout = step_response(sys_closed, T_num=100)
else:
Expand Down
4 changes: 2 additions & 2 deletionscontrol/stochsys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -183,14 +183,14 @@ def lqe(*args, **kwargs):

# contributed by Sawyer B. Fuller <minster@uw.edu>
def dlqe(*args, **kwargs):
"""dlqe(A, G, C, QN, RN, [, N])
r"""dlqe(A, G, C, QN, RN, [, N])

Linear quadratic estimator design (Kalman filter) for discrete-time
systems. Given the system

.. math::

x[n+1] &= Ax[n] + Bu[n] + Gw[n] \\\\
x[n+1] &= Ax[n] + Bu[n] + Gw[n] \\
y[n] &= Cx[n] + Du[n] + v[n]

with unbiased process noise w and measurement noise v with covariances
Expand Down
19 changes: 11 additions & 8 deletionscontrol/tests/flatsys_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -194,14 +194,17 @@ def test_kinematic_car_ocp(
else:
initial_guess = None

# Solve the optimal trajectory
traj_ocp = fs.solve_flat_ocp(
vehicle_flat, timepts, x0, u0,
cost=traj_cost, constraints=input_constraints,
terminal_cost=terminal_cost, basis=basis,
initial_guess=initial_guess,
minimize_kwargs={'method': method},
)
# Solve the optimal trajectory (allow warnings)
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message="unable to solve", category=UserWarning)
traj_ocp = fs.solve_flat_ocp(
vehicle_flat, timepts, x0, u0,
cost=traj_cost, constraints=input_constraints,
terminal_cost=terminal_cost, basis=basis,
initial_guess=initial_guess,
minimize_kwargs={'method': method},
)
xd, ud = traj_ocp.eval(timepts)

if not traj_ocp.success:
Expand Down
28 changes: 14 additions & 14 deletionscontrol/tests/freqresp_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,7 +16,8 @@
from control.statesp import StateSpace
from control.xferfcn import TransferFunction
from control.matlab import ss, tf, bode, rss
from control.freqplot import bode_plot, nyquist_plot, singular_values_plot
from control.freqplot import bode_plot, nyquist_plot, nyquist_response, \
singular_values_plot, singular_values_response
from control.tests.conftest import slycotonly

pytestmark = pytest.mark.usefixtures("mplcleanup")
Expand DownExpand Up@@ -97,19 +98,17 @@ def test_nyquist_basic(ss_siso):
tf_siso = tf(ss_siso)
nyquist_plot(ss_siso)
nyquist_plot(tf_siso)
count, contour = nyquist_plot(
tf_siso, plot=False, return_contour=True, omega_num=20)
assert len(contour) == 20
response = nyquist_response(tf_siso, omega_num=20)
assert len(response.contour) == 20

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

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


@pytest.mark.usefixtures("legacy_plot_signature")
Expand DownExpand Up@@ -200,7 +199,7 @@ def test_bode_margin(dB, maginfty1, maginfty2, gminv,
den = [1, 25, 100, 0]
sys = ctrl.tf(num, den)
plt.figure()
ctrl.bode_plot(sys,margins=True, dB=dB, deg=deg, Hz=Hz)
ctrl.bode_plot(sys,display_margins=True, dB=dB, deg=deg, Hz=Hz)
fig = plt.gcf()
allaxes = fig.get_axes()

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


def test_singular_values_plot_mpl_base(ss_mimo_ct, ss_mimo_dt):
sys_ct = ss_mimo_ct.sys
sys_dt = ss_mimo_dt.sys
plt.figure()
singular_values_plot(sys_ct, plot=True)
singular_values_plot(sys_ct)
fig = plt.gcf()
allaxes = fig.get_axes()
assert(len(allaxes) == 1)
assert(allaxes[0].get_label() == 'control-sigma')
plt.figure()
singular_values_plot([sys_ct, sys_dt],plot=True,Hz=True, dB=True, grid=False)
singular_values_plot([sys_ct, sys_dt], Hz=True, dB=True, grid=False)
fig = plt.gcf()
allaxes = fig.get_axes()
assert(len(allaxes) == 1)
Expand All@@ -679,10 +679,10 @@ def test_singular_values_plot_mpl_base(ss_mimo_ct, ss_mimo_dt):
def test_singular_values_plot_mpl_superimpose_nyq(ss_mimo_ct, ss_mimo_dt):
sys_ct = ss_mimo_ct.sys
sys_dt = ss_mimo_dt.sys
omega_all = np.logspace(-3,2, 1000)
omega_all = np.logspace(-3,int(math.log10(2 * math.pi/sys_dt.dt)), 1000)
plt.figure()
singular_values_plot(sys_ct, omega_all, plot=True)
singular_values_plot(sys_dt, omega_all, plot=True)
singular_values_plot(sys_ct, omega_all)
singular_values_plot(sys_dt, omega_all)
fig = plt.gcf()
allaxes = fig.get_axes()
assert(len(allaxes) == 1)
Expand Down
15 changes: 9 additions & 6 deletionscontrol/tests/optimal_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -745,12 +745,15 @@ def vehicle_output(t, x, u, params):
initial_guess = (state_guess, input_guess)

# Solve the optimal control problem
result = opt.solve_ocp(
vehicle, timepts, x0, traj_cost, constraints,
terminal_cost=term_cost, initial_guess=initial_guess,
trajectory_method=method,
# minimize_method='COBYLA', # SLSQP',
)
with warnings.catch_warnings():
warnings.filterwarnings(
'ignore', message="unable to solve", category=UserWarning)
result = opt.solve_ocp(
vehicle, timepts, x0, traj_cost, constraints,
terminal_cost=term_cost, initial_guess=initial_guess,
trajectory_method=method,
# minimize_method='COBYLA', # SLSQP',
)

if fail == 'xfail':
assert not result.success
Expand Down
3 changes: 1 addition & 2 deletionscontrol/tests/sisotool_test.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,8 +79,7 @@ def test_sisotool(self, tsys):
'omega_limits': None,
'omega_num': None,
'ax': np.array([[ax_mag], [ax_phase]]),
'margins': True,
'margin_info': True,
'display_margins': 'overlay',
}

# Check that the xaxes of the bode plot are shared before the rlocus click
Expand Down
2 changes: 1 addition & 1 deletioncontrol/timeplot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -292,7 +292,7 @@ def time_response_plot(
if ax is None:
with plt.rc_context(timeplot_rcParams):
ax_array = fig.subplots(nrows, ncols, sharex=True, squeeze=False)
fig.set_tight_layout(True)
fig.set_layout_engine('tight')
fig.align_labels()

else:
Expand Down
2 changes: 1 addition & 1 deletioncontrol/timeresp.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1084,7 +1084,7 @@ def forced_response(sys, T=None, U=0., X0=0., transpose=False,
if U.ndim == 1:
U = U.reshape(1, -1) # pylint: disable=E1103

# Algorithm: to integrate from time 0 to time dt, with linear
# Algorithm: to integrate from time 0 to time dt, with linear
# interpolation between inputs u(0) = u0 and u(dt) = u1, we solve
# xdot = A x + B u, x(0) = x0
# udot = (u1 - u0) / dt, u(0) = u0.
Expand Down
8 changes: 7 additions & 1 deletioncontrol/xferfcn.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -468,7 +468,13 @@ def __str__(self, var=None):
numstr = _tf_polynomial_to_string(self.num[no][ni], var=var)
denstr = _tf_polynomial_to_string(self.den[no][ni], var=var)
elif self.display_format == 'zpk':
z, p, k = tf2zpk(self.num[no][ni], self.den[no][ni])
num = self.num[no][ni]
if num.size == 1 and num.item() == 0:
# Catch a special case that SciPy doesn't handle
z, p, k = tf2zpk([1.], self.den[no][ni])
k = 0
else:
z, p, k = tf2zpk(self.num[no][ni], self.den[no][ni])
numstr = _tf_factorized_polynomial_to_string(
z, gain=k, var=var)
denstr = _tf_factorized_polynomial_to_string(p, var=var)
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp