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
23 changes: 15 additions & 8 deletions openhcs/core/debug/debug_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,33 +132,39 @@ class DebugBoundary(ABC, metaclass=AutoRegisterMeta):

name: ClassVar[str | None] = None
progress_status: ClassVar[type[ProgressStatus]]

@classmethod
def reported_output_refs(
self, output_artifacts: DebugArtifactRefProjection,
cls, output_artifacts: DebugArtifactRefProjection,
) -> tuple[DebugArtifactRef, ...]:
return ()

@classmethod
def event_artifact_projection(
self,
cls,
output_artifacts: DebugArtifactRefProjection,
input_artifacts: DebugArtifactRefProjection,
) -> DebugArtifactRefProjection:
return input_artifacts

def validate_exception(self, exception: BaseException | None) -> None:
@classmethod
def validate_exception(cls, exception: BaseException | None) -> None:
if exception is not None:
raise ValueError(f"{self.name!r} debug events cannot carry an exception.")
raise ValueError(f"{cls.name!r} debug events cannot carry an exception.")


class ReportsOutputArtifactsDebugBoundary:
"""Trait for boundaries that report the artifacts the invocation produced."""

@classmethod
def reported_output_refs(
self, output_artifacts: DebugArtifactRefProjection,
cls, output_artifacts: DebugArtifactRefProjection,
) -> tuple[DebugArtifactRef, ...]:
return output_artifacts.refs

@classmethod
def event_artifact_projection(
self,
cls,
output_artifacts: DebugArtifactRefProjection,
input_artifacts: DebugArtifactRefProjection,
) -> DebugArtifactRefProjection:
Expand All @@ -179,9 +185,10 @@ class ExceptionDebugBoundary(ReportsOutputArtifactsDebugBoundary, DebugBoundary)
name = "exception"
progress_status = ErrorProgressStatus

def validate_exception(self, exception: BaseException | None) -> None:
@classmethod
def validate_exception(cls, exception: BaseException | None) -> None:
if exception is None:
raise ValueError(f"{self.name!r} debug events require an exception.")
raise ValueError(f"{cls.name!r} debug events require an exception.")


class DebugWorkerState(ABC, metaclass=AutoRegisterMeta):
Expand Down
2 changes: 1 addition & 1 deletion openhcs/processing/backends/assemblers/blending.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def weighted_samples(self, tile, mask, affine_sampler: Callable) -> tuple:
fy, fx = self.fractional_yx
if fy == 0 and fx == 0:
return tile * mask, mask
array_module = MemoryType(detect_memory_type(tile)).import_module()
array_module = MemoryType(detect_memory_type(tile)).library.module
identity_matrix = array_module.ones(2, dtype=array_module.float64)
kwargs = {
"offset": (-fy, -fx),
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/test_debug_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
UngroupedScope,
)
from openhcs.core.execution.compiled_step_plan import CompiledStepPlan
from openhcs.core.debug.debug_views import runtime_inspection_view
from openhcs.core.debug.debug_runtime import (
ReportsOutputArtifactsDebugBoundary,
NoOpDebugExecutionPolicy,
DebugArtifactRef,
DebugArtifactRefProjection,
Expand Down Expand Up @@ -404,11 +406,11 @@ def sink_install_request(

def test_debug_boundaries_own_progress_status_and_artifact_policy():
assert BeforeInvocationDebugBoundary.progress_status is StartedProgressStatus
assert not BeforeInvocationDebugBoundary.reports_output_artifacts
assert not issubclass(BeforeInvocationDebugBoundary, ReportsOutputArtifactsDebugBoundary)
assert AfterInvocationDebugBoundary.progress_status is SuccessProgressStatus
assert AfterInvocationDebugBoundary.reports_output_artifacts
assert issubclass(AfterInvocationDebugBoundary, ReportsOutputArtifactsDebugBoundary)
assert ExceptionDebugBoundary.progress_status is ErrorProgressStatus
assert ExceptionDebugBoundary.reports_output_artifacts
assert issubclass(ExceptionDebugBoundary, ReportsOutputArtifactsDebugBoundary)


class DebugSnapshotFileManagerStub:
Expand Down Expand Up @@ -559,7 +561,7 @@ def test_debug_artifact_boundary_has_no_name_key_reconstruction():
repository_root = Path(__file__).resolve().parents[2]
targets = (
(
repository_root / "openhcs/core/debug.py",
repository_root / "openhcs/core/debug/debug_runtime.py",
"DebugArtifactRefProjection",
{"from_artifact_plans"},
),
Expand Down Expand Up @@ -1089,7 +1091,7 @@ def test_projection_exception_contains_complete_invocation_context_without_debug
assert "module='CorrectIlluminationCalculate'" in message
assert "callable='correct_illumination_calculate'" in message
assert "kwarg_names=('runtime_adapter', 'threshold')" in message
assert "openhcs.core.runtime_image_values.ImageMetadataPayload" in message
assert "openhcs.core.payload.runtime_image_values.ImageMetadataPayload" in message
assert "plane_axis='runtime_slice'" in message
assert "declared_plane_axis='runtime_slice'" in message
assert "plane_index=preserved" in message
Expand Down Expand Up @@ -1560,7 +1562,7 @@ def test_paused_worker_runtime_inspection_projects_runtime_value_store():
controller.bind_context(context)
controller.apply_command(ChooseSourceGroupDebugCommand)

view_model = controller.runtime_inspection_view()
view_model = runtime_inspection_view(controller)

table = view_model.sections[0].table
assert table is not None
Expand Down Expand Up @@ -1593,7 +1595,7 @@ def test_runtime_inspection_control_payload_round_trips_view_model():
controller.bind_context(context)
controller.apply_command(ChooseSourceGroupDebugCommand)
response = DebugRuntimeInspectionResponse(
view_model=controller.runtime_inspection_view()
view_model=runtime_inspection_view(controller)
)

restored_response = DebugRuntimeInspectionResponse.from_control_response(
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/test_primary_object_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,20 @@ def visit_Call(self, node):
node.keywords = kept
return node

before = DeclaredLabelVariants().visit(PayloadAttributes().visit(before))
class MovedModule(ast.NodeTransformer):
"""The morphology backend moved into its family package."""

MOVED = {
"openhcs.processing.backends.cellprofiler.morphology":
"openhcs.processing.backends.cellprofiler.morphology_family.morphology",
}

def visit_ImportFrom(self, node):
node.module = self.MOVED.get(node.module, node.module)
return node

before = MovedModule().visit(
DeclaredLabelVariants().visit(PayloadAttributes().visit(before)))
# Compare the original algorithm, not docstring, signature or output ABI.
assert ast.dump(ast.Module(body=before.body[1:-1], type_ignores=[])) == ast.dump(
ast.Module(body=after.body[1:-1], type_ignores=[]))
Loading