Skip to content

Commit 8e8bf08

Browse files
committed
fix printing for systems w/ unspecified inputs, outputs, states
1 parent a4b4c43 commit 8e8bf08

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

control/iosys.py

Lines changed: 7 additions & 11 deletions
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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@ def test_ss2io(self):
100100
np.testing.assert_array_equal(linsys.C, iosys_named.C)
101101
np.testing.assert_array_equal(linsys.D, iosys_named.D)
102102

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

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

0 commit comments

Comments
 (0)