Skip to content
Merged
Changes from 1 commit
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
Next Next commit
fix bug in namedio unit test that was treating static SS systems the …
…same as transfer functions. tests to track down missing names on some systems when converting to LinearIOSystem
  • Loading branch information
sawyerbfuller committed Apr 17, 2023
commit 78f5aec6f35b69d33584da3ce4830e7eced2f7c5
28 changes: 24 additions & 4 deletions control/tests/namedio_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ def test_named_ss():
(lambda t, x, u, params: -x, None),
{'inputs': 2, 'outputs':2, 'states':2}],
[ct.ss, ([[1, 2], [3, 4]], [[0], [1]], [[1, 0]], 0), {}],
[ct.ss, ([], [], [], 3), {}], # static system
[ct.StateSpace, ([[1, 2], [3, 4]], [[0], [1]], [[1, 0]], 0), {}],
[ct.tf, ([1, 2], [3, 4, 5]), {}],
[ct.tf, (2, 3), {}], # static system
[ct.TransferFunction, ([1, 2], [3, 4, 5]), {}],
])
def test_io_naming(fun, args, kwargs):
Expand All @@ -112,7 +114,7 @@ def test_io_naming(fun, args, kwargs):
assert sys_g.name == 'sys[0]'
assert sys_g.input_labels == [f'u[{i}]' for i in range(sys_g.ninputs)]
assert sys_g.output_labels == [f'y[{i}]' for i in range(sys_g.noutputs)]
if sys_g.nstates:
if sys_g.nstates is not None:
assert sys_g.state_labels == [f'x[{i}]' for i in range(sys_g.nstates)]

#
Expand All @@ -128,7 +130,7 @@ def test_io_naming(fun, args, kwargs):
sys_r.set_outputs(output_labels)
assert sys_r.output_labels == output_labels

if sys_g.nstates:
if sys_g.nstates is not None:
state_labels = [f'x{i}' for i in range(sys_g.nstates)]
sys_r.set_states(state_labels)
assert sys_r.state_labels == state_labels
Expand All @@ -143,7 +145,7 @@ def test_io_naming(fun, args, kwargs):
sys_k = fun(state_labels, output_labels, input_labels, name='mysys')

elif sys_g.nstates is None:
# Don't pass state labels
# Don't pass state labels if TransferFunction
sys_k = fun(
*args, inputs=input_labels, outputs=output_labels, name='mysys')

Expand All @@ -155,7 +157,7 @@ def test_io_naming(fun, args, kwargs):
assert sys_k.name == 'mysys'
assert sys_k.input_labels == input_labels
assert sys_k.output_labels == output_labels
if sys_g.nstates:
if sys_g.nstates is not None:
assert sys_k.state_labels == state_labels

#
Expand Down Expand Up @@ -193,6 +195,24 @@ def test_io_naming(fun, args, kwargs):
assert sys_tf.input_labels == input_labels
assert sys_tf.output_labels == output_labels

#
# Convert the system to a LinearIOSystem and make sure labels transfer
#
if not isinstance(
sys_r, (ct.FrequencyResponseData, ct.NonlinearIOSystem)) and \
ct.slycot_check():
sys_lio = ct.LinearIOSystem(sys_r)
assert sys_lio != sys_r
assert sys_lio.input_labels == input_labels
assert sys_lio.output_labels == output_labels

# Reassign system and signal names
sys_lio = ct.LinearIOSystem(
sys_g, inputs=input_labels, outputs=output_labels, name='new')
assert sys_lio.name == 'new'
assert sys_lio.input_labels == input_labels
assert sys_lio.output_labels == output_labels


# Internal testing of StateSpace initialization
def test_init_namedif():
Expand Down