Repository navigation
Fill in missing task input/output names from edge data mappings #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from typing import NamedTuple | ||
|
|
||
|
|
||
| class DataMapping(NamedTuple): | ||
| source: str | ||
| target: str | ||
| source_output: str | ||
| target_input: str |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import warnings | ||
| from collections import defaultdict | ||
|
|
||
| from ewokscore.graph import TaskGraph | ||
|
|
||
| from .models import DataMapping | ||
|
|
||
|
|
||
| def get_valid_data_mappings(ewoks_graph: TaskGraph) -> list[DataMapping]: | ||
| data_mappings: list[DataMapping] = [] | ||
| for source, target, link_attrs in ewoks_graph.graph.edges(data=True): | ||
| if link_attrs.get("map_all_data", False): | ||
| warnings.warn( | ||
| f"Ewoks link {source!r} -> {target!r} uses 'map_all_data', which " | ||
| "is not yet supported.", | ||
| UserWarning, | ||
| stacklevel=2, | ||
| ) | ||
|
|
||
| for mapping in link_attrs.get("data_mapping", []): | ||
| source_output = mapping.get("source_output") | ||
| if source_output is None: | ||
| warnings.warn( | ||
| f"Data mapping on Ewoks link {source!r} -> {target!r} has no " | ||
| "'source_output', which is not yet supported.", | ||
| UserWarning, | ||
| stacklevel=2, | ||
| ) | ||
| continue | ||
|
|
||
| data_mappings.append( | ||
| DataMapping( | ||
| source=source, | ||
| target=target, | ||
| source_output=source_output, | ||
| target_input=mapping["target_input"], | ||
| ) | ||
| ) | ||
|
|
||
| return data_mappings | ||
|
|
||
|
|
||
| def get_edge_sources_and_targets( | ||
| graph: TaskGraph, | ||
| ) -> tuple[dict[str, list[str]], dict[str, list[str]]]: | ||
| data_mappings = get_valid_data_mappings(graph) | ||
| sources: dict[str, list[str]] = defaultdict(list[str]) | ||
| targets: dict[str, list[str]] = defaultdict(list[str]) | ||
| for mapping in data_mappings: | ||
| sources[mapping.source].append(mapping.source_output) | ||
| targets[mapping.target].append(mapping.target_input) | ||
|
|
||
| return sources, targets | ||
|
Comment on lines
+43
to
+53
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to avoid the double warning. def get_edge_sources_and_targets(
data_mappings: list[DataMapping],
) -> tuple[dict[str, list[str]], dict[str, list[str]]]:Let def graph_to_svg(graph: TaskGraph, output_path: str | Path) -> None:
data_mappings = get_valid_data_mappings(graph)
task_group = build_svg_task_group(
graph,
data_mappings,
)
elk_graph_before_layout = convert_ewoks_to_elk_graph(
graph,
task_group.extract_task_sizes(),
task_group.extract_input_positions(),
task_group.extract_output_positions(),
data_mappings,
)Having the warning twice might be better :). You're the judge on that one.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are right I got lost in PR. It's fine with b3d0dec |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New util to go through data mappings in the new
get_edge_sources_and_targetsfunction