-
Notifications
You must be signed in to change notification settings - Fork 438
Multivariable interconnect functionality #881
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
Multivariable interconnect functionality #881
Conversation
Nice PR for this functionality. A few thoughts/comments:
a = np.array((1,2,3))
a[0] // gives 1
a[(0,1]) // tuple indexing gives IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
a[[0,1]) // list indexing gives array([1, 2]) This could be used to access a subset of signals in a given name:
|
The problem is that with the new "abbreviated" ways of specifying signals, there can be ambiguity if you use a list instead of a tuple. For example, if we allowed tuples and lists to be used interchangeably, the output specification
becomes ambiguous. Is this a single output with system 'P' and signal 'z' or did you mean the outputs of the system 'P' and also the signals 'z'? In this PR, this specification gets interpreted as the former case, whereas if you want the latter you would write
Note that here we have used the shorthand that you can specify the outputs of a block just by giving the name of the block ('P') and you can specify any output signal in the diagram (regardless of what subsystem it belongs to) just be specifying the signal name ('z'). (It is also possible that you mean signals 'P' and systems 'z', of course, and if there is ambiguity based on the specific subsystems then you get an error.)
The only thing supported in this PR is ranges with optional upper and lower limits. If you want to index by a list, you would have to either list things out or use a list comprehension, such as
That functionality was there before, since if you had a system with outputs What you can do now that you couldn't do before is connect all of the xd's to new signals zd's (say) by saying something like
|
OK, this looks good. One other question: I recently noticed that there is a bug in the current code in which system names and labels are lost when indexing the system: e_summer = ct.summing_junction(['r', '-y'], 'e')
print(e_summer.input_labels)
print(e_summer[0,0].input_labels) # loses name and labels
print(e_summer[0,0].output_labels) # loses name and labels gives
Any chance this PR addresses that? |
This PR doesn't address One question is how to handle system naming. When we take a subset of a set of inputs and outputs we probably don't want to use exactly the same system name. Normally, we set the name to something like |
|
LGTM |
574ae73
to
c17a389
Compare
d646017
to
55e2b55
Compare
This PR expands the
interconnect
function to allow a variety of "multivariable" specifications for connections, inputs, and outputs when systems have variables with names of the formsig[i]
:sys.sig
will match all signals of the formsys.sig[i]
. So a MIMO feedback system interconnection assuming the usual input/output naming conventions can be written asconnections=[['P.u', 'C.y'], ['C.u', '-P.y']], inplist='C.u', outlist='P.y'
(before this PR, you would have to writeconnections=[['P.u[0]', 'C.u[0]'], ['P.u[1]', 'C.u[1]'], ...]
).sys.sig[i:j]
or tuple specifications of the form(sys_index, [i1, ..., iN], gain)
instead of having to write all signals out explicitly.connections=[['P', 'C'], ['C', -P]], inplist='C', outlist='P'
(note that the input toC
will be the sum of the input to the new system and the negation of the plant output, so the error between the reference and the output).sys.find_inputs
,sys.find_outputs
,sys.find_states
. Each returns a list of indices (versus the singular version, which returns a single index).linsys[2, 1]
, now preserves signal names and modifies the system name using configurable a prefix and suffix (default is to append '$indexed' to the system name).Note: one change in this PR is that you now must use lists rather than tuples when specifying lists of signals. This is consistent with the documentation from previous versions, but some examples used tuples instead of lists. In order to handle the multi-variable case, the only place that a tuple should be used is as a low level signal specification. Everything else should be a list.