Skip to content

Commit 8163f97

Browse files
Merge pull request #90 from festim-dev/fix-handles-for-bubblers
Fix handling of several inputs for Bubbler
2 parents 05a4ef2 + 8d5d100 commit 8163f97

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

src/convert_to_python.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,24 @@ def make_edge_data(data: dict) -> list[dict]:
168168
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
169169
)
170170
else:
171+
# make sure that the source block has only one output port (ie. that sourceHandle is None)
172+
assert edge["sourceHandle"] is None, (
173+
f"Source block {block.id} has multiple output ports, "
174+
"but connection method hasn't been implemented."
175+
)
171176
output_index = 0
172177

173178
if isinstance(target_block, Scope):
174179
input_index = target_block._connections_order.index(edge["id"])
180+
elif isinstance(target_block, Bubbler):
181+
if edge["targetHandle"] == "sample_in_soluble":
182+
input_index = 0
183+
elif edge["targetHandle"] == "sample_in_insoluble":
184+
input_index = 1
185+
else:
186+
raise ValueError(
187+
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
188+
)
175189
elif isinstance(target_block, FestimWall):
176190
if edge["targetHandle"] == "c_0":
177191
input_index = 0
@@ -182,6 +196,11 @@ def make_edge_data(data: dict) -> list[dict]:
182196
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
183197
)
184198
else:
199+
# make sure that the target block has only one input port (ie. that targetHandle is None)
200+
assert edge["targetHandle"] is None, (
201+
f"Target block {target_block.id} has multiple input ports, "
202+
"but connection method hasn't been implemented."
203+
)
185204
input_index = block_to_input_index[target_block]
186205

187206
edge["source_var_name"] = node["var_name"]

src/pathsim_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,24 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
437437
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
438438
)
439439
else:
440+
# make sure that the source block has only one output port (ie. that sourceHandle is None)
441+
assert edge["sourceHandle"] is None, (
442+
f"Source block {block.id} has multiple output ports, "
443+
"but connection method hasn't been implemented."
444+
)
440445
output_index = 0
441446

442447
if isinstance(target_block, Scope):
443448
input_index = target_block._connections_order.index(edge["id"])
444-
# TODO we should do the same for all blocks with several input/target ports
449+
elif isinstance(target_block, Bubbler):
450+
if edge["targetHandle"] == "sample_in_soluble":
451+
input_index = 0
452+
elif edge["targetHandle"] == "sample_in_insoluble":
453+
input_index = 1
454+
else:
455+
raise ValueError(
456+
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
457+
)
445458
elif isinstance(target_block, FestimWall):
446459
if edge["targetHandle"] == "c_0":
447460
input_index = 0
@@ -452,6 +465,11 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
452465
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
453466
)
454467
else:
468+
# make sure that the target block has only one input port (ie. that targetHandle is None)
469+
assert edge["targetHandle"] is None, (
470+
f"Target block {target_block.id} has multiple input ports, "
471+
"but connection method hasn't been implemented."
472+
)
455473
input_index = block_to_input_index[target_block]
456474

457475
connection = Connection(

test/test_convert_python.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,41 @@
4141
},
4242
],
4343
"edges": [
44-
{"source": "1", "target": "2", "id": "e1-2"},
45-
{"source": "2", "target": "3", "id": "e2-3"},
46-
{"source": "3", "target": "4", "id": "e3-4"},
47-
{"source": "3", "target": "5", "id": "e3-5"},
48-
{"source": "4", "target": "5", "id": "e4-5"},
44+
{
45+
"source": "1",
46+
"target": "2",
47+
"id": "e1-2",
48+
"sourceHandle": None,
49+
"targetHandle": None,
50+
},
51+
{
52+
"source": "2",
53+
"target": "3",
54+
"id": "e2-3",
55+
"sourceHandle": None,
56+
"targetHandle": None,
57+
},
58+
{
59+
"source": "3",
60+
"target": "4",
61+
"id": "e3-4",
62+
"sourceHandle": None,
63+
"targetHandle": None,
64+
},
65+
{
66+
"source": "3",
67+
"target": "5",
68+
"id": "e3-5",
69+
"sourceHandle": None,
70+
"targetHandle": None,
71+
},
72+
{
73+
"source": "4",
74+
"target": "5",
75+
"id": "e4-5",
76+
"sourceHandle": None,
77+
"targetHandle": None,
78+
},
4979
],
5080
"solverParams": {
5181
"Solver": "SSPRK22",

0 commit comments

Comments
 (0)