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
27 changes: 23 additions & 4 deletions openhcs/core/orchestrator/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,18 @@ def create_context(

return context

def source_workspace_projection(self):
def source_workspace_projection(
self, *, resolved_config: GlobalPipelineConfig | None = None
):
"""Return the canonical resolved source state for the initialized plate.

The projection carries every named alias, sample/well, site, channel, Z,
timepoint, and backend-owned pixel reference used by compilation, runtime,
and UI inspection. Consumers must query this view rather than constructing
a second metadata model.

Compilation supplies its already-resolved configuration; live inspection
resolves the current saved configuration at this query boundary.
"""
if not self.is_initialized():
raise RuntimeError(
Expand All @@ -699,7 +704,10 @@ def source_workspace_projection(self):
metadata_handler=self.microscope_handler.metadata_handler,
filemanager=self.filemanager,
source_bindings=source_bindings_defaults_to_base(
self.get_effective_config().source_bindings_config
(
self.get_effective_config()
if resolved_config is None else resolved_config
).source_bindings_config
),
).projection_if_available()
if projection is not None:
Expand Down Expand Up @@ -801,6 +809,8 @@ def get_component_keys(
self,
component: Union["AllComponents", "VariableComponents"],
component_filter: Optional[List[Union[str, int]]] = None,
*,
resolved_config: GlobalPipelineConfig | None = None,
) -> List[str]:
"""
Generic method to get component keys using VariableComponents directly.
Expand All @@ -814,6 +824,8 @@ def get_component_keys(
component: AllComponents or VariableComponents enum specifying which component to extract
(also accepts GroupBy enum which will be converted to AllComponents)
component_filter: Optional list of component values to filter by
resolved_config: Existing compilation configuration. Omit for live
inspection of the current saved declaration.

Returns:
List of component values as strings, sorted
Expand All @@ -833,16 +845,23 @@ def get_component_keys(
# Convert to AllComponents for cache lookup (includes multiprocessing axis)
component = convert_enum_by_value(component, AllComponents) or component

effective_config = (
self.get_effective_config() if resolved_config is None else resolved_config
)
source_bindings = source_bindings_defaults_to_base(
self.get_effective_config().source_bindings_config
effective_config.source_bindings_config
)
# Use component directly - let natural errors occur for wrong types
component_name = component.value

# Try metadata cache first (preferred source)
cached_metadata = self._metadata_cache_service.get_cached_metadata(component)
if source_bindings.source_filter_declarations:
all_components = list(self.source_workspace_projection().component_values(component))
all_components = list(
self.source_workspace_projection(
resolved_config=effective_config
).component_values(component)
)
elif cached_metadata:
all_components = list(cached_metadata.keys())
logger.debug(
Expand Down
26 changes: 19 additions & 7 deletions openhcs/core/pipeline/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def _compile_sequential_runtime_filter_plan(
for seq_component in seq_config.sequential_components
if len(
session.orchestrator.get_component_keys(
AllComponents(seq_component.value)
AllComponents(seq_component.value),
resolved_config=session.global_config,
)
)
> 1
Expand Down Expand Up @@ -504,7 +505,9 @@ def declare_zarr_stores(session: CompilationSession) -> None:

context = session.context
orchestrator = session.orchestrator
all_wells = orchestrator.get_component_keys(get_multiprocessing_axis())
all_wells = orchestrator.get_component_keys(
get_multiprocessing_axis(), resolved_config=session.global_config
)

# Access config from merged config (pipeline + global) for proper inheritance
vfs_config = session.global_config.vfs_config
Expand Down Expand Up @@ -690,7 +693,9 @@ def analyze_pipeline_sequential_mode(
component_enum = AllComponents(seq_comp)

# Get component values from orchestrator's cache (populated from filename parsing)
component_values = orchestrator.get_component_keys(component_enum)
component_values = orchestrator.get_component_keys(
component_enum, resolved_config=global_config
)

if not component_values:
logger.warning(f"No {seq_comp} values found in orchestrator cache")
Expand Down Expand Up @@ -907,7 +912,7 @@ def _axis_values_to_process(
)
if well_filter_config and well_filter_config.well_filter is not None:
available_wells = orchestrator.get_component_keys(
get_multiprocessing_axis()
get_multiprocessing_axis(), resolved_config=effective_config
)
resolved_wells = WellFilterProcessor.resolve_filter_with_mode(
well_filter_config.well_filter,
Expand All @@ -931,6 +936,7 @@ def _axis_values_to_process(
return orchestrator.get_component_keys(
get_multiprocessing_axis(),
resolved_axis_filter,
resolved_config=effective_config,
)

@staticmethod
Expand Down Expand Up @@ -994,6 +1000,7 @@ def _resolve_global_step_axis_filters(
pipeline,
temp_context,
orchestrator,
global_config,
)
return temp_context.step_axis_filters

Expand Down Expand Up @@ -1657,11 +1664,13 @@ def compile_pipelines(
filemanager=orchestrator.filemanager,
input_dir=orchestrator.input_dir,
available_axis_values=orchestrator.get_component_keys(
get_multiprocessing_axis()
get_multiprocessing_axis(), resolved_config=effective_config
),
),
source_projections_by_axis=DEFAULT_SOURCE_PROJECTION_CACHE.partition_by_axes(
orchestrator.source_workspace_projection(),
orchestrator.source_workspace_projection(
resolved_config=effective_config
),
axis_ids=axis_values_to_process,
),
enable_visualizer_override=enable_visualizer_override,
Expand Down Expand Up @@ -1734,6 +1743,7 @@ def _resolve_step_axis_filters(
pipeline: ResolvedPipelineDefinition,
context,
orchestrator,
global_config: GlobalPipelineConfig,
):
"""
Resolve axis filters for steps with any WellFilterConfig instances.
Expand All @@ -1750,7 +1760,9 @@ def _resolve_step_axis_filters(

# Get available axis values from orchestrator using multiprocessing axis

available_axis_values = orchestrator.get_component_keys(get_multiprocessing_axis())
available_axis_values = orchestrator.get_component_keys(
get_multiprocessing_axis(), resolved_config=global_config
)
if not available_axis_values:
logger.warning("No available axis values found for axis filter resolution")
return
Expand Down
11 changes: 9 additions & 2 deletions openhcs/core/pipeline/path_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ def context_producer_scope(
if source_component is None:
return PathPlannerGroupScope.ungrouped()
source_keys = tuple(
self.planner.orchestrator.get_component_keys(source_component)
self.planner.orchestrator.get_component_keys(
source_component, resolved_config=self.planner.session.global_config
)
)
return (
PathPlannerGroupScope.from_raw(source_keys, component=source_component)
Expand Down Expand Up @@ -504,7 +506,12 @@ def dynamic_execution_scope_for_group_by(
if group_by_component is None:
return PathPlannerGroupScope.ungrouped()
source_keys = (
tuple(self.planner.orchestrator.get_component_keys(group_by_component))
tuple(
self.planner.orchestrator.get_component_keys(
group_by_component,
resolved_config=self.planner.session.global_config,
)
)
if step.processing_config.input_source is InputSource.PIPELINE_START
else ()
)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_materialization_filter_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _resolved_checkpoint(
orchestrator = SimpleNamespace(
plate_path=plate_path,
pipeline_config=pipeline_config,
get_component_keys=lambda _component: ["A01", "B02"],
get_component_keys=lambda _component, *, resolved_config: ["A01", "B02"],
create_context=lambda axis_id, *, resolved_config: SimpleNamespace(
axis_id=axis_id,
step_axis_filters={},
Expand Down
84 changes: 83 additions & 1 deletion tests/unit/test_microscope_virtual_workspace_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import pytest
from dataclasses import dataclass
from dataclasses import dataclass, replace
from pathlib import Path
from types import SimpleNamespace

Expand Down Expand Up @@ -63,6 +63,88 @@ def test_virtual_workspace_metadata_records_parser_owned_axis_values(
)


def test_compiler_source_queries_borrow_config_while_public_queries_stay_live(
tmp_path, monkeypatch
):
from unittest.mock import Mock
from objectstate.lazy_factory import ensure_global_config_context
from openhcs.core.config import GlobalPipelineConfig, PipelineConfig
from openhcs.core.orchestrator.orchestrator import PipelineOrchestrator
from openhcs.core.source_bindings import (
SourceBindingsConfig,
LazySourceBindingsConfig,
SourceFilterClause,
SourceFilterMatchType,
SourceFilterSubject,
)

source_handler = OperaPhenixHandler(SimpleNamespace())
(tmp_path / "Images").mkdir()
monkeypatch.setattr(
source_handler.metadata_handler, "get_grid_dimensions", lambda _: (3, 3)
)
monkeypatch.setattr(source_handler.metadata_handler, "get_pixel_size", lambda _: 1.0)
source_handler.save_virtual_workspace_metadata(
tmp_path,
{
"Images/r01c01f001p001-ch1sk1fk1fl1.tiff": SourcePixelRef(
"disk", "/source/source-a.tiff"
),
"Images/r02c03f001p001-ch1sk1fk1fl1.tiff": SourcePixelRef(
"disk", "/source/source-b.tiff"
),
},
)
metadata_path = tmp_path / "openhcs_metadata.json"
metadata_document = json.loads(metadata_path.read_text())
subdirectory = metadata_document[FIELDS.SUBDIRECTORIES]["Images"]
subdirectory[FIELDS.IMAGE_FILES] = list(subdirectory[FIELDS.WORKSPACE_MAPPING])
metadata_path.write_text(json.dumps(metadata_document))
source_a = SourceBindingsConfig(source_filters=(
SourceFilterClause(
SourceFilterSubject.FILE, SourceFilterMatchType.CONTAINS, "source-a"
),
))
source_b = SourceBindingsConfig(source_filters=(
SourceFilterClause(
SourceFilterSubject.FILE, SourceFilterMatchType.CONTAINS, "source-b"
),
))
held_config = GlobalPipelineConfig(source_bindings_config=source_a)
ensure_global_config_context(GlobalPipelineConfig, held_config)
owner = PipelineOrchestrator(
tmp_path,
pipeline_config=PipelineConfig(
source_bindings_config=LazySourceBindingsConfig(
source_filters=source_a.source_filters
)
),
resolved_config=held_config,
)
owner.initialize(resolved_config=held_config)
live_config = Mock(wraps=owner.get_effective_config)
monkeypatch.setattr(owner, "get_effective_config", live_config)

assert owner.get_component_keys(
AllComponents.WELL, resolved_config=held_config
) == ["R01C01"]
live_config.assert_not_called()
owner.pipeline_config = replace(
owner.pipeline_config,
source_bindings_config=LazySourceBindingsConfig(
source_filters=source_b.source_filters
),
)
owner.initialize()
live_config.reset_mock()
assert owner.get_component_keys(AllComponents.WELL) == ["R02C03"]
assert live_config.call_count == 1
assert owner.get_component_keys(
AllComponents.WELL, resolved_config=held_config
) == ["R01C01"]
assert live_config.call_count == 1


@pytest.mark.parametrize(
"spacing",
[
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_path_planner_materialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _artifact_planner_stub() -> PathPlanner:
),
)
planner.orchestrator = SimpleNamespace(
get_component_keys=lambda _component: (),
get_component_keys=lambda _component, *, resolved_config: (),
)
planner.plans = {
2: CompiledStepPlan(
Expand Down Expand Up @@ -3757,7 +3757,7 @@ def test_execution_groups_resolve_non_grouped_variable_component_conflicts():
def test_non_dict_group_by_declares_dynamic_scope_without_plate_key_lookup():
planner = _artifact_planner_stub()
planner.orchestrator = SimpleNamespace(
get_component_keys=lambda group_by: pytest.fail(
get_component_keys=lambda group_by, *, resolved_config: pytest.fail(
"non-dict group_by must not request plate component keys"
)
)
Expand Down
Loading