|
13 | 13 | Amplifier, |
14 | 14 | Adder, |
15 | 15 | Multiplier, |
16 | | - # Function, |
| 16 | + Function, |
17 | 17 | Delay, |
18 | 18 | RNG, |
19 | 19 | PID, |
|
28 | 28 | Bubbler, |
29 | 29 | FestimWall, |
30 | 30 | Integrator, |
31 | | - Function1to1, |
32 | | - Function2to2, |
33 | 31 | ) |
34 | 32 | from flask import jsonify |
35 | 33 | import inspect |
|
57 | 55 | "rng": RNG, |
58 | 56 | "pid": PID, |
59 | 57 | "integrator": Integrator, |
60 | | - "function": Function1to1, |
61 | | - "function2to2": Function2to2, |
| 58 | + "function": Function, |
| 59 | + "function2to2": Function, |
62 | 60 | "delay": Delay, |
63 | 61 | "bubbler": Bubbler, |
64 | 62 | "wall": FestimWall, |
@@ -383,19 +381,10 @@ def make_connections(nodes, edges, blocks) -> list[Connection]: |
383 | 381 | raise ValueError( |
384 | 382 | f"Invalid source handle '{edge['sourceHandle']}' for {edge}." |
385 | 383 | ) |
386 | | - elif isinstance(block, Function1to1): |
387 | | - # Function1to1 has only one output port |
388 | | - output_index = 0 |
389 | | - elif isinstance(block, Function2to2): |
390 | | - # Function2to2 has two output ports |
391 | | - if edge["sourceHandle"] == "output-0": |
392 | | - output_index = 0 |
393 | | - elif edge["sourceHandle"] == "output-1": |
394 | | - output_index = 1 |
395 | | - else: |
396 | | - raise ValueError( |
397 | | - f"Invalid source handle '{edge['sourceHandle']}' for {edge}." |
398 | | - ) |
| 384 | + elif isinstance(block, Function): |
| 385 | + # Function outputs are always in order, so we can use the handle directly |
| 386 | + assert edge["sourceHandle"], edge |
| 387 | + output_index = int(edge["sourceHandle"].replace("source-", "")) |
399 | 388 | else: |
400 | 389 | # make sure that the source block has only one output port (ie. that sourceHandle is None) |
401 | 390 | assert edge["sourceHandle"] is None, ( |
@@ -424,19 +413,9 @@ def make_connections(nodes, edges, blocks) -> list[Connection]: |
424 | 413 | raise ValueError( |
425 | 414 | f"Invalid target handle '{edge['targetHandle']}' for {edge}." |
426 | 415 | ) |
427 | | - elif isinstance(target_block, Function1to1): |
428 | | - # Function1to1 has only one input port |
429 | | - input_index = 0 |
430 | | - elif isinstance(target_block, Function2to2): |
431 | | - # Function2to2 has two input ports |
432 | | - if edge["targetHandle"] == "input-0": |
433 | | - input_index = 0 |
434 | | - elif edge["targetHandle"] == "input-1": |
435 | | - input_index = 1 |
436 | | - else: |
437 | | - raise ValueError( |
438 | | - f"Invalid target handle '{edge['targetHandle']}' for {edge}." |
439 | | - ) |
| 416 | + elif isinstance(target_block, Function): |
| 417 | + # Function inputs are always in order, so we can use the handle directly |
| 418 | + input_index = int(edge["targetHandle"].replace("target-", "")) |
440 | 419 | else: |
441 | 420 | # make sure that the target block has only one input port (ie. that targetHandle is None) |
442 | 421 | assert edge["targetHandle"] is None, ( |
|
0 commit comments