Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CustomHandle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Handle, useNodeConnections } from '@xyflow/react';
const CustomHandle = (props) => {
const connections = useNodeConnections({
handleType: props.type,
handleId: props.id,
});

return (
<Handle
{...props}
isConnectable={connections.length < props.connectionCount}
isConnectable={connections.length < 1}
/>
);
};
Expand Down
4 changes: 1 addition & 3 deletions src/FunctionNode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
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(
<CustomHandle
key={handleId}
id={handleId}
type="target"
position="left"
style={{ ...handleStyle, top: `${topPercentage}%` }}
connectionCount={connectionCount}
/>
);

Expand Down Expand Up @@ -124,4 +122,4 @@
}

// Default FunctionNode with 1 input and 1 output
export default createFunctionNode(1, 1);

Check warning on line 125 in src/FunctionNode.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.11)

Fast refresh can't handle anonymous components. Add a name to your export

Check warning on line 125 in src/FunctionNode.jsx

View workflow job for this annotation

GitHub Actions / test (20.x, 3.10)

Fast refresh can't handle anonymous components. Add a name to your export
37 changes: 8 additions & 29 deletions src/convert_to_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, (
Expand Down Expand Up @@ -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, (
Expand Down
22 changes: 0 additions & 22 deletions src/custom_pathsim_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
41 changes: 10 additions & 31 deletions src/pathsim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Amplifier,
Adder,
Multiplier,
# Function,
Function,
Delay,
RNG,
PID,
Expand All @@ -28,8 +28,6 @@
Bubbler,
FestimWall,
Integrator,
Function1to1,
Function2to2,
)
from flask import jsonify
import inspect
Expand Down Expand Up @@ -57,8 +55,8 @@
"rng": RNG,
"pid": PID,
"integrator": Integrator,
"function": Function1to1,
"function2to2": Function2to2,
"function": Function,
"function2to2": Function,
"delay": Delay,
"bubbler": Bubbler,
"wall": FestimWall,
Expand Down Expand Up @@ -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, (
Expand Down Expand Up @@ -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, (
Expand Down
6 changes: 3 additions & 3 deletions test/test_convert_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"type": "function",
"data": {
"label": "func_block",
"expression": "lambda x: x * 2 + 1",
"func": "lambda x: x * 2 + 1",
},
},
{
Expand Down Expand Up @@ -63,7 +63,7 @@
"target": "4",
"id": "e3-4",
"sourceHandle": None,
"targetHandle": None,
"targetHandle": "target-0",
},
{
"source": "3",
Expand All @@ -76,7 +76,7 @@
"source": "4",
"target": "5",
"id": "e4-5",
"sourceHandle": None,
"sourceHandle": "source-0",
"targetHandle": None,
},
],
Expand Down
Loading