5.3 API - Port Groups - Default / Minimum number of ports?

Hey,

been looking at the latest API docs which also include port groups to define dynamic ports.

I noticed that nodes which use port groups by default have 0 inputs / outputs. Have been trying to find a way to set a default say to min. 1 Input port or 1 output port, but thus far without success.

From the examples I take that

configure_context.get_connected_output_port_numbers()

Returns the number of currently “existing” output ports

So my first thought was to try something like this in configure:

def configure(self, configure_context):
        # Define the output port specification with the id
        connected_output_ports = configure_context.get_connected_output_port_numbers()
        if connected_output_ports == [0]:
            connected_output_ports = [1]  # Default to 1 port if none are connected
        return [knext.BinaryPortObjectSpec(id="test") for _ in range(connected_output_ports[0])]

and this in execute:

def execute(self, exec_context):
# Serialize the JSON structure
        serialized_json_data = pickle.dumps(json_structure)
        
        # Create the binary output port object
        connected_output_ports = exec_context.get_connected_output_port_numbers()
        print("outputportno: ", connected_output_ports)
        if  connected_output_ports == [0]:
            connected_output_ports = [1]  # Default to 1 port if none are connected
        return [serialized_json_data] * connected_output_ports[0]

However getting no joy and the following errors:

Configure failed (IllegalStateException): Python node configure returned wrong number of output port specs

Is there in general a way to make a python-based node “spawn” with a pre-defined number of dynamic ports?

P.S. my usecase is as follows: e.g. I have one initial node with certain parameters that need to be configured and are then passed on to further nodes. So output of this first node is fixed to one and input of the next node as well. However passed on the parameters defined in the first node the second node would need at least 1 (potentially more) output ports.

Edit: To guarantee at least “one” port I managed to add a “normal” port - however still interested to see if it is possible to set number of ports of a port group to a default number other than 0

Hi @MartinDDDD,

Thanks for trying. Very good question! We’ve also run into the problem that we want more configuration of this (but in the other direction: we’d like 0 or 1 port, but not more). But right now, it’s not yet possible and not immediately on our roadmap. Sorry!

Best,
Carsten

1 Like

Thanks Carsten, appreciate the feedback!

Is there a point in me putting this in as a feature request under Feedback & Ideas section?

1 Like

No need, I have added your request to our internal development ticket AP-23085.

Cheers,
Carsten

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.