-
Notifications
You must be signed in to change notification settings - Fork 180
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
RFC: prototyping papi transfer + engine core + pe load liquid class #16602
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
"""Load liquid class command request, result, and implementation models.""" | ||
from __future__ import annotations | ||
|
||
from opentrons_shared_data.liquid_classes.liquid_class_definition import ( | ||
AspirateProperties, | ||
SingleDispenseProperties, | ||
MultiDispenseProperties, | ||
) | ||
from pydantic import BaseModel, Field | ||
from typing import Optional, Type, Dict, TYPE_CHECKING | ||
from typing_extensions import Literal | ||
|
||
from .command import AbstractCommandImpl, BaseCommand, BaseCommandCreate, SuccessData | ||
from ..errors.error_occurrence import ErrorOccurrence | ||
from ..types import ImmutableLiquidClass | ||
|
||
if TYPE_CHECKING: | ||
from ..state.state import StateView | ||
|
||
LoadLiquidClassCommandType = Literal["loadLiquidClass"] | ||
|
||
|
||
class LoadLiquidClassParams(BaseModel): | ||
"""Payload required to load a liquid into a well.""" | ||
|
||
pipetteId: str = Field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having the pipette id and tiprack id in here doesn't seem right to me. It means the command orchestration layer has to do a bunch of extra work to load the full liquid class and tie it back to a possibly-generated ID for the relevant pipette. It seems better to have the command take in the full liquid class, and then later when the command orchestration layer references the LC in a command like Also is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're totally right. Going to change this to accept the liquid class as is, and the engine then saves only the properties related to the pipette ID & tiprack uri in question. I want the engine to save only relevant parts of the liquid class so that the run summary doesn't get bloated because of parts of the liquid class that will be irrelevant not just to the transfer in question but the entire run. This will be definitely useful when handling built-in liquid classes which will have properties corresponding to all pipette+tiprack combos we support. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even trimming out unnecessary stuff strikes me as a bit of a premature optimization. IMO if we're going to put the data in the engine, we should put the entire data in the engine. Sure, the liquid classes are big, but you're gonna be using like 1-10ish of them per protocol, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, unlike other definitions like labware and modules, liquid class properties are going to be mutable. If the engine were to save the entire liquid class, then every time there's a change to the properties for a specific pipette+tip combination, the snapshots of the entire liquid class will need to be updated. If we save split properties per pipette+tip combination then only the snapshot of the specific combo will need to be updated. But I understand your point about pre-mature optimization; maybe the optimization above isn't worth the code bloat. I'll change this to saving complete liquid class and if we run into the above issue more often than we'd like to then I'll add the optimization. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @sfoster1, I don't know if saving the entire LiquidClass is a good idea, and trying to save the whole thing is making me struggle with how to represent the data in the PE. So LiquidClass starts out with the RECOMMENDED settings for every possible pipette and tip type, right? So it looks something like:
But for any given transfer, the user can customize the settings. So the user's code is going to look something like this:
Inside the implementation of
With your proposal to store the entire And in terms of implementation, if we have to store the entire |
||
..., | ||
description="Unique identifier of pipette to use with liquid class.", | ||
) | ||
tiprackId: str = Field( | ||
..., | ||
description="Unique identifier of tip rack to use with liquid class.", | ||
) | ||
aspirateProperties: AspirateProperties | ||
singleDispenseProperties: SingleDispenseProperties | ||
multiDispenseProperties: Optional[MultiDispenseProperties] | ||
liquidClassId: Optional[str] = Field( | ||
None, | ||
description="An optional ID to assign to this liquid class. If None, an ID " | ||
"will be generated.", | ||
) | ||
|
||
|
||
class LoadLiquidClassResult(BaseModel): | ||
"""Result data from the execution of a LoadLiquidClass command.""" | ||
|
||
loadedLiquidClass: ImmutableLiquidClass = Field( | ||
..., description="An immutable liquid class created from the load params." | ||
) | ||
|
||
|
||
class LoadLiquidClassImplementation( | ||
AbstractCommandImpl[LoadLiquidClassParams, SuccessData[LoadLiquidClassResult, None]] | ||
): | ||
"""Load liquid command implementation.""" | ||
|
||
def __init__(self, state_view: StateView, **kwargs: object) -> None: | ||
self._state_view = state_view | ||
|
||
async def execute( | ||
self, params: LoadLiquidClassParams | ||
) -> SuccessData[LoadLiquidClassResult, None]: | ||
"""Load data necessary for a liquid class.""" | ||
|
||
liq_class_hash = "create-a-hash" | ||
existing_liq_class = self._state_view.liquid.get_liq_class_by_hash( | ||
liq_class_hash | ||
) | ||
if existing_liq_class: | ||
liq_class = existing_liq_class | ||
else: | ||
liq_class = ImmutableLiquidClass( | ||
id="get-a-uuid", | ||
hash="create-a-hash", | ||
pipetteId=params.pipetteId, | ||
tiprackId=params.tiprackId, | ||
aspirateProperties=params.aspirateProperties, | ||
singleDispenseProperties=params.singleDispenseProperties, | ||
multiDispenseProperties=params.multiDispenseProperties, | ||
) | ||
# **** TODO: save liquid class to state ***** | ||
|
||
return SuccessData( | ||
public=LoadLiquidClassResult( | ||
loadedLiquidClass=liq_class, | ||
), | ||
private=None, | ||
) | ||
|
||
|
||
class LoadLiquidClass( | ||
BaseCommand[LoadLiquidClassParams, LoadLiquidClassResult, ErrorOccurrence] | ||
): | ||
"""Load liquid command resource model.""" | ||
|
||
commandType: LoadLiquidClassCommandType = "loadLiquidClass" | ||
params: LoadLiquidClassParams | ||
result: Optional[LoadLiquidClassResult] | ||
|
||
_ImplementationCls: Type[ | ||
LoadLiquidClassImplementation | ||
] = LoadLiquidClassImplementation | ||
|
||
|
||
class LoadLiquidClassCreate(BaseCommandCreate[LoadLiquidClassParams]): | ||
"""Load liquid command creation request.""" | ||
|
||
commandType: LoadLiquidClassCommandType = "loadLiquidClass" | ||
params: LoadLiquidClassParams | ||
|
||
_CommandCls: Type[LoadLiquidClass] = LoadLiquidClass |
This comment was marked as outdated.
Sorry, something went wrong.