Skip to content

Commit 210ab45

Browse files
committed
improved docstring checking + first round of fixes
1 parent 8bd36ee commit 210ab45

9 files changed

Lines changed: 146 additions & 117 deletions

File tree

control/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ def use_legacy_defaults(version):
381381
# exception is raised.
382382
#
383383
def _process_legacy_keyword(kwargs, oldkey, newkey, newval):
384-
if kwargs.get(oldkey) is not None:
384+
if oldkey in kwargs:
385385
warnings.warn(
386386
f"keyword '{oldkey}' is deprecated; use '{newkey}'",
387387
FutureWarning)

control/flatsys/flatsys.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .poly import PolyFamily
1010
from .systraj import SystemTrajectory
1111
from ..exception import ControlArgument
12+
from ..config import _process_legacy_keyword
1213
from ..nlsys import NonlinearIOSystem
1314
from ..timeresp import _check_convert_array
1415

@@ -315,7 +316,7 @@ def point_to_point(
315316
316317
Parameters
317318
----------
318-
flatsys : FlatSystem object
319+
sys : FlatSystem object
319320
Description of the differentially flat system. This object must
320321
define a function `flatsys.forward()` that takes the system state and
321322
produceds the flag of flat outputs and a system `flatsys.reverse()`
@@ -364,6 +365,20 @@ def point_to_point(
364365
365366
The constraints are applied at each time point along the trajectory.
366367
368+
initial_guess : 2D array_like, optional
369+
Initial guess for the trajectory coefficients (not implemented).
370+
371+
params : dict, optional
372+
Parameter values for the system. Passed to the evaluation
373+
functions for the system as default values, overriding internal
374+
defaults.
375+
376+
minimize_method : str, optional
377+
Set the method used by :func:`scipy.optimize.minimize`.
378+
379+
minimize_options : str, optional
380+
Set the options keyword used by :func:`scipy.optimize.minimize`.
381+
367382
minimize_kwargs : str, optional
368383
Pass additional keywords to :func:`scipy.optimize.minimize`.
369384
@@ -399,9 +414,8 @@ def point_to_point(
399414
T0 = timepts[0] if len(timepts) > 1 else T0
400415

401416
# Process keyword arguments
402-
if trajectory_constraints is None:
403-
# Backwards compatibility
404-
trajectory_constraints = kwargs.pop('constraints', None)
417+
trajectory_constraints = _process_legacy_keyword(
418+
kwargs, 'constraints', 'trajectory_constraints', trajectory_constraints)
405419

406420
minimize_kwargs = {}
407421
minimize_kwargs['method'] = kwargs.pop('minimize_method', None)
@@ -632,7 +646,7 @@ def solve_flat_ocp(
632646
633647
Parameters
634648
----------
635-
flatsys : FlatSystem object
649+
sys : FlatSystem object
636650
Description of the differentially flat system. This object must
637651
define a function `flatsys.forward()` that takes the system state and
638652
produceds the flag of flat outputs and a system `flatsys.reverse()`
@@ -684,6 +698,17 @@ def solve_flat_ocp(
684698
initial_guess : 2D array_like, optional
685699
Initial guess for the optimal trajectory of the flat outputs.
686700
701+
params : dict, optional
702+
Parameter values for the system. Passed to the evaluation
703+
functions for the system as default values, overriding internal
704+
defaults.
705+
706+
minimize_method : str, optional
707+
Set the method used by :func:`scipy.optimize.minimize`.
708+
709+
minimize_options : str, optional
710+
Set the options keyword used by :func:`scipy.optimize.minimize`.
711+
687712
minimize_kwargs : str, optional
688713
Pass additional keywords to :func:`scipy.optimize.minimize`.
689714
@@ -724,12 +749,10 @@ def solve_flat_ocp(
724749
T0 = timepts[0] if len(timepts) > 1 else 0
725750

726751
# Process keyword arguments
727-
if trajectory_constraints is None:
728-
# Backwards compatibility
729-
trajectory_constraints = kwargs.pop('constraints', None)
730-
if trajectory_cost is None:
731-
# Compatibility with point_to_point
732-
trajectory_cost = kwargs.pop('cost', None)
752+
trajectory_constraints = _process_legacy_keyword(
753+
kwargs, 'constraints', 'trajectory_constraints', trajectory_constraints)
754+
trajectory_cost = _process_legacy_keyword(
755+
kwargs, 'cost', 'trajectory_cost', trajectory_cost)
733756

734757
minimize_kwargs = {}
735758
minimize_kwargs['method'] = kwargs.pop('minimize_method', None)

control/iosys.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ def update_names(self, **kwargs):
558558
Description of output signals; defaults to `y[i]`.
559559
states : int, list of str, int, or None, optional
560560
Description of system states; defaults to `x[i]`.
561+
input_prefix : string, optional
562+
Set the prefix for input signals. Default = 'u'.
563+
output_prefix : string, optional
564+
Set the prefix for output signals. Default = 'y'.
565+
state_prefix : string, optional
566+
Set the prefix for state signals. Default = 'x'.
561567
562568
"""
563569
self.name = kwargs.pop('name', self.name)

control/lti.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def bandwidth(self, dbdrop=-3):
153153
154154
Parameters
155155
----------
156-
dpdrop : float, optional
156+
dbdrop : float, optional
157157
A strictly negative scalar in dB (default = -3) defines the
158158
amount of gain drop for deciding bandwidth.
159159

control/nlsys.py

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -462,30 +462,7 @@ def output(self, t, x, u, params=None):
462462
t, np.asarray(x).reshape(-1), np.asarray(u).reshape(-1))
463463

464464
def feedback(self, other=1, sign=-1, params=None):
465-
"""Feedback interconnection between two input/output systems
466-
467-
Parameters
468-
----------
469-
sys1: InputOutputSystem
470-
The primary process.
471-
sys2: InputOutputSystem
472-
The feedback process (often a feedback controller).
473-
sign: scalar, optional
474-
The sign of feedback. `sign` = -1 indicates negative feedback,
475-
and `sign` = 1 indicates positive feedback. `sign` is an optional
476-
argument; it assumes a value of -1 if not specified.
477-
478-
Returns
479-
-------
480-
out: InputOutputSystem
481-
482-
Raises
483-
------
484-
ValueError
485-
if the inputs, outputs, or timebases of the systems are
486-
incompatible.
487-
488-
"""
465+
"""Feedback interconnection between two input/output systems."""
489466
# Convert sys2 to an I/O system if needed
490467
other = _convert_static_iosystem(other)
491468

@@ -1045,11 +1022,10 @@ def set_output_map(self, output_map):
10451022
self.noutputs = output_map.shape[0]
10461023

10471024
def unused_signals(self):
1048-
"""Find unused subsystem inputs and outputs
1025+
"""Find unused subsystem inputs and outputs.
10491026
10501027
Returns
10511028
-------
1052-
10531029
unused_inputs : dict
10541030
A mapping from tuple of indices (isys, isig) to string
10551031
'{sys}.{sig}', for all unused subsystem inputs.
@@ -1083,6 +1059,7 @@ def unused_signals(self):
10831059
return ({inputs[i][:2]: inputs[i][2] for i in unused_sysinp},
10841060
{outputs[i][:2]: outputs[i][2] for i in unused_sysout})
10851061

1062+
10861063
def connection_table(self, show_names=False, column_width=32):
10871064
"""Print table of connections inside an interconnected system model.
10881065
@@ -1183,6 +1160,8 @@ def _find_outputs_by_basename(self, basename):
11831160
for sig, isig in sys.output_index.items()
11841161
if sig == (basename)}
11851162

1163+
# TODO: change `warning` to `print_warning` or `warn_unsed`?
1164+
# TODO: change to internal function? (not sure users need to see this)
11861165
def check_unused_signals(
11871166
self, ignore_inputs=None, ignore_outputs=None, warning=True):
11881167
"""Check for unused subsystem inputs and outputs
@@ -1207,6 +1186,9 @@ def check_unused_signals(
12071186
If the 'sig' form is used, all subsystem outputs with that
12081187
name are considered ignored.
12091188
1189+
warning : bool, optional
1190+
If `True`, print a warning listing any unused signals.
1191+
12101192
Returns
12111193
-------
12121194
dropped_inputs: list of tuples

control/optimal.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ def _simulate_states(self, x0, inputs):
748748
#
749749

750750
# Compute the optimal trajectory from the current state
751+
# TODO: update docstring to refer to primary function (?)
751752
def compute_trajectory(
752753
self, x, squeeze=None, transpose=None, return_states=True,
753754
initial_guess=None, print_summary=True, **kwargs):
@@ -757,6 +758,14 @@ def compute_trajectory(
757758
----------
758759
x : array-like or number, optional
759760
Initial state for the system.
761+
initial_guess : (tuple of) 1D or 2D array_like
762+
Initial states and/or inputs to use as a guess for the optimal
763+
trajectory. For shooting methods, an array of inputs for each
764+
time point should be specified. For collocation methods, the
765+
initial guess is either the input vector or a tuple consisting
766+
guesses for the state and the input. Guess should either be a
767+
2D vector of shape (ninputs, ntimepts) or a 1D input of shape
768+
(ninputs,) that will be broadcast by extension of the time axis.
760769
return_states : bool, optional
761770
If True (default), return the values of the state at each time.
762771
squeeze : bool, optional
@@ -768,6 +777,9 @@ def compute_trajectory(
768777
If True, assume that 2D input arrays are transposed from the
769778
standard format. Used to convert MATLAB-style inputs to our
770779
format.
780+
print_summary : bool, optional
781+
If `True` (default), print a short summary of the computation.
782+
771783
772784
Returns
773785
-------

control/statesp.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -863,20 +863,11 @@ def horner(self, x, warn_infinite=True):
863863
Expects inputs and outputs to be formatted correctly. Use ``sys(x)``
864864
for a more user-friendly interface.
865865
866-
Parameters
867-
----------
868-
x : complex array_like or complex
869-
Complex frequencies
870-
871-
Returns
872-
-------
873-
output : (self.noutputs, self.ninputs, len(x)) complex ndarray
874-
Frequency response
875-
876866
Notes
877867
-----
878-
Attempts to use Laub's method from Slycot library, with a
879-
fall-back to python code.
868+
Attempts to use Laub's method from Slycot library, with a fall-back
869+
to Python code.
870+
880871
"""
881872
# Make sure the argument is a 1D array of complex numbers
882873
x_arr = np.atleast_1d(x).astype(complex, copy=False)
@@ -1390,8 +1381,9 @@ def dcgain(self, warn_infinite=False):
13901381
"""
13911382
return self._dcgain(warn_infinite)
13921383

1384+
# TODO: decide if we need this function (already in NonlinearIOSystem
13931385
def dynamics(self, t, x, u=None, params=None):
1394-
"""Compute the dynamics of the system
1386+
"""Compute the dynamics of the system.
13951387
13961388
Given input `u` and state `x`, returns the dynamics of the state-space
13971389
system. If the system is continuous, returns the time derivative dx/dt
@@ -1439,6 +1431,7 @@ def dynamics(self, t, x, u=None, params=None):
14391431
return (self.A @ x).reshape((-1,)) \
14401432
+ (self.B @ u).reshape((-1,)) # return as row vector
14411433

1434+
# TODO: decide if we need this function (already in NonlinearIOSystem
14421435
def output(self, t, x, u=None, params=None):
14431436
"""Compute the output of the system
14441437

0 commit comments

Comments
 (0)