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
277 changes: 277 additions & 0 deletions docs/validation/step-input-image-artifact-origin-20261004.rst

Large diffs are not rendered by default.

134 changes: 4 additions & 130 deletions openhcs/core/runtime_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
)
from openhcs.core.aligned_image_payload import (
ImagePayloadExecutionMode,
stack_image_payloads,
)
from openhcs.core.artifacts import (
ArtifactInputPlan,
Expand All @@ -30,32 +29,18 @@
InvocationArtifactInputEdgePlan,
InvocationArtifactInputProjectionKey,
)
from openhcs.core.runtime_image_loading import ImagePayloadSourceMetadataContext
from openhcs.core.runtime_image_values import (
ImagePayloadMetadataCompositionMode,
image_payload_metadata,
)
from openhcs.core.source_bindings import (
CompiledSourceBindingPlan,
NamedSourceBinding,
)
from openhcs.core.source_binding_selection import (
SourceBindingMatchedImageSet,
)
from openhcs.core.source_image_provenance import (
SourceImageIdentity,
SourceImageProvenance,
SourceUniverseRequest,
)
from openhcs.core.source_load_plan import SourceLoadPlan
from openhcs.core.runtime_plane_projection import (
RuntimePlaneAxis,
RuntimePlaneAxisValueProjection,
RuntimePlaneProjection,
)
from openhcs.core.source_workspace_projection import (
VirtualWorkspacePathLookup,
VirtualWorkspaceSourceProjectionAuthority,
)

if TYPE_CHECKING:
from openhcs.core.callable_contract import CallableContract
Expand Down Expand Up @@ -249,121 +234,10 @@ def runtime_artifact_input(
)

def source_artifact_payload(self, ref: ArtifactSpecRef) -> object:
"""Resolve one source-bound artifact through workspace matching and VFS."""

"""Resolve a named input through its existing source-origin owner."""
binding = self.source_binding_for_artifact_ref(ref)
source_payload = self.source_payload
source_provenance = (
None
if source_payload is None
else image_payload_metadata(source_payload).source_provenance
)
if source_provenance is not None and not source_provenance.has_values:
raise ValueError(
f"Source-bound artifact {ref!r} requires main-flow source provenance."
)

cache = self.context.runtime_source_workspace_projection_cache
projection = VirtualWorkspaceSourceProjectionAuthority.from_context(
self.context,
cache=cache,
).projection_if_available()
if projection is None:
raise ValueError(
f"Source-bound artifact {ref!r} requires a virtual-workspace "
"source projection."
)
projection = cache.filtered_by_axis(
projection,
axis_id=self.axis_scope.axis_id,
)
source_context = (
self.context.runtime_source_binding_context_cache.source_pattern_context(
parser=self.context.microscope_handler.parser,
projection=projection,
metadata_rules=self.source_binding_plan.metadata_rules,
)
)
matched_set = SourceBindingMatchedImageSet.from_plan(
bindings=self.source_binding_plan.binding_declarations,
match_plan=self.source_binding_plan.match_plan,
source_context=source_context,
identity_policy=self.context.source_image_set_identity_policy,
)
source_universe = tuple(
dict.fromkeys(
source_path
for declared_binding in self.source_binding_plan.binding_declarations
for source_path in projection.files_for_projection_role(
declared_binding.projection_role,
axis_id=self.axis_scope.axis_id,
)
)
)
members = matched_set.members_for_binding(
binding,
anchor_provenance=(
source_provenance
if source_provenance is not None
else SourceImageProvenance()
),
source_universe=source_universe,
)
if not members:
raise ValueError(
f"Source-bound artifact {ref!r} resolved no workspace members."
)

payloads = self.context.filemanager.load_batch(
list(members),
Backend.VIRTUAL_WORKSPACE.value,
)
if len(payloads) != len(members):
raise ValueError(
f"Source-bound artifact {ref!r} loaded {len(payloads)} payloads "
f"for {len(members)} workspace members."
)
projected_payloads = []
for member, payload in zip(members, payloads, strict=True):
lookup = VirtualWorkspacePathLookup.from_paths(member, member)
source_projection = projection.require_source_projection_for(lookup)
if not source_projection.matches_binding(binding):
raise ValueError(
f"Workspace projection for {member!r} does not match compiled "
f"source artifact {ref!r}."
)
projected = projection.project_payload(lookup, payload)
projected_payloads.append(
binding.apply_loaded_payload(
projected,
ImagePayloadSourceMetadataContext(
SourceImageIdentity(
member,
projection.source_metadata_for(lookup),
),
source_projection.ref.backend,
self.context.filemanager,
source_projection.ref.backend_address,
),
)
)
payload = (
projected_payloads[0]
if len(projected_payloads) == 1
and image_payload_metadata(projected_payloads[0]).persists_whole_image()
else stack_image_payloads(
projected_payloads,
metadata_mode=ImagePayloadMetadataCompositionMode.for_plane_axis(
RuntimePlaneAxis.RUNTIME_SLICE
),
)
)
metadata = image_payload_metadata(payload)
domain = self.source_binding_plan.source_spatial_domain.admit_source_cohort(
metadata.source_spatial_domain,
depth=len(members),
)
return metadata.replace_fields(source_spatial_domain=domain).attach_to(payload)
owner = SourceUniverseRequest.for_binding(binding)
return owner.source_artifact_payload(self, binding)


RuntimeAdapterFactory = Callable[[RuntimeAdapterRequest], object]
Expand Down
10 changes: 9 additions & 1 deletion openhcs/core/runtime_image_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,14 @@ def project_declared_source_image(
"with provenance planes "
f"{self.source_image_provenance_planes.identity!r}."
)
return self.project_source_planes(payload, source_plane_selection)

def project_source_planes(
self,
payload: RuntimeArrayData,
source_plane_selection: tuple[int, ...],
) -> RuntimeArrayData:
"""Project selected provenance planes through their declared pixel axis."""
if not source_plane_selection:
return self.attach_to(payload)
complete_source_axis = tuple(range(self.source_provenance.source_plane_count))
Expand All @@ -959,7 +967,7 @@ def project_declared_source_image(
raise ValueError(
"Declared source-image channel projection requires exactly "
f"one channel; got source planes {source_plane_selection!r} "
f"for {source_image_name!r}."
"for the requested source selection."
)
return self.project_channel_payload(
payload,
Expand Down
Loading
Loading