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
19 changes: 19 additions & 0 deletions src/convert_to_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,24 @@ def make_edge_data(data: dict) -> list[dict]:
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
)
else:
# make sure that the source block has only one output port (ie. that sourceHandle is None)
assert edge["sourceHandle"] is None, (
f"Source block {block.id} has multiple output ports, "
"but connection method hasn't been implemented."
)
output_index = 0

if isinstance(target_block, Scope):
input_index = target_block._connections_order.index(edge["id"])
elif isinstance(target_block, Bubbler):
if edge["targetHandle"] == "sample_in_soluble":
input_index = 0
elif edge["targetHandle"] == "sample_in_insoluble":
input_index = 1
else:
raise ValueError(
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
elif isinstance(target_block, FestimWall):
if edge["targetHandle"] == "c_0":
input_index = 0
Expand All @@ -182,6 +196,11 @@ def make_edge_data(data: dict) -> list[dict]:
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
else:
# make sure that the target block has only one input port (ie. that targetHandle is None)
assert edge["targetHandle"] is None, (
f"Target block {target_block.id} has multiple input ports, "
"but connection method hasn't been implemented."
)
input_index = block_to_input_index[target_block]

edge["source_var_name"] = node["var_name"]
Expand Down
20 changes: 19 additions & 1 deletion src/pathsim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,24 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
f"Invalid source handle '{edge['sourceHandle']}' for {edge}."
)
else:
# make sure that the source block has only one output port (ie. that sourceHandle is None)
assert edge["sourceHandle"] is None, (
f"Source block {block.id} has multiple output ports, "
"but connection method hasn't been implemented."
)
output_index = 0

if isinstance(target_block, Scope):
input_index = target_block._connections_order.index(edge["id"])
# TODO we should do the same for all blocks with several input/target ports
elif isinstance(target_block, Bubbler):
if edge["targetHandle"] == "sample_in_soluble":
input_index = 0
elif edge["targetHandle"] == "sample_in_insoluble":
input_index = 1
else:
raise ValueError(
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
elif isinstance(target_block, FestimWall):
if edge["targetHandle"] == "c_0":
input_index = 0
Expand All @@ -452,6 +465,11 @@ def make_connections(nodes, edges, blocks) -> list[Connection]:
f"Invalid target handle '{edge['targetHandle']}' for {edge}."
)
else:
# make sure that the target block has only one input port (ie. that targetHandle is None)
assert edge["targetHandle"] is None, (
f"Target block {target_block.id} has multiple input ports, "
"but connection method hasn't been implemented."
)
input_index = block_to_input_index[target_block]

connection = Connection(
Expand Down
40 changes: 35 additions & 5 deletions test/test_convert_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,41 @@
},
],
"edges": [
{"source": "1", "target": "2", "id": "e1-2"},
{"source": "2", "target": "3", "id": "e2-3"},
{"source": "3", "target": "4", "id": "e3-4"},
{"source": "3", "target": "5", "id": "e3-5"},
{"source": "4", "target": "5", "id": "e4-5"},
{
"source": "1",
"target": "2",
"id": "e1-2",
"sourceHandle": None,
"targetHandle": None,
},
{
"source": "2",
"target": "3",
"id": "e2-3",
"sourceHandle": None,
"targetHandle": None,
},
{
"source": "3",
"target": "4",
"id": "e3-4",
"sourceHandle": None,
"targetHandle": None,
},
{
"source": "3",
"target": "5",
"id": "e3-5",
"sourceHandle": None,
"targetHandle": None,
},
{
"source": "4",
"target": "5",
"id": "e4-5",
"sourceHandle": None,
"targetHandle": None,
},
],
"solverParams": {
"Solver": "SSPRK22",
Expand Down
Loading