diff --git a/src/CustomHandle.jsx b/src/CustomHandle.jsx
index 31435971..91ddd6dc 100644
--- a/src/CustomHandle.jsx
+++ b/src/CustomHandle.jsx
@@ -4,12 +4,13 @@ import { Handle, useNodeConnections } from '@xyflow/react';
const CustomHandle = (props) => {
const connections = useNodeConnections({
handleType: props.type,
+ handleId: props.id,
});
return (
);
};
diff --git a/src/FunctionNode.jsx b/src/FunctionNode.jsx
index 8ae0b3ee..560ae790 100644
--- a/src/FunctionNode.jsx
+++ b/src/FunctionNode.jsx
@@ -22,8 +22,7 @@ export function createFunctionNode(numInputs, numOutputs) {
for (let i = 0; i < numInputs; i++) {
const handleId = `target-${i}`;
const topPercentage = numInputs === 1 ? 50 : ((i + 1) / (numInputs + 1)) * 100;
- const connectionCount = data?.maxConnections?.[handleId] || 1;
-
+
inputHandles.push(
);
diff --git a/src/convert_to_python.py b/src/convert_to_python.py
index e30dcf48..54057280 100644
--- a/src/convert_to_python.py
+++ b/src/convert_to_python.py
@@ -2,14 +2,12 @@
import os
from inspect import signature
-from pathsim.blocks import Scope
+from pathsim.blocks import Scope, Function
from .custom_pathsim_blocks import (
Process,
Splitter,
Bubbler,
FestimWall,
- Function1to1,
- Function2to2,
)
from .pathsim_utils import (
map_str_to_object,
@@ -174,19 +172,10 @@ def make_edge_data(data: dict) -> list[dict]:
raise ValueError(
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
)
- elif isinstance(block, Function1to1):
- # Function1to1 has only one output port
- output_index = 0
- elif isinstance(block, Function2to2):
- # Function2to2 has two output ports
- if edge["sourceHandle"] == "output-0":
- output_index = 0
- elif edge["sourceHandle"] == "output-1":
- output_index = 1
- else:
- raise ValueError(
- f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
- )
+ elif isinstance(block, Function):
+ # Function outputs are always in order, so we can use the handle directly
+ assert edge["sourceHandle"], edge
+ output_index = int(edge["sourceHandle"].replace("source-", ""))
else:
# make sure that the source block has only one output port (ie. that sourceHandle is None)
assert edge["sourceHandle"] is None, (
@@ -215,19 +204,9 @@ def make_edge_data(data: dict) -> list[dict]:
raise ValueError(
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
- elif isinstance(target_block, Function1to1):
- # Function1to1 has only one input port
- input_index = 0
- elif isinstance(target_block, Function2to2):
- # Function2to2 has two input ports
- if edge["targetHandle"] == "input-0":
- input_index = 0
- elif edge["targetHandle"] == "input-1":
- input_index = 1
- else:
- raise ValueError(
- f"Invalid target handle '{edge['targetHandle']}' for {edge}."
- )
+ elif isinstance(target_block, Function):
+ # Function inputs are always in order, so we can use the handle directly
+ input_index = int(edge["targetHandle"].replace("target-", ""))
else:
# make sure that the target block has only one input port (ie. that targetHandle is None)
assert edge["targetHandle"] is None, (
diff --git a/src/custom_pathsim_blocks.py b/src/custom_pathsim_blocks.py
index 7f4812ee..f9a51f3c 100644
--- a/src/custom_pathsim_blocks.py
+++ b/src/custom_pathsim_blocks.py
@@ -94,28 +94,6 @@ def create_reset_events(self):
]
-class Function1to1(pathsim.blocks.Function):
- """Function block with 1 input and 1 output."""
-
- def __init__(self, expression="lambda x: 1*x"):
- if isinstance(expression, str):
- func = eval(expression)
- else:
- func = expression
- super().__init__(func=func)
-
-
-class Function2to2(pathsim.blocks.Function):
- """Function block with 2 inputs and 2 outputs."""
-
- def __init__(self, expression="lambda x, y:1*x, 1*y"):
- if isinstance(expression, str):
- func = eval(expression)
- else:
- func = expression
- super().__init__(func=func)
-
-
# BUBBLER SYSTEM
diff --git a/src/pathsim_utils.py b/src/pathsim_utils.py
index bc8b2d08..bac6ceac 100644
--- a/src/pathsim_utils.py
+++ b/src/pathsim_utils.py
@@ -13,7 +13,7 @@
Amplifier,
Adder,
Multiplier,
- # Function,
+ Function,
Delay,
RNG,
PID,
@@ -28,8 +28,6 @@
Bubbler,
FestimWall,
Integrator,
- Function1to1,
- Function2to2,
)
from flask import jsonify
import inspect
@@ -57,8 +55,8 @@
"rng": RNG,
"pid": PID,
"integrator": Integrator,
- "function": Function1to1,
- "function2to2": Function2to2,
+ "function": Function,
+ "function2to2": Function,
"delay": Delay,
"bubbler": Bubbler,
"wall": FestimWall,
@@ -383,19 +381,10 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
raise ValueError(
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
)
- elif isinstance(block, Function1to1):
- # Function1to1 has only one output port
- output_index = 0
- elif isinstance(block, Function2to2):
- # Function2to2 has two output ports
- if edge["sourceHandle"] == "output-0":
- output_index = 0
- elif edge["sourceHandle"] == "output-1":
- output_index = 1
- else:
- raise ValueError(
- f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
- )
+ elif isinstance(block, Function):
+ # Function outputs are always in order, so we can use the handle directly
+ assert edge["sourceHandle"], edge
+ output_index = int(edge["sourceHandle"].replace("source-", ""))
else:
# make sure that the source block has only one output port (ie. that sourceHandle is None)
assert edge["sourceHandle"] is None, (
@@ -424,19 +413,9 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
raise ValueError(
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
- elif isinstance(target_block, Function1to1):
- # Function1to1 has only one input port
- input_index = 0
- elif isinstance(target_block, Function2to2):
- # Function2to2 has two input ports
- if edge["targetHandle"] == "input-0":
- input_index = 0
- elif edge["targetHandle"] == "input-1":
- input_index = 1
- else:
- raise ValueError(
- f"Invalid target handle '{edge['targetHandle']}' for {edge}."
- )
+ elif isinstance(target_block, Function):
+ # Function inputs are always in order, so we can use the handle directly
+ input_index = int(edge["targetHandle"].replace("target-", ""))
else:
# make sure that the target block has only one input port (ie. that targetHandle is None)
assert edge["targetHandle"] is None, (
diff --git a/test/test_convert_python.py b/test/test_convert_python.py
index 27a01be4..2680068f 100644
--- a/test/test_convert_python.py
+++ b/test/test_convert_python.py
@@ -29,7 +29,7 @@
"type": "function",
"data": {
"label": "func_block",
- "expression": "lambda x: x * 2 + 1",
+ "func": "lambda x: x * 2 + 1",
},
},
{
@@ -63,7 +63,7 @@
"target": "4",
"id": "e3-4",
"sourceHandle": None,
- "targetHandle": None,
+ "targetHandle": "target-0",
},
{
"source": "3",
@@ -76,7 +76,7 @@
"source": "4",
"target": "5",
"id": "e4-5",
- "sourceHandle": None,
+ "sourceHandle": "source-0",
"targetHandle": None,
},
],