Skip to content

Commit

Permalink
Remove length from TipState.
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxColoring committed Oct 9, 2024
1 parent 1f50f1d commit 463315b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 106 deletions.
8 changes: 2 additions & 6 deletions api/src/opentrons/protocol_engine/commands/pick_up_tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..errors import ErrorOccurrence, TipNotAttachedError
from ..resources import ModelUtils
from ..state import update_types
from ..types import DeckPoint, TipGeometry
from ..types import DeckPoint
from .pipetting_common import (
PipetteIdMixin,
WellLocationMixin,
Expand Down Expand Up @@ -132,11 +132,7 @@ async def execute(
)
state_update.update_tip_state(
pipette_id=pipette_id,
tip_geometry=TipGeometry(
volume=tip_geometry.volume,
length=tip_geometry.length,
diameter=tip_geometry.diameter,
),
tip_geometry=tip_geometry,
)
except TipNotAttachedError as e:
return DefinedErrorData(
Expand Down
4 changes: 3 additions & 1 deletion api/src/opentrons/protocol_engine/execution/gantry_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ def get_max_travel_z(self, pipette_id: str) -> float:
)
else:
instrument_height = VIRTUAL_MAX_OT3_HEIGHT
tip_length = self._state_view.tips.get_tip_length(pipette_id)

tip = self._state_view.pipettes.get_attached_tip(pipette_id=pipette_id)
tip_length = tip.length if tip is not None else 0
return instrument_height - tip_length

async def move_to(
Expand Down
10 changes: 1 addition & 9 deletions api/src/opentrons/protocol_engine/state/tips.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class TipState:

tips_by_labware_id: Dict[str, TipRackStateByWellName]
column_by_labware_id: Dict[str, List[List[str]]]

channels_by_pipette_id: Dict[str, int]
length_by_pipette_id: Dict[str, float]
active_channels_by_pipette_id: Dict[str, int]
nozzle_map_by_pipette_id: Dict[str, NozzleMap]

Expand All @@ -61,7 +61,6 @@ def __init__(self) -> None:
tips_by_labware_id={},
column_by_labware_id={},
channels_by_pipette_id={},
length_by_pipette_id={},
active_channels_by_pipette_id={},
nozzle_map_by_pipette_id={},
)
Expand Down Expand Up @@ -121,18 +120,15 @@ def _handle_succeeded_command(self, command: Command) -> None:
labware_id = command.params.labwareId
well_name = command.params.wellName
pipette_id = command.params.pipetteId
length = command.result.tipLength
self._set_used_tips(
pipette_id=pipette_id, well_name=well_name, labware_id=labware_id
)
self._state.length_by_pipette_id[pipette_id] = length

elif isinstance(
command.result,
(DropTipResult, DropTipInPlaceResult, unsafe.UnsafeDropTipInPlaceResult),
):
pipette_id = command.params.pipetteId
self._state.length_by_pipette_id.pop(pipette_id, None)

def _handle_failed_command(
self,
Expand Down Expand Up @@ -506,10 +502,6 @@ def has_clean_tip(self, labware_id: str, well_name: str) -> bool:

return well_state == TipRackWellState.CLEAN

def get_tip_length(self, pipette_id: str) -> float:
"""Return the given pipette's tip length."""
return self._state.length_by_pipette_id.get(pipette_id, 0)


def _drop_wells_before_starting_tip(
wells: TipRackStateByWellName, starting_tip_name: str
Expand Down
15 changes: 12 additions & 3 deletions api/tests/opentrons/protocol_engine/execution/test_gantry_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

from opentrons.protocol_engine.state.state import StateView
from opentrons.protocol_engine.state.motion import PipetteLocationData
from opentrons.protocol_engine.types import MotorAxis, DeckPoint, CurrentWell
from opentrons.protocol_engine.types import (
MotorAxis,
DeckPoint,
CurrentWell,
TipGeometry,
)
from opentrons.protocol_engine.errors import MustHomeError, InvalidAxisForRobotType

from opentrons.protocol_engine.execution.gantry_mover import (
Expand Down Expand Up @@ -499,7 +504,9 @@ def test_virtual_get_max_travel_z_ot2(
decoy.when(
mock_state_view.pipettes.get_instrument_max_height_ot2("pipette-id")
).then_return(42)
decoy.when(mock_state_view.tips.get_tip_length("pipette-id")).then_return(20)
decoy.when(mock_state_view.pipettes.get_attached_tip("pipette-id")).then_return(
TipGeometry(length=20, diameter=0, volume=0)
)

result = virtual_subject.get_max_travel_z("pipette-id")

Expand All @@ -513,7 +520,9 @@ def test_virtual_get_max_travel_z_ot3(
) -> None:
"""It should get the max travel z height with the state store."""
decoy.when(mock_state_view.config.robot_type).then_return("OT-3 Standard")
decoy.when(mock_state_view.tips.get_tip_length("pipette-id")).then_return(48)
decoy.when(mock_state_view.pipettes.get_attached_tip("pipette-id")).then_return(
TipGeometry(length=48, diameter=0, volume=0)
)

result = virtual_subject.get_max_travel_z("pipette-id")

Expand Down
87 changes: 0 additions & 87 deletions api/tests/opentrons/protocol_engine/state/test_tip_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,93 +908,6 @@ def test_has_tip_tip_rack(
assert result is True


def test_drop_tip(
subject: TipStore,
load_labware_command: commands.LoadLabware,
pick_up_tip_command: commands.PickUpTip,
drop_tip_command: commands.DropTip,
drop_tip_in_place_command: commands.DropTipInPlace,
unsafe_drop_tip_in_place_command: commands.unsafe.UnsafeDropTipInPlace,
supported_tip_fixture: pipette_definition.SupportedTipsDefinition,
) -> None:
"""It should be clear tip length when a tip is dropped."""
subject.handle_action(
actions.SucceedCommandAction(private_result=None, command=load_labware_command)
)
load_pipette_command = commands.LoadPipette.construct( # type: ignore[call-arg]
result=commands.LoadPipetteResult(pipetteId="pipette-id")
)
load_pipette_private_result = commands.LoadPipettePrivateResult(
pipette_id="pipette-id",
serial_number="pipette-serial",
config=LoadedStaticPipetteData(
channels=8,
max_volume=15,
min_volume=3,
model="gen a",
display_name="display name",
flow_rates=FlowRates(
default_aspirate={},
default_dispense={},
default_blow_out={},
),
tip_configuration_lookup_table={15: supported_tip_fixture},
nominal_tip_overlap={},
nozzle_offset_z=1.23,
home_position=4.56,
nozzle_map=get_default_nozzle_map(PipetteNameType.P300_SINGLE_GEN2),
back_left_corner_offset=Point(x=1, y=2, z=3),
front_right_corner_offset=Point(x=4, y=5, z=6),
pipette_lld_settings={},
),
)
subject.handle_action(
actions.SucceedCommandAction(
private_result=load_pipette_private_result, command=load_pipette_command
)
)

subject.handle_action(
actions.SucceedCommandAction(private_result=None, command=pick_up_tip_command)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 1.23

subject.handle_action(
actions.SucceedCommandAction(private_result=None, command=drop_tip_command)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 0

subject.handle_action(
actions.SucceedCommandAction(private_result=None, command=pick_up_tip_command)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 1.23

subject.handle_action(
actions.SucceedCommandAction(
private_result=None, command=drop_tip_in_place_command
)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 0

subject.handle_action(
actions.SucceedCommandAction(private_result=None, command=pick_up_tip_command)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 1.23

subject.handle_action(
actions.SucceedCommandAction(
private_result=None, command=unsafe_drop_tip_in_place_command
)
)
result = TipView(subject.state).get_tip_length("pipette-id")
assert result == 0


@pytest.mark.parametrize(
argnames=["nozzle_map", "expected_channels"],
argvalues=[
Expand Down

0 comments on commit 463315b

Please sign in to comment.