Skip to content

Commit b47ed08

Browse files
authored
change default value of statesp.remove_useless_states to False (#509)
1 parent ad0a0eb commit b47ed08

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

control/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,7 @@ def use_legacy_defaults(version):
226226
linearized_system_name_prefix='',
227227
linearized_system_name_suffix='_linearized')
228228

229+
# turned off _remove_useless_states
230+
set_defaults('statesp', remove_useless_states=True)
231+
229232
return (major, minor, patch)

control/statesp.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
# Define module default parameter values
7373
_statesp_defaults = {
7474
'statesp.use_numpy_matrix': False, # False is default in 0.9.0 and above
75-
'statesp.remove_useless_states': True,
75+
'statesp.remove_useless_states': False,
7676
'statesp.latex_num_format': '.3g',
7777
'statesp.latex_repr_type': 'partitioned',
7878
}
@@ -217,8 +217,7 @@ class StateSpace(LTI):
217217
__array_priority__ = 11 # override ndarray and matrix types
218218

219219
def __init__(self, *args, **kwargs):
220-
"""
221-
StateSpace(A, B, C, D[, dt])
220+
"""StateSpace(A, B, C, D[, dt])
222221
223222
Construct a state space object.
224223
@@ -228,6 +227,13 @@ def __init__(self, *args, **kwargs):
228227
True for unspecified sampling time). To call the copy constructor,
229228
call StateSpace(sys), where sys is a StateSpace object.
230229
230+
The `remove_useless_states` keyword can be used to scan the A, B, and
231+
C matrices for rows or columns of zeros. If the zeros are such that a
232+
particular state has no effect on the input-output dynamics, then that
233+
state is removed from the A, B, and C matrices. If not specified, the
234+
value is read from `config.defaults['statesp.remove_useless_states']
235+
(default = False).
236+
231237
"""
232238
# first get A, B, C, D matrices
233239
if len(args) == 4:
@@ -251,8 +257,8 @@ def __init__(self, *args, **kwargs):
251257
"Expected 1, 4, or 5 arguments; received %i." % len(args))
252258

253259
# Process keyword arguments
254-
remove_useless = kwargs.get(
255-
'remove_useless',
260+
remove_useless_states = kwargs.get(
261+
'remove_useless_states',
256262
config.defaults['statesp.remove_useless_states'])
257263

258264
# Convert all matrices to standard form
@@ -321,7 +327,7 @@ def __init__(self, *args, **kwargs):
321327
raise ValueError("C and D must have the same number of rows.")
322328

323329
# Check for states that don't do anything, and remove them.
324-
if remove_useless:
330+
if remove_useless_states:
325331
self._remove_useless_states()
326332

327333
def _remove_useless_states(self):
@@ -1274,7 +1280,7 @@ def _convert_to_statespace(sys, **kw):
12741280
# Generate a simple state space system of the desired dimension
12751281
# The following Doesn't work due to inconsistencies in ltisys:
12761282
# return StateSpace([[]], [[]], [[]], eye(outputs, inputs))
1277-
return StateSpace(0., zeros((1, inputs)), zeros((outputs, 1)),
1283+
return StateSpace([], zeros((0, inputs)), zeros((outputs, 0)),
12781284
sys * ones((outputs, inputs)))
12791285

12801286
# If this is a matrix, try to create a constant feedthrough

control/tests/statesp_test.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,7 @@ def test_is_static_gain(self):
395395
D0 = 0
396396
D1 = np.ones((2,1))
397397
assert StateSpace(A0, B0, C1, D1).is_static_gain()
398-
# TODO: fix this once remove_useless_states is false by default
399-
# should be False when remove_useless is false
400-
# print(StateSpace(A1, B0, C1, D1).is_static_gain())
398+
assert not StateSpace(A1, B0, C1, D1).is_static_gain()
401399
assert not StateSpace(A0, B1, C1, D1).is_static_gain()
402400
assert not StateSpace(A1, B1, C1, D1).is_static_gain()
403401
assert StateSpace(A0, B0, C0, D0).is_static_gain()
@@ -586,10 +584,9 @@ def test_matrix_static_gain(self):
586584

587585
def test_remove_useless_states(self):
588586
"""Regression: _remove_useless_states gives correct ABC sizes."""
589-
g1 = StateSpace(np.zeros((3, 3)),
590-
np.zeros((3, 4)),
591-
np.zeros((5, 3)),
592-
np.zeros((5, 4)))
587+
g1 = StateSpace(np.zeros((3, 3)), np.zeros((3, 4)),
588+
np.zeros((5, 3)), np.zeros((5, 4)),
589+
remove_useless_states=True)
593590
assert (0, 0) == g1.A.shape
594591
assert (0, 4) == g1.B.shape
595592
assert (5, 0) == g1.C.shape

0 commit comments

Comments
 (0)