pathsim.connection

class pathsim.connection.Connection(source, *targets)[source]

Bases: object

Class 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.

Example

Lets assume we have two generic blocks

B1 = Block… B2 = 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)

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 giving tuples (lists also work) as the arguments

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.

The port specification can be simplified (quality of life) by using the __getitem__ method that is implemented in the base ‘Block’ class. It returns the tuple of block and port pair that is used for the port specification in the ‘Connection’ initialization. For example the following initializations are equivalent:

Connection(B1[1], B2[3]) <=> Connection((B1, 1), (B2, 3))

Parameters:
on()[source]
off()[source]
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:

bool

to_dict()[source]

Convert connection to dictionary representation for serialization

update()[source]

Transfers data from the source block output port to the target block input port.

class pathsim.connection.Duplex(source, target)[source]

Bases: Connection

Extension 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.

update()[source]

Transfers data between the two target blocks and ports bidirectionally.