Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,7 @@ def plan_blocks(
target=output,
preferred_boundaries=preferred_boundaries,
)
by_output = {step.output: step for step in settled}
selected: dict[str, PlanStep] = {}
pending = [output]

while pending:
attribute = pending.pop()

if attribute in available or attribute in selected:
continue

step = by_output.get(attribute)
if step is None:
msg = f"No supported execution route for {attribute!r}."
raise BiltExecutionPlanError(msg)

selected[attribute] = step
pending.extend(step.consumed)

graph, unresolved = build_dependency_graph(
tuple(selected.values()),
available,
)
if unresolved:
msg = f"Unresolved execution dependencies: {unresolved}."
raise BiltExecutionPlanError(msg)

blocks = ordered_blocks(graph)
for block in blocks:
if not block.is_cyclic:
continue
try:
extract_supported_linear_block(block)
except BiltLinearBlockError as error:
outputs = ", ".join(sorted(block.outputs))
msg = (
f"Execution of coupled blocks is not yet supported for this formulation. "
f"Required computations: {outputs}. {error}"
)
raise BiltExecutionPlanError(msg) from error

return blocks
return _plan_settled_blocks(settled, available, (output,), joint=False)


def plan_blocks_many(
Expand All @@ -103,6 +63,17 @@ def plan_blocks_many(
raise BiltExecutionPlanError(msg)

settled, _ = settle_assignments_many(assignments, available, backend, targets=targets)
return _plan_settled_blocks(settled, available, targets, joint=True)


def _plan_settled_blocks(
settled: tuple[PlanStep, ...],
available: set[str],
targets: tuple[str, ...],
*,
joint: bool,
) -> tuple[PlanBlock, ...]:
"""Select the dependency closure and validate its ordered execution blocks."""
by_output = {step.output: step for step in settled}
selected: dict[str, PlanStep] = {}
pending = list(targets)
Expand All @@ -112,22 +83,32 @@ def plan_blocks_many(
continue
step = by_output.get(attribute)
if step is None:
msg = f"No supported joint execution route for {attribute!r}."
route = "joint execution" if joint else "execution"
msg = f"No supported {route} route for {attribute!r}."
raise BiltExecutionPlanError(msg)
selected[attribute] = step
pending.extend(step.consumed)

graph, unresolved = build_dependency_graph(tuple(selected.values()), available)
if unresolved:
msg = f"Unresolved multi-output execution dependencies: {unresolved}."
kind = "multi-output execution" if joint else "execution"
msg = f"Unresolved {kind} dependencies: {unresolved}."
raise BiltExecutionPlanError(msg)

blocks = ordered_blocks(graph)
for block in blocks:
if block.is_cyclic:
try:
extract_supported_linear_block(block)
except BiltLinearBlockError as error:
if not block.is_cyclic:
continue
try:
extract_supported_linear_block(block)
except BiltLinearBlockError as error:
if joint:
msg = f"Unsupported coupled multi-output block {sorted(block.outputs)!r}: {error}"
raise BiltExecutionPlanError(msg) from error
else:
outputs = ", ".join(sorted(block.outputs))
msg = (
f"Execution of coupled blocks is not yet supported for this formulation. "
f"Required computations: {outputs}. {error}"
)
raise BiltExecutionPlanError(msg) from error
return blocks
Loading