Skip to content

Commit 62532f6

Browse files
committed
allow {input,output}_prefix in interconnect() + documentation updates
1 parent de053e2 commit 62532f6

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

control/iosys.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def __init__(self, params=None, **kwargs):
142142
143143
"""
144144
# Store the system name, inputs, outputs, and states
145-
name, inputs, outputs, states, dt = _process_namedio_keywords(
146-
kwargs)
145+
name, inputs, outputs, states, dt = _process_namedio_keywords(kwargs)
147146

148147
# Initialize the data structure
149148
# Note: don't use super() to override LinearIOSystem/StateSpace MRO
@@ -915,8 +914,7 @@ def __init__(self, syslist, connections=None, inplist=None, outlist=None,
915914
dt = kwargs.pop('dt', None)
916915

917916
# Process keyword arguments (except dt)
918-
name, inputs, outputs, states, _ = _process_namedio_keywords(
919-
kwargs, end=True)
917+
name, inputs, outputs, states, _ = _process_namedio_keywords(kwargs)
920918

921919
# Initialize the system list and index
922920
self.syslist = list(syslist) # insure modifications can be made
@@ -1017,7 +1015,7 @@ def __init__(self, syslist, connections=None, inplist=None, outlist=None,
10171015
# Note: don't use super() to override LinearICSystem/StateSpace MRO
10181016
InputOutputSystem.__init__(
10191017
self, inputs=inputs, outputs=outputs,
1020-
states=states, params=params, dt=dt, name=name)
1018+
states=states, params=params, dt=dt, name=name, **kwargs)
10211019

10221020
# Convert the list of interconnections to a connection map (matrix)
10231021
self.connect_map = np.zeros((ninputs, noutputs))
@@ -1246,7 +1244,9 @@ def set_output_map(self, output_map):
12461244
----------
12471245
output_map : 2D array
12481246
Specify the matrix that will be used to multiply the vector of
1249-
subsystem outputs to obtain the vector of system outputs.
1247+
subsystem outputs concatenated with subsystem inputs to obtain
1248+
the vector of system outputs.
1249+
12501250
"""
12511251
# Figure out the number of internal inputs and outputs
12521252
ninputs = sum(sys.ninputs for sys in self.syslist)
@@ -2546,7 +2546,7 @@ def interconnect(
25462546
signals are given names, then the forms 'sys.sig' or ('sys', 'sig')
25472547
are also recognized. Finally, for multivariable systems the signal
25482548
index can be given as a list, for example '(subsys_i, [inp_j1, ...,
2549-
inp_jn])', as as a slice, for example, 'sys.sig[i:j]', or as a base
2549+
inp_jn])'; as a slice, for example, 'sys.sig[i:j]'; or as a base
25502550
name `sys.sig` (which matches `sys.sig[i]`).
25512551
25522552
Similarly, each output-spec should describe an output signal from
@@ -2709,7 +2709,7 @@ def interconnect(
27092709
... [P, C], connections=[['P', 'C'], ['C', '-P']],
27102710
... inplist=['C'], outlist=['P'])
27112711
2712-
This feedback system can also be constructed using the
2712+
A feedback system can also be constructed using the
27132713
:func:`~control.summing_block` function and the ability to
27142714
automatically interconnect signals with the same names:
27152715
@@ -2728,7 +2728,7 @@ def interconnect(
27282728
default being to add the suffix '$copy' to the system name.
27292729
27302730
In addition to explicit lists of system signals, it is possible to
2731-
lists vectors of signals, using one of the following forms:
2731+
lists vectors of signals, using one of the following forms::
27322732
27332733
(subsys, [i1, ..., iN], gain) signals with indices i1, ..., in
27342734
'sysname.signal[i:j]' range of signal names, i through j-1
@@ -2754,8 +2754,7 @@ def interconnect(
27542754
27552755
"""
27562756
dt = kwargs.pop('dt', None) # by pass normal 'dt' processing
2757-
name, inputs, outputs, states, _ = _process_namedio_keywords(
2758-
kwargs, end=True)
2757+
name, inputs, outputs, states, _ = _process_namedio_keywords(kwargs)
27592758

27602759
if not check_unused and (ignore_inputs or ignore_outputs):
27612760
raise ValueError('check_unused is False, but either '
@@ -3011,10 +3010,21 @@ def interconnect(
30113010
outlist, outputs = new_outlist, new_outputs
30123011
dprint(f" {outlist=}\n {outputs=}")
30133012

3013+
# Make sure inputs and outputs match inplist outlist, if specified
3014+
if inputs and (
3015+
isinstance(inputs, (list, tuple)) and len(inputs) != len(inplist)
3016+
or isinstance(inputs, int) and inputs != len(inplist)):
3017+
raise ValueError("`inputs` incompatible with `inplist`")
3018+
if outputs and (
3019+
isinstance(outputs, (list, tuple)) and len(outputs) != len(outlist)
3020+
or isinstance(outputs, int) and outputs != len(outlist)):
3021+
raise ValueError("`outputs` incompatible with `outlist`")
3022+
30143023
newsys = InterconnectedSystem(
30153024
syslist, connections=connections, inplist=inplist,
30163025
outlist=outlist, inputs=inputs, outputs=outputs, states=states,
3017-
params=params, dt=dt, name=name, warn_duplicate=warn_duplicate)
3026+
params=params, dt=dt, name=name, warn_duplicate=warn_duplicate,
3027+
**kwargs)
30183028

30193029
# See if we should add any signals
30203030
if add_unused:
@@ -3034,7 +3044,8 @@ def interconnect(
30343044
newsys = InterconnectedSystem(
30353045
syslist, connections=connections, inplist=inplist,
30363046
outlist=outlist, inputs=inputs, outputs=outputs, states=states,
3037-
params=params, dt=dt, name=name, warn_duplicate=warn_duplicate)
3047+
params=params, dt=dt, name=name, warn_duplicate=warn_duplicate,
3048+
**kwargs)
30383049

30393050
# check for implicitly dropped signals
30403051
if check_unused:

doc/iosys.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ most explict would specify every signal::
325325
outlist=['P.y[0]', 'P.y[1]', 'P.z[0]', 'P.z[1]', 'C.u[0]', 'C.u[1]']
326326
)
327327

328-
This connections can be simplified using signal ranges:
328+
This connections can be simplified using signal ranges::
329329

330330
clsys2 = ct.interconnect(
331331
[C, P, sumblk],
@@ -348,7 +348,7 @@ when all signals with the same prefix are used::
348348
)
349349

350350
A further simplification is possible when all of the inputs or outputs
351-
of an individual system are used in a given specification:
351+
of an individual system are used in a given specification::
352352

353353
clsys4 = ct.interconnect(
354354
[C, P, sumblk],
@@ -358,7 +358,7 @@ of an individual system are used in a given specification:
358358

359359
And finally, since we have named the signals throughout the system in
360360
a consistent way, we could let :func:`ct.interconnect` do all of the
361-
work:
361+
work::
362362

363363
clsys5 = ct.interconnect(
364364
[C, P, sumblk], inplist=['sum.r', 'P.v'], outlist=['P', 'C.u']

0 commit comments

Comments
 (0)