Skip to content

Commit c36fcc0

Browse files
authored
Fix iosys errors for unspecified # of inputs/outputs (#355)
1 parent 72262c6 commit c36fcc0

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

control/iosys.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ def __repr__(self):
212212

213213
def __str__(self):
214214
"""String representation of an input/output system"""
215-
str = "System: " + (self.name if self.name else "(none)") + "\n"
216-
str += "Inputs (%d): " % self.ninputs
215+
str = "System: " + (self.name if self.name else "(None)") + "\n"
216+
str += "Inputs (%s): " % self.ninputs
217217
for key in self.input_index: str += key + ", "
218-
str += "\nOutputs (%d): " % self.noutputs
218+
str += "\nOutputs (%s): " % self.noutputs
219219
for key in self.output_index: str += key + ", "
220-
str += "\nStates (%d): " % self.nstates
220+
str += "\nStates (%s): " % self.nstates
221221
for key in self.state_index: str += key + ", "
222222
return str
223223

@@ -317,13 +317,8 @@ def __add__(sys1, sys2):
317317
ninputs = sys1.ninputs
318318
noutputs = sys1.noutputs
319319

320-
# Make sure timebase are compatible
321-
dt = _find_timebase(sys1, sys2)
322-
if dt is False:
323-
raise ValueError("System timebases are not compabile")
324-
325320
# Create a new system to handle the composition
326-
newsys = InterconnectedSystem((sys1, sys2), dt=dt)
321+
newsys = InterconnectedSystem((sys1, sys2))
327322

328323
# Set up the input map
329324
newsys.set_input_map(np.concatenate(
@@ -937,6 +932,7 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
937932
system_count = 0
938933
for sys in syslist:
939934
# Make sure time bases are consistent
935+
# TODO: Use lti._find_timebase() instead?
940936
if dt is None and sys.dt is not None:
941937
# Timebase was not specified; set to match this system
942938
dt = sys.dt
@@ -948,7 +944,7 @@ def __init__(self, syslist, connections=[], inplist=[], outlist=[],
948944
sys.nstates is None:
949945
raise TypeError("System '%s' must define number of inputs, "
950946
"outputs, states in order to be connected" %
951-
sys)
947+
sys.name)
952948

953949
# Keep track of the offsets into the states, inputs, outputs
954950
self.input_offset.append(ninputs)

control/tests/iosys_test.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# operations on input/output systems. Separate unit tests should be
99
# created for that purpose.
1010

11+
from __future__ import print_function
1112
import unittest
1213
import warnings
1314
import numpy as np
@@ -100,6 +101,32 @@ def test_ss2io(self):
100101
np.testing.assert_array_equal(linsys.C, iosys_named.C)
101102
np.testing.assert_array_equal(linsys.D, iosys_named.D)
102103

104+
# Make sure unspecified inputs/outputs/states are handled properly
105+
def test_iosys_unspecified(self):
106+
# System with unspecified inputs and outputs
107+
sys = ios.NonlinearIOSystem(secord_update, secord_output)
108+
np.testing.assert_raises(TypeError, sys.__mul__, sys)
109+
110+
# Make sure we can print various types of I/O systems
111+
def test_iosys_print(self):
112+
# Send the output to /dev/null
113+
import os
114+
f = open(os.devnull,"w")
115+
116+
# Simple I/O system
117+
iosys = ct.ss2io(self.siso_linsys)
118+
print(iosys, file=f)
119+
120+
# I/O system without ninputs, noutputs
121+
ios_unspecified = ios.NonlinearIOSystem(secord_update, secord_output)
122+
print(ios_unspecified, file=f)
123+
124+
# I/O system with derived inputs and outputs
125+
ios_linearized = ios.linearize(ios_unspecified, [0, 0], [0])
126+
print(ios_linearized, file=f)
127+
128+
f.close()
129+
103130
@unittest.skipIf(StrictVersion(sp.__version__) < "1.0",
104131
"requires SciPy 1.0 or greater")
105132
def test_nonlinear_iosys(self):
@@ -832,7 +859,6 @@ def test_lineariosys_statespace(self):
832859
np.testing.assert_array_equal(io_feedback.C, ss_feedback.C)
833860
np.testing.assert_array_equal(io_feedback.D, ss_feedback.D)
834861

835-
836862
def test_duplicates(self):
837863
nlios = ios.NonlinearIOSystem(None, \
838864
lambda t, x, u, params: u*u, inputs=1, outputs=1)

0 commit comments

Comments
 (0)