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
174 changes: 67 additions & 107 deletions benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,111 +3,71 @@
from __future__ import annotations

import openhcs as _openhcs_dependency_bootstrap # noqa: F401

__all__ = (
"DatasetSpec",
"AcquiredDataset",
"MetricCollector",
"BenchmarkResult",
"ToolAdapter",
"ToolAdapterError",
"ToolExecutionError",
"ToolNotInstalledError",
"ToolVersionError",
"DatasetAcquisitionError",
"acquire_dataset",
"BBBC021_SINGLE_PLATE",
"DATASET_REGISTRY",
"get_dataset_spec",
"PipelineSpec",
"NUCLEI_SEGMENTATION",
"PIPELINE_REGISTRY",
"get_pipeline_spec",
"TimeMetric",
"MemoryMetric",
"BenchmarkCaseProgress",
"BenchmarkProgressEvent",
"BenchmarkProgressEventKind",
"BenchmarkProgressSnapshot",
"iter_progress_events",
"summarize_progress",
"CellProfilerAdapter",
"OpenHCSAdapter",
"CellProfilerCompatibilityResult",
"run_benchmark",
"run_cellprofiler_compatibility_benchmark",
from python_introspect import lazy_exports

__all__ = lazy_exports(
globals(),
{
"benchmark.contracts.dataset": (
"DatasetSpec",
"AcquiredDataset",
),
"benchmark.contracts.metric": (
"MetricCollector",
),
"benchmark.contracts.tool_adapter": (
"BenchmarkResult",
"ToolAdapter",
"ToolAdapterError",
"ToolExecutionError",
"ToolNotInstalledError",
"ToolVersionError",
),
"benchmark.datasets.acquire": (
"DatasetAcquisitionError",
"acquire_dataset",
),
"benchmark.datasets": (
"BBBC021_SINGLE_PLATE",
"DATASET_REGISTRY",
),
"benchmark.datasets.registry": (
"get_dataset_spec",
),
"benchmark.contracts.pipeline": (
"PipelineSpec",
),
"benchmark.pipelines": (
"NUCLEI_SEGMENTATION",
),
"benchmark.pipelines.registry": (
"PIPELINE_REGISTRY",
"get_pipeline_spec",
),
"benchmark.metrics.time": (
"TimeMetric",
),
"benchmark.metrics.memory": (
"MemoryMetric",
),
"benchmark.progress": (
"BenchmarkCaseProgress",
"BenchmarkProgressEvent",
"BenchmarkProgressEventKind",
"BenchmarkProgressSnapshot",
"iter_progress_events",
"summarize_progress",
),
"benchmark.adapters.cellprofiler": (
"CellProfilerAdapter",
),
"benchmark.adapters.openhcs": (
"OpenHCSAdapter",
),
"benchmark.runner": (
"CellProfilerCompatibilityResult",
"run_benchmark",
"run_cellprofiler_compatibility_benchmark",
),
},
)

_EXPORT_NAMES = frozenset(__all__)
_MISSING_EXPORT = object()


def _benchmark_export_modules():
import benchmark.contracts.dataset as dataset_contracts

yield dataset_contracts

import benchmark.contracts.metric as metric_contracts

yield metric_contracts

import benchmark.contracts.pipeline as pipeline_contracts

yield pipeline_contracts

import benchmark.contracts.tool_adapter as tool_adapter_contracts

yield tool_adapter_contracts

import benchmark.datasets as dataset_exports

yield dataset_exports

import benchmark.pipelines as pipeline_exports

yield pipeline_exports

import benchmark.metrics as metric_exports

yield metric_exports

import benchmark.progress as progress_exports

yield progress_exports

import benchmark.adapters.openhcs as openhcs_adapter

yield openhcs_adapter

import benchmark.adapters.cellprofiler as cellprofiler_adapter

yield cellprofiler_adapter

import benchmark.runner as runner_exports

yield runner_exports


def resolve_benchmark_export(name: str):
"""Resolve one public benchmark export from its owning module."""
if name not in _EXPORT_NAMES:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
existing = globals().get(name, _MISSING_EXPORT)
if existing is not _MISSING_EXPORT:
return existing
for module in _benchmark_export_modules():
namespace = vars(module)
if name in namespace:
value = namespace[name]
globals()[name] = value
return value
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __getattr__(name: str):
"""Resolve public benchmark re-exports from their owning modules on demand."""
return resolve_benchmark_export(name)


def __dir__() -> list[str]:
return sorted(set(globals()) | _EXPORT_NAMES)
48 changes: 9 additions & 39 deletions benchmark/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,12 @@

from __future__ import annotations

__all__ = ("CellProfilerAdapter", "OpenHCSAdapter")

_EXPORT_NAMES = frozenset(__all__)
_MISSING_EXPORT = object()


def _adapter_export_modules():
import benchmark.adapters.openhcs as openhcs_adapter

yield openhcs_adapter

import benchmark.adapters.cellprofiler as cellprofiler_adapter

yield cellprofiler_adapter


def resolve_adapter_export(name: str):
"""Resolve one public adapter export from its owning module."""
if name not in _EXPORT_NAMES:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
existing = globals().get(name, _MISSING_EXPORT)
if existing is not _MISSING_EXPORT:
return existing
for module in _adapter_export_modules():
namespace = vars(module)
if name in namespace:
value = namespace[name]
globals()[name] = value
return value
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


def __getattr__(name: str):
"""Resolve public adapter re-exports from their owning modules on demand."""
return resolve_adapter_export(name)


def __dir__() -> list[str]:
return sorted(set(globals()) | _EXPORT_NAMES)
from python_introspect import lazy_exports

__all__ = lazy_exports(
globals(),
{
".cellprofiler": ("CellProfilerAdapter",),
".openhcs": ("OpenHCSAdapter",),
},
)
2 changes: 1 addition & 1 deletion benchmark/agent_validation/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from benchmark.agent_validation.perturbations import DiagnosticPerturbationDeclaration
from benchmark.agent_validation.scoring import AttemptJournalScorer
from openhcs.core.pipeline_document import PipelineDocumentAuthority
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable


@dataclass(frozen=True, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/agent_validation/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path

from benchmark.agent_validation.contracts import AttemptRecord
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable


@dataclass(frozen=True, slots=True)
Expand Down
5 changes: 2 additions & 3 deletions benchmark/agent_validation/mcp_attempt_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dataclasses import dataclass, fields
from pathlib import Path

from python_introspect import dataclass_from_mapping
from python_introspect import JsonObject, dataclass_from_mapping, to_jsonable

from benchmark.agent_validation.contracts import (
ArchitectureViolation,
Expand Down Expand Up @@ -49,7 +49,7 @@
ValidatePipelineCapability,
get_agent_capability,
)
from openhcs.agent.dto.common import JsonObject, RenderedSource
from openhcs.agent.dto.common import RenderedSource
from openhcs.agent.dto.execution import ArtifactPlanInspection, ExecutionJobRef
from openhcs.agent.dto.functions import (
CustomFunctionRegistrationResult,
Expand All @@ -66,7 +66,6 @@
McpDevToolResult,
first_payload_mapping,
)
from openhcs.serialization.json import to_jsonable


@dataclass(frozen=True, slots=True)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/annotated_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from zipfile import ZipFile
from collections.abc import Iterator
from metaclass_registry import AutoRegisterMeta
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable
from openhcs.core.runtime_measurements import MeasurementRowAxisField
from openhcs.processing.backends.cellprofiler.intensity import (
MeasureObjectIntensityModule,
Expand Down
10 changes: 5 additions & 5 deletions benchmark/cellprofiler_benchmark_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def configure(
def run(self, args: argparse.Namespace) -> int:
from benchmark.contracts.control import BenchmarkRunInspectionRequest
from benchmark.control import inspect_benchmark_run, report_benchmark_run
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable

inspection = inspect_benchmark_run(
BenchmarkRunInspectionRequest(
Expand Down Expand Up @@ -149,7 +149,7 @@ def run(self, args: argparse.Namespace) -> int:
inspect_measured_pipeline_run,
report_measured_pipeline_run,
)
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable

inspection = inspect_measured_pipeline_run(args.output_dir)
if args.report:
Expand Down Expand Up @@ -226,7 +226,7 @@ def run(self, args: argparse.Namespace) -> int:
from openhcs.runtime.zmq_execution_signature import (
ZMQRuntimeObservationExportScope,
)
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable

output_dir = args.output_dir.expanduser().resolve()
policy = AgentPathPolicy.with_roots(
Expand Down Expand Up @@ -333,7 +333,7 @@ def configure(

def run(self, args: argparse.Namespace) -> int:
from benchmark.control import discover_benchmark_cases
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable

result = discover_benchmark_cases(
args.manifest,
Expand Down Expand Up @@ -422,7 +422,7 @@ def run(self, args: argparse.Namespace) -> int:
well_throughput_start_method_from_manifest,
)
from openhcs.core.config import MultiprocessingStartMethod
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable

if args.max_memory_mb is not None and (
not math.isfinite(args.max_memory_mb) or args.max_memory_mb <= 0
Expand Down
3 changes: 1 addition & 2 deletions benchmark/contracts/measured_run_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
from pathlib import Path
from typing import Self

from python_introspect import dataclass_from_mapping
from python_introspect import dataclass_from_mapping, to_jsonable

from benchmark.contracts.run_artifacts import write_new_measured_artifact
from benchmark.timing import PhaseTimingRecord
from openhcs.runtime.environment_provenance import RuntimeEnvironmentSnapshot
from openhcs.runtime.zmq_execution_signature import ZMQRuntimeObservationExportScope
from openhcs.serialization.json import to_jsonable

MEASURED_PIPELINE_RUN_RECEIPT_SCHEMA_VERSION = "openhcs.benchmark.measured-pipeline.v2"
_ARCHIVED_MEASURED_PIPELINE_RUN_RECEIPT_SCHEMA_VERSION = (
Expand Down
3 changes: 1 addition & 2 deletions benchmark/contracts/run_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
from pathlib import Path
from typing import Self

from python_introspect import dataclass_from_mapping
from python_introspect import dataclass_from_mapping, to_jsonable

from openhcs.serialization.json import to_jsonable

COMPARISON_SUITE_RUN_RECEIPT_SCHEMA_VERSION = (
"openhcs.benchmark.comparison-suite-run.v1"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Dataset utilities and registry."""

from openhcs.core.public_api import public_names_from_objects
from python_introspect import public_names_from_objects

from benchmark.contracts.dataset import (
ArchiveFormat,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/matched_cellprofiler_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
ZMQAuxiliaryExecutionParams,
ZMQRuntimeObservationExportScope,
)
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable


def _parser() -> argparse.ArgumentParser:
Expand Down
2 changes: 1 addition & 1 deletion benchmark/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Metric collectors."""

from openhcs.core.public_api import public_names_from_objects
from python_introspect import public_names_from_objects

from benchmark.metrics.time import TimeMetric
from benchmark.metrics.memory import MemoryMetric
Expand Down
2 changes: 1 addition & 1 deletion benchmark/native_measurement_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
RuntimeMeasurementSnapshot,
runtime_measurement_projection_cache_identity,
)
from openhcs.serialization.json import to_jsonable
from python_introspect import to_jsonable


def _policy_identity(value):
Expand Down
2 changes: 1 addition & 1 deletion benchmark/pipelines/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Pipeline registry."""

from openhcs.core.public_api import public_names_from_objects
from python_introspect import public_names_from_objects

from benchmark.contracts.pipeline import PipelineSpec
from benchmark.pipelines.registry import (
Expand Down
Loading
Loading