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

refactor(api, robot-server): Refactor ProtocolRunner per protocol type #12343

Merged
merged 36 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2410782
WIP: created an abstract interface for ProtocolRunner. started JsonRu…
TamarZanzouri Mar 14, 2023
290e860
WIP create_protocol_runner
TamarZanzouri Mar 16, 2023
842a99e
test json_runner and finished logic for json_runner
TamarZanzouri Mar 17, 2023
f5b5325
WIP python and legacy runner
TamarZanzouri Mar 17, 2023
7de1dae
python and legacy runner implementation
TamarZanzouri Mar 20, 2023
8f30fa7
create_simulating_runner.py
TamarZanzouri Mar 20, 2023
c73922c
fixed robot server dependencies.py
TamarZanzouri Mar 21, 2023
33c260a
MaintenanceRunner
TamarZanzouri Mar 21, 2023
b727804
wip robot-server
TamarZanzouri Mar 21, 2023
5ecd3cb
changed create_simulating_runner to monkeypatch
TamarZanzouri Mar 22, 2023
037f322
removed set_run_started_at and fixed test failing on started_at
TamarZanzouri Mar 22, 2023
d54c1ec
rollback depends for protocol_analyzer.py and moved runner creation i…
TamarZanzouri Mar 22, 2023
af5aaac
reorganize prtocol_runner tests and text fixes
TamarZanzouri Mar 23, 2023
3a870b0
removed task_queue from maintenance runner
TamarZanzouri Mar 23, 2023
4009a37
Merge branch 'edge' into RSS-200-refactor-protocol-runner
TamarZanzouri Mar 23, 2023
50978e3
linting
TamarZanzouri Mar 23, 2023
20d3c3f
fixed failing test in actions router
TamarZanzouri Mar 23, 2023
08524fd
fixed maintenance test with task runner
TamarZanzouri Mar 23, 2023
da0fdba
Update api/src/opentrons/protocol_runner/protocol_runner.py
TamarZanzouri Mar 27, 2023
b38aaf7
pr feedback
TamarZanzouri Mar 27, 2023
14e2fa0
changed ProtocolRunResult to RunnerRunResult
TamarZanzouri Mar 27, 2023
5aa7899
added linting ignore
TamarZanzouri Mar 28, 2023
f36be33
fixed g-code testing
TamarZanzouri Mar 28, 2023
a81df1d
g-code testing fix
TamarZanzouri Mar 28, 2023
b647315
linting
TamarZanzouri Mar 28, 2023
e802d65
linting
TamarZanzouri Mar 28, 2023
923e00c
added pe.play for run live commands
TamarZanzouri Mar 28, 2023
e1e9ddd
added tavern test for posting protocol commands
TamarZanzouri Mar 29, 2023
88cae89
addressed PR comments, fixed live runner bug, updated tests
sanni-t Apr 5, 2023
742e292
updated tests, fixed linter errors
sanni-t Apr 5, 2023
93be36f
Merge branch 'edge' into RSS-200-refactor-protocol-runner
sanni-t Apr 7, 2023
56a1b2f
correct docstring
sanni-t Apr 7, 2023
b272e10
Apply suggestions from code review
sanni-t Apr 13, 2023
433ca47
fix runner smoke tests and linter errors, some renaming from PR review
sanni-t Apr 14, 2023
b6e7385
update runner typing & type naming, renamed set_task_queue_wait() to …
sanni-t Apr 14, 2023
5789c41
address all remaining review comments
sanni-t Apr 14, 2023
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
4 changes: 3 additions & 1 deletion api/src/opentrons/cli/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ async def _analyze(
except ProtocolFilesInvalidError as error:
raise click.ClickException(str(error))

runner = await create_simulating_runner(robot_type=protocol_source.robot_type)
runner = await create_simulating_runner(
robot_type=protocol_source.robot_type, protocol_config=protocol_source.config
)
analysis = await runner.run(protocol_source)

if json_output:
Expand Down
21 changes: 17 additions & 4 deletions api/src/opentrons/protocol_runner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
"""Protocol run control and management.

The main export of this module is the ProtocolRunner class. See
The main export of this module is the AbstractRunner class. See
protocol_runner.py for more details.
"""
from .protocol_runner import ProtocolRunner, ProtocolRunResult
from .protocol_runner import (
AbstractRunner,
RunResult,
create_protocol_runner,
JsonRunner,
PythonAndLegacyRunner,
LiveRunner,
RunnerType,
)
from .create_simulating_runner import create_simulating_runner

__all__ = [
"ProtocolRunner",
"ProtocolRunResult",
"AbstractRunner",
"RunResult",
"create_simulating_runner",
"create_protocol_runner",
"JsonRunner",
"PythonAndLegacyRunner",
"LiveRunner",
"RunnerType",
]
18 changes: 11 additions & 7 deletions api/src/opentrons/protocol_runner/create_simulating_runner.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
"""Simulating ProtocolRunner factory."""
"""Simulating AbstractRunner factory."""

from opentrons.config import feature_flags
from opentrons.hardware_control import API as OT2API, HardwareControlAPI
from opentrons.protocol_engine import (
Config as ProtocolEngineConfig,
create_protocol_engine,
)
from opentrons.protocol_reader.protocol_source import ProtocolConfig

from opentrons_shared_data.robot.dev_types import RobotType

from .legacy_wrappers import LegacySimulatingContextCreator
from .protocol_runner import ProtocolRunner
from .protocol_runner import create_protocol_runner, AbstractRunner


async def create_simulating_runner(robot_type: RobotType) -> ProtocolRunner:
"""Create a ProtocolRunner wired to a simulating HardwareControlAPI.
async def create_simulating_runner(
robot_type: RobotType, protocol_config: ProtocolConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if accepting a protocol_type makes more sense here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a TODO to address later.

) -> AbstractRunner:

This comment was marked as resolved.

"""Create a AbstractRunner wired to a simulating HardwareControlAPI.

Example:
```python
Expand All @@ -24,15 +27,15 @@ async def create_simulating_runner(robot_type: RobotType) -> ProtocolRunner:
from opentrons.protocol_runner import (
ProtocolType,
ProtocolFile,
ProtocolRunner,
AbstractRunner,
create_simulating_runner,
)

protocol = ProtocolFile(
protocol_type=ProtocolType.PYTHON,
files=[Path("/path/to/protocol.py")],
)
runner: ProtocolRunner = await create_simulating_runner()
runner: AbstractRunner = await create_simulating_runner()
commands: List[Command] = await runner.run(protocol)
```
"""
Expand Down Expand Up @@ -62,7 +65,8 @@ async def create_simulating_runner(robot_type: RobotType) -> ProtocolRunner:
protocol_engine=protocol_engine,
)

return ProtocolRunner(
return create_protocol_runner(
protocol_config=protocol_config,
protocol_engine=protocol_engine,
hardware_api=simulating_hardware_api,
legacy_context_creator=simulating_legacy_context_creator,
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/protocol_runner/legacy_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def read(
)


# TODO (spp, 2023-04-05): Remove 'legacy' wording since this is the context we are using
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# for all python protocols.
class LegacyContextCreator:
"""Interface to construct Protocol API v2 contexts."""

Expand Down
Loading