Skip to content

Commit

Permalink
api updates, test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni-t committed Mar 19, 2024
1 parent c451654 commit 9c9cbbf
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 20 deletions.
4 changes: 3 additions & 1 deletion api/src/opentrons/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ def _run_file_non_pe(

context.home()
try:
execute_apiv2.run_protocol(protocol, context)
# TODO (spp, 2024-03-18): use true run-time param overrides once enabled
# for cli protocol simulation/ execution
execute_apiv2.run_protocol(protocol, context, run_time_param_overrides=None)
finally:
context.cleanup()

Expand Down
4 changes: 3 additions & 1 deletion api/src/opentrons/protocol_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,6 @@ class EnumParameter(RTPBase):

RunTimeParameter = Union[IntParameter, FloatParameter, EnumParameter]

RTPOverridesType = Dict[str, Union[float, bool, str]] # update value types as more RTP types are added
RTPOverridesType = Dict[
str, Union[float, bool, str]
] # update value types as more RTP types are added
5 changes: 3 additions & 2 deletions api/src/opentrons/protocol_reader/protocol_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Read relevant protocol information from a set of files."""
from pathlib import Path
from typing import Optional, Sequence, Dict, Union
from typing import Optional, Sequence

from opentrons.protocols.parse import PythonParseMode

Expand Down Expand Up @@ -55,7 +55,8 @@ def __init__(
async def save(
self,
files: Sequence[BufferedFile],
directory: Path, content_hash: str,
directory: Path,
content_hash: str,
) -> ProtocolSource:
"""Compute a `ProtocolSource` from buffered files and save them as files.
Expand Down
10 changes: 8 additions & 2 deletions api/src/opentrons/protocol_runner/legacy_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,15 @@ class LegacyExecutor:
"""Interface to execute Protocol API v2 protocols in a child thread."""

@staticmethod
async def execute(protocol: LegacyProtocol, context: LegacyProtocolContext, run_time_param_overrides: Optional[RTPOverridesType]) -> None:
async def execute(
protocol: LegacyProtocol,
context: LegacyProtocolContext,
run_time_param_overrides: Optional[RTPOverridesType],
) -> None:
"""Execute a PAPIv2 protocol with a given ProtocolContext in a child thread."""
await to_thread.run_sync(run_protocol, protocol, context, run_time_param_overrides)
await to_thread.run_sync(
run_protocol, protocol, context, run_time_param_overrides
)


__all__ = [
Expand Down
20 changes: 12 additions & 8 deletions api/src/opentrons/protocol_runner/protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
LegacyExecutor,
LegacyLoadInfo,
)
from ..protocol_engine.types import PostRunHardwareState, DeckConfigurationType, \
RTPOverridesType
from ..protocol_engine.types import (
PostRunHardwareState,
DeckConfigurationType,
RTPOverridesType,
)


class RunResult(NamedTuple):
Expand Down Expand Up @@ -106,8 +109,8 @@ async def stop(self) -> None:
async def run(
self,
deck_configuration: DeckConfigurationType,
run_time_params_overrides: Optional[RTPOverridesType],
protocol_source: Optional[ProtocolSource] = None,
run_time_params_overrides: Optional[RTPOverridesType] = None,
) -> RunResult:
"""Run a given protocol to completion."""

Expand Down Expand Up @@ -137,17 +140,18 @@ def __init__(
self._legacy_executor = legacy_executor or LegacyExecutor()
# TODO(mc, 2022-01-11): replace task queue with specific implementations
# of runner interface
self._task_queue = (
task_queue or TaskQueue()
)
self._task_queue = task_queue or TaskQueue()
self._task_queue.set_cleanup_func(
func=protocol_engine.finish,
drop_tips_after_run=drop_tips_after_run,
post_run_hardware_state=post_run_hardware_state,
)

async def load(
self, protocol_source: ProtocolSource, python_parse_mode: PythonParseMode, run_time_params_overrides: Optional[RTPOverridesType],
self,
protocol_source: ProtocolSource,
python_parse_mode: PythonParseMode,
run_time_params_overrides: Optional[RTPOverridesType],
) -> None:
"""Load a Python or JSONv5(& older) ProtocolSource into managed ProtocolEngine."""
labware_definitions = await protocol_reader.extract_labware_definitions(
Expand Down Expand Up @@ -197,8 +201,8 @@ async def load(
async def run( # noqa: D102
self,
deck_configuration: DeckConfigurationType,
run_time_params_overrides: Optional[RTPOverridesType],
protocol_source: Optional[ProtocolSource] = None,
run_time_params_overrides: Optional[RTPOverridesType] = None,
python_parse_mode: PythonParseMode = PythonParseMode.NORMAL,
) -> RunResult:
# TODO(mc, 2022-01-11): move load to runner creation, remove from `run`
Expand Down
6 changes: 5 additions & 1 deletion api/src/opentrons/protocols/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
MODULE_LOG = logging.getLogger(__name__)


def run_protocol(protocol: Protocol, context: ProtocolContext, run_time_param_overrides: Optional[Dict[str, Union[float, bool, str]]]) -> None:
def run_protocol(
protocol: Protocol,
context: ProtocolContext,
run_time_param_overrides: Optional[Dict[str, Union[float, bool, str]]],
) -> None:
"""Run a protocol.
:param protocol: The :py:class:`.protocols.types.Protocol` to execute
Expand Down
4 changes: 3 additions & 1 deletion api/src/opentrons/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,9 @@ def _run_file_non_pe(
context.home()
with scraper.scrape():
try:
execute.run_protocol(protocol, context)
# TODO (spp, 2024-03-18): use true run-time param overrides once enabled
# for cli protocol simulation/ execution
execute.run_protocol(protocol, context, run_time_param_overrides=None)
if (
isinstance(protocol, PythonProtocol)
and protocol.api_level >= APIVersion(2, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ async def test_runner_with_python(
robot_type="OT-2 Standard",
protocol_config=protocol_source.config,
)
result = await subject.run(deck_configuration=[], protocol_source=protocol_source)
result = await subject.run(
deck_configuration=[],
protocol_source=protocol_source,
run_time_params_overrides=None,
)
commands_result = result.commands
pipettes_result = result.state_summary.pipettes
labware_result = result.state_summary.labware
Expand Down Expand Up @@ -114,7 +118,10 @@ async def test_runner_with_json(json_protocol_file: Path) -> None:
subject = await create_simulating_runner(
robot_type="OT-2 Standard", protocol_config=protocol_source.config
)
result = await subject.run(deck_configuration=[], protocol_source=protocol_source)
result = await subject.run(
deck_configuration=[],
protocol_source=protocol_source,
)

commands_result = result.commands
pipettes_result = result.state_summary.pipettes
Expand Down Expand Up @@ -176,7 +183,11 @@ async def test_runner_with_legacy_python(legacy_python_protocol_file: Path) -> N
robot_type="OT-2 Standard",
protocol_config=protocol_source.config,
)
result = await subject.run(deck_configuration=[], protocol_source=protocol_source)
result = await subject.run(
deck_configuration=[],
protocol_source=protocol_source,
run_time_params_overrides=None,
)

commands_result = result.commands
pipettes_result = result.state_summary.pipettes
Expand Down Expand Up @@ -235,7 +246,11 @@ async def test_runner_with_legacy_json(legacy_json_protocol_file: Path) -> None:
subject = await create_simulating_runner(
robot_type="OT-2 Standard", protocol_config=protocol_source.config
)
result = await subject.run(deck_configuration=[], protocol_source=protocol_source)
result = await subject.run(
deck_configuration=[],
protocol_source=protocol_source,
run_time_params_overrides=None,
)

commands_result = result.commands
pipettes_result = result.state_summary.pipettes
Expand Down
3 changes: 3 additions & 0 deletions api/tests/opentrons/protocol_runner/test_protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ async def test_load_legacy_python(
await legacy_python_runner_subject.load(
legacy_protocol_source,
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
run_time_params_overrides=None,
)

decoy.verify(
Expand Down Expand Up @@ -526,6 +527,7 @@ async def test_load_python_with_pe_papi_core(
await legacy_python_runner_subject.load(
legacy_protocol_source,
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
run_time_params_overrides=None,
)

decoy.verify(protocol_engine.add_plugin(matchers.IsA(LegacyContextPlugin)), times=0)
Expand Down Expand Up @@ -587,6 +589,7 @@ async def test_load_legacy_json(
await legacy_python_runner_subject.load(
legacy_protocol_source,
python_parse_mode=PythonParseMode.ALLOW_LEGACY_METADATA_AND_REQUIREMENTS,
run_time_params_overrides=None,
)

decoy.verify(
Expand Down

0 comments on commit 9c9cbbf

Please sign in to comment.