Skip to content

feat: parallel and map branch name#387

Merged
wangyb-A merged 3 commits into
mainfrom
feat/item_namer
May 15, 2026
Merged

feat: parallel and map branch name#387
wangyb-A merged 3 commits into
mainfrom
feat/item_namer

Conversation

@wangyb-A
Copy link
Copy Markdown
Contributor

@wangyb-A wangyb-A commented May 8, 2026

Issue #, if available:
close #303

Description of changes:

Add support for custom naming of map iterations and parallel branches.

Map:

  • item_namer on MapConfig[T]
  • Make MapConfig generic over T (the item type)
  • Add optional item_namer: Callable[[T, int], str] field
  • When provided, replaces the default map-item-{index} naming scheme
  • Receives the item and its index, returns a custom name string

Parallel:

  • Add ParallelBranch frozen dataclass with func and optional name
  • ParallelBranch implements call, making it directly usable anywhere a plain callable is accepted
  • When name is provided, replaces the default parallel-branch-{index} naming in execution history

Shared mechanism:

  • Add get_iteration_name(index) method to ConcurrentExecutor base class
  • MapExecutor and ParallelExecutor override it for custom naming

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Testing:

iShot_2026-05-07_17 18 37 iShot_2026-05-07_17 19 32 iShot_2026-05-11_16 35 37

@wangyb-A wangyb-A marked this pull request as ready for review May 8, 2026 00:28
Comment thread examples/src/parallel/parallel_with_named_branches.py
Comment thread examples/template.yaml
]
},
"DurableConfig": {
"RetentionPeriodInDays": 7,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this could be in Globals

operation_id: str = executor_context._create_step_id_for_logical_step( # noqa: SLF001
executable.index
)
name: str = f"{self.name_prefix}{executable.index}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we did this for both parallel and map. For parallel branches that use Python functions, they already have their unique names in __name__. We should leverage that to construct the branch names.

nesting_type=nesting_type,
)
self.items = items
self._item_namer = item_namer
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is _item_namer internal while the other fields are public? Do we have a guideline? I feel it's quite arbitrary when deciding whether or not I field should be internal.

name: str | None = None,
) -> Callable[
[Callable[Concatenate[DurableContext, Params], T]],
Callable[Params, ParallelBranch[T]],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! But is the return type readable?

def parallel(
self,
functions: Sequence[Callable[[DurableContext], T]],
functions: Sequence[Callable[[DurableContext], T] | ParallelBranch[T]],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't ParallelBranch also a Callable

@github-project-automation github-project-automation Bot moved this from In review to Pending merge in aws-durable-execution May 15, 2026
@wangyb-A wangyb-A merged commit cdcb353 into main May 15, 2026
124 of 126 checks passed
@github-project-automation github-project-automation Bot moved this from Pending merge to Done in aws-durable-execution May 15, 2026
@wangyb-A wangyb-A deleted the feat/item_namer branch May 15, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[Feature]: branch/iteration namer for concurrent operations

4 participants