Skip to content

Interpret str-type args to interconnect as non-sequence #698

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions control/iosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,11 @@ def interconnect(syslist, connections=None, inplist=[], outlist=[],
# Use an empty connections list
connections = []

if isinstance(inputs, str):
inputs = [inputs]
if isinstance(outputs, str):
outputs = [outputs]

# If inplist/outlist is not present, try using inputs/outputs instead
if not inplist and inputs is not None:
inplist = list(inputs)
Expand Down
20 changes: 20 additions & 0 deletions control/tests/interconnect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,23 @@ def test_interconnect_exceptions():

with pytest.raises(TypeError, match="unknown parameter"):
sumblk = ct.summing_junction(input_count=2, output_count=2)


def test_string_inputoutput():
# regression test for gh-692
P1 = ct.rss(2, 1, 1)
P1_iosys = ct.LinearIOSystem(P1, inputs='u1', outputs='y1')
P2 = ct.rss(2, 1, 1)
P2_iosys = ct.LinearIOSystem(P2, inputs='y1', outputs='y2')

P_s1 = ct.interconnect([P1_iosys, P2_iosys], inputs='u1', outputs=['y2'])
assert P_s1.input_index == {'u1' : 0}

P_s2 = ct.interconnect([P1_iosys, P2_iosys], input='u1', outputs=['y2'])
assert P_s2.input_index == {'u1' : 0}

P_s1 = ct.interconnect([P1_iosys, P2_iosys], inputs=['u1'], outputs='y2')
assert P_s1.output_index == {'y2' : 0}

P_s2 = ct.interconnect([P1_iosys, P2_iosys], inputs=['u1'], output='y2')
assert P_s2.output_index == {'y2' : 0}