Feature method to convert network to subsystem - #1021
Conversation
|
Thank you for the contribution @HaSchneider, will look into this and give you feedback soon! |
|
As it could be possible to have subsystem-internal sources/sinks, I would like to suggest the following change:
I would also add/transfer the properties of the original connections to the interface connections so starting values can be preserved, if the original Network was solved already. Other than that, I am thinking if the Subsystem/Network architecture needs to be implemented in a different way, there are a couple of thoughts that come to my mind:
Any thoughts about it, since you are working with Subsystems frequently? This does not need to be included in this PR but it let to me thinking about it :D |
|
That are good suggestions. I adjusted the method, so that all connections are copied instead of creating new conenctions. All connection properties should be kept now. Only the source/targets are now adjusted accordingly to the subsysteminterface. Regarding your other suggestions:
|
Nice, thank you! I will have a look at the changes. All the other topics can go to a different issue/pr.
It is, but the inherit logic of which subsystem belongs to where goes missing due to the flattening of the labels. So a structured registry in the Network could be helpful.
Yes, that is exactly what I am thinking about as well. Also being able to put parts of Network in "shutdown" mode.
also agree
also agree |
| for conn in args: | ||
| self.conns[conn.label] = copy.copy(conn) |
There was a problem hiding this comment.
I think the copying/plain reusing of connections could break things if a model is exported more than once. There will be still some objects in the copied Connection instances which point to the original objects, e.g. fluidwrappers etc. So maybe it is actually better to serialize and de-serialize instead.
There was a problem hiding this comment.
Yes, that is correct. I tried also deepcopy but that results in the follwoing error:
TESPyComponentError: Component name in subsystem is not unique| return components | ||
|
|
||
|
|
||
| def convert_to_subsystem(self, subname, interface_exceptions=[]): |
There was a problem hiding this comment.
Maybe this could live in the Subsystem class instead. So we could have something like this:
Subsystem.from_network()- calls
Network.export(), your logic to transform the ports and thenSubsystem._deserialize()to deserialize theNetwork.export()
- calls
Subsystem.to_network()- calls
Subsystem._serialize(), logic to transformSubsystemInterfacetoSource/Sinketc.,Network.from_dict()
- calls
Subsystem._deserialize()Subsystem._serialize()
There was a problem hiding this comment.
Yes, this might be a better location. Currently the type of the returned Subsystem is:
tespy.networks.network.Network.convert_to_subsystem.<locals>.sub_network😆
|
Let's maybe have a call to discuss this topic in detail @HaSchneider, do you have time Monday next week? |
|
The subsystem has now a clasmethod There is one issue that might come up here: When a proper configured network is converted to a subsystem, using that subsystem in another network will most likely lead to an overdetermined system. |
|
Thank you for the update, we could change it so the subsystem can optionally be created "clean" = without any specifications. |
As described in #1020 this implements a method for the Network class which returns a subsystem class implementation of the corresponding network.
A new subsystem is created and all sinks and sources are transformed in subsystem interfaces. All connections and the corresponding components are converted, only those to/from sink/sources are reconnected to subsystem interfaces.
This doesnt have to be a method of Network class, it could also be implemented as normal function in subsystem.py for example.
To do: