Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): Do not enqueue json commands on protocol load #14759

Merged
merged 22 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
07b01f5
added schema definition for fixtures
TamarZanzouri Sep 14, 2023
e44a81a
initial move commands list into task_queue
TamarZanzouri Mar 26, 2024
a073995
moved logic from task queue into runner for json protocols
TamarZanzouri Mar 27, 2024
ce43819
reverted task queue changes
TamarZanzouri Mar 27, 2024
004e498
json runner with Event set and wait. fixed v6 upload test
TamarZanzouri Mar 28, 2024
e2d4658
reverted task queue changes and use runner._run method instead
TamarZanzouri Mar 29, 2024
f87b1db
Delete shared-data/fixture/schemas/1.json
TamarZanzouri Mar 29, 2024
3d7c688
clean up
TamarZanzouri Mar 29, 2024
23c7d40
Merge branch 'edge' into EXEC-352-do-not-enqueue-json-protocol-commands
TamarZanzouri Mar 29, 2024
747974c
fixed failing test from merge
TamarZanzouri Apr 1, 2024
bd2afe5
fixed failing test
TamarZanzouri Apr 1, 2024
335c10d
started adding tests WIP
TamarZanzouri Apr 2, 2024
2e1c4f4
added captors and tested add_and_execute_command
TamarZanzouri Apr 2, 2024
cb83ccf
added test for break on stop
TamarZanzouri Apr 2, 2024
819d957
added test to not execute commands if run stopped
TamarZanzouri Apr 3, 2024
c5249d3
fixed logic with test
TamarZanzouri Apr 3, 2024
6c812d6
added tests for papi and json play and stop in the middle of a run
TamarZanzouri Apr 4, 2024
76aa3e5
fixed unit test to match logic in e2e test
TamarZanzouri Apr 4, 2024
d3b0cd3
changed tests to use delay and wait for a running state
TamarZanzouri Apr 4, 2024
25344bd
Update robot-server/tests/integration/http_api/runs/test_play_stop_pa…
TamarZanzouri Apr 4, 2024
02a6ead
removed retry on get run commands
TamarZanzouri Apr 4, 2024
123f313
removed retry
TamarZanzouri Apr 4, 2024
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
19 changes: 15 additions & 4 deletions api/src/opentrons/protocol_runner/protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
LegacyExecutor,
LegacyLoadInfo,
)
from ..protocol_engine.errors import ProtocolCommandFailedError
from ..protocol_engine.types import (
PostRunHardwareState,
DeckConfigurationType,
Expand Down Expand Up @@ -283,6 +284,7 @@ def __init__(
)

self._hardware_api.should_taskify_movement_execution(taskify=False)
self._queued_commands: List[pe_commands.CommandCreate] = []

async def load(self, protocol_source: ProtocolSource) -> None:
"""Load a JSONv6+ ProtocolSource into managed ProtocolEngine."""
Expand Down Expand Up @@ -324,17 +326,16 @@ async def load(self, protocol_source: ProtocolSource) -> None:
color=liquid.displayColor,
)
await _yield()

initial_home_command = pe_commands.HomeCreate(
params=pe_commands.HomeParams(axes=None)
)
# this command homes all axes, including pipette plugner and gripper jaw
self._protocol_engine.add_command(request=initial_home_command)

for command in commands:
self._protocol_engine.add_command(request=command)
await _yield()
SyntaxColoring marked this conversation as resolved.
Show resolved Hide resolved
self._queued_commands = commands

self._task_queue.set_run_func(func=self._protocol_engine.wait_until_complete)
self._task_queue.set_run_func(func=self._add_command_and_execute)

async def run( # noqa: D102
self,
Expand All @@ -355,6 +356,16 @@ async def run( # noqa: D102
commands = self._protocol_engine.state_view.commands.get_all()
return RunResult(commands=commands, state_summary=run_data, parameters=[])

async def _add_command_and_execute(self) -> None:
print(self._queued_commands)
TamarZanzouri marked this conversation as resolved.
Show resolved Hide resolved
for command in self._queued_commands:
result = await self._protocol_engine.add_and_execute_command(command)
if result and result.error:
raise ProtocolCommandFailedError(
original_error=result.error,
message=f"{result.error.errorType}: {result.error.detail}",
)


class LiveRunner(AbstractRunner):
"""Protocol runner implementation for live http protocols."""
Expand Down
75 changes: 68 additions & 7 deletions api/tests/opentrons/protocol_runner/test_protocol_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
from opentrons.util.broker import Broker

from opentrons import protocol_reader
from opentrons.protocol_engine import ProtocolEngine, Liquid, commands as pe_commands
from opentrons.protocol_engine import (
ProtocolEngine,
Liquid,
commands as pe_commands,
errors as pe_errors,
)
from opentrons.protocol_reader import (
ProtocolSource,
JsonProtocolConfig,
Expand Down Expand Up @@ -328,6 +333,54 @@ async def test_run_json_runner(
)


async def test_run_json_runner_stop_requested_breaks_loop(
decoy: Decoy,
hardware_api: HardwareAPI,
protocol_engine: ProtocolEngine,
task_queue: TaskQueue,
json_runner_subject: JsonRunner,
json_file_reader: JsonFileReader,
json_translator: JsonTranslator,
) -> None:
"""It should run a protocol to completion."""
labware_definition = LabwareDefinition.construct()
json_protocol_source = ProtocolSource(
directory=Path("/dev/null"),
main_file=Path("/dev/null/abc.json"),
files=[],
metadata={},
robot_type="OT-2 Standard",
config=JsonProtocolConfig(schema_version=6),
content_hash="abc123",
)

commands: List[pe_commands.CommandCreate] = [
pe_commands.HomeCreate(params=pe_commands.HomeParams())
]

json_protocol = ProtocolSchemaV6.construct() # type: ignore[call-arg]

decoy.when(
await protocol_reader.extract_labware_definitions(json_protocol_source)
).then_return([labware_definition])
decoy.when(json_file_reader.read(json_protocol_source)).then_return(json_protocol)
decoy.when(json_translator.translate_commands(json_protocol)).then_return(commands)

await json_runner_subject.load(json_protocol_source)

run_func_captor = matchers.Captor()

# Verify that the run func calls the right things:
run_func = run_func_captor.value
await run_func()

decoy.when(
await protocol_engine.add_and_execute_command(
pe_commands.HomeCreate(params=pe_commands.HomeParams())
)
).then_raise(pe_errors.RunStoppedError("run stopped"))


@pytest.mark.parametrize(
"schema_version, json_protocol",
[
Expand Down Expand Up @@ -385,6 +438,8 @@ async def test_load_json_runner(

await json_runner_subject.load(json_protocol_source)

run_func_captor = matchers.Captor()

decoy.verify(
protocol_engine.add_labware_definition(labware_definition),
protocol_engine.add_liquid(
Expand All @@ -393,24 +448,30 @@ async def test_load_json_runner(
protocol_engine.add_command(
request=pe_commands.HomeCreate(params=pe_commands.HomeParams(axes=None))
),
protocol_engine.add_command(
task_queue.set_run_func(func=run_func_captor),
)

# Verify that the run func calls the right things:
run_func = run_func_captor.value
await run_func()
decoy.verify(
await protocol_engine.add_and_execute_command(
request=pe_commands.WaitForResumeCreate(
params=pe_commands.WaitForResumeParams(message="hello")
)
),
),
protocol_engine.add_command(
await protocol_engine.add_and_execute_command(
request=pe_commands.WaitForResumeCreate(
params=pe_commands.WaitForResumeParams(message="goodbye")
)
),
),
protocol_engine.add_command(
await protocol_engine.add_and_execute_command(
request=pe_commands.LoadLiquidCreate(
params=pe_commands.LoadLiquidParams(
liquidId="water-id", labwareId="labware-id", volumeByWell={"A1": 30}
)
),
),
task_queue.set_run_func(func=protocol_engine.wait_until_complete),
)


Expand Down
Loading
Loading