pathsim.connection
- class pathsim.connection.Connection(source, *targets)[source]
Bases:
objectClass to handle input-output relations of blocks by connecting them (directed graph) and transfering data from the output port of the source block to the input port of the target block.
The default ports for connection are (0) -> (0), since these are the default inputs that are used in the SISO blocks.
Examples
Lets assume we have some generic blocks
from pathsim.blocks._block import Block B1 = Block() B2 = Block() B3 = Block()
that we want to connect. We initialize a ‘Connection’ with the blocks directly as the arguments if we want to connect the default ports (0) -> (0)
from pathsim import Connection C = Connection(B1, B2)
which is a connection from block ‘B1’ to ‘B2’. If we want to explicitly declare the input and output ports we can do that by utilizing the ‘__getitem__’ method of the blocks
C = Connection(B1[0], B2[0])
which is exactly the default port setup. Connecting output port (1) of ‘B1’ to the default input port (0) of ‘B2’ do
C = Connection(B1[1], B2[0])
or just
C = Connection(B1[1], B2).
The ‘Connection’ class also supports multiple targets for a single source. This is specified by just adding more blocks with their respective ports into the constructor like this:
C = Connection(B1, B2[0], B2[1], B3)
The port definitions follow the same structure as for single target connections.
‘self’-connections also work without a problem. This is useful for modeling direct feedback of a block to itself.
Port definitions support slicing. This enables direct MIMO connections. For example connecting ports 0, 1, 2 of ‘B1’ to ports 1, 2, 3 of ‘B2’ works like this:
C = Connection(B1[0:2], B2[1:3])
Slicing can also be used for one-to-many connections where this:
C = Connection(B1, B2[0], B2[1])
would be equivalent to this:
C = Connection(B1, B2[0:2])
- Parameters:
source (PortReference, Block) – source block and optional source output port
targets (tuple[PortReference], tuple[Block]) – target blocks and optional target input ports
- get_blocks()[source]
Returns all the unique internal source and target blocks of the connection instance
- overwrites(other)[source]
Check if the connection ‘self’ overwrites the target port of connection ‘other’ and return ‘True’ if so.
- Parameters:
other (Connection) – other connection to check
- Returns:
overwrites – True if port is overwritten, False otherwise
- Return type:
- class pathsim.connection.Duplex(source, target)[source]
Bases:
ConnectionExtension of the ‘Connection’ class, that defines bidirectional connections between two blocks by grouping together the inputs and outputs of the blocks into an IO-pair.