Skip to content

Commit

Permalink
move lru_cache to ul_per_mm
Browse files Browse the repository at this point in the history
  • Loading branch information
amit lissack committed Apr 5, 2022
1 parent e3fdba8 commit b70ae8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 0 additions & 7 deletions api/src/opentrons/hardware_control/instrument_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Shared code for managing pipette configuration and storage."""
import functools
from dataclasses import dataclass
import logging
from typing import (
Expand Down Expand Up @@ -50,8 +49,6 @@

AxisType = TypeVar("AxisType", Axis, OT3Axis)

PLUNGER_CACHE_LIMIT = 32


@dataclass(frozen=True)
class LiquidActionSpec(Generic[AxisType]):
Expand Down Expand Up @@ -396,22 +393,19 @@ def ready_for_tip_action(self, target: Pipette, action: HardwareAction) -> None:
raise RuntimeError("Pipette not ready to aspirate")
self._ihp_log.debug(f"{action} on {target.name}")

@functools.lru_cache(PLUNGER_CACHE_LIMIT)
def plunger_position(
self, instr: Pipette, ul: float, action: "UlPerMmAction"
) -> float:
mm = ul / instr.ul_per_mm(ul, action)
position = mm + instr.config.bottom
return round(position, 6)

@functools.lru_cache(PLUNGER_CACHE_LIMIT)
def plunger_speed(
self, instr: Pipette, ul_per_s: float, action: "UlPerMmAction"
) -> float:
mm_per_s = ul_per_s / instr.ul_per_mm(instr.config.max_volume, action)
return round(mm_per_s, 6)

@functools.lru_cache(PLUNGER_CACHE_LIMIT)
def plunger_flowrate(
self, instr: Pipette, mm_per_s: float, action: "UlPerMmAction"
) -> float:
Expand Down Expand Up @@ -902,7 +896,6 @@ def get_pipette(self, mount: MountType) -> Pipette:
class OT3InstrumentHandler(InstrumentHandlerProvider[OT3Mount]):
"""Override for correct plunger_position."""

@functools.lru_cache(PLUNGER_CACHE_LIMIT)
def plunger_position(
self, instr: Pipette, ul: float, action: "UlPerMmAction"
) -> float:
Expand Down
5 changes: 5 additions & 0 deletions api/src/opentrons/hardware_control/pipette.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import functools

""" Classes and functions for pipette state tracking
"""
from dataclasses import asdict, replace
Expand Down Expand Up @@ -287,6 +289,9 @@ def remove_tip(self) -> None:
def has_tip(self) -> bool:
return self._has_tip

# Cache max is chosen somewhat arbitrarily. With a float is input we don't
# want this to unbounded.
@functools.lru_cache(maxsize=100)
def ul_per_mm(self, ul: float, action: UlPerMmAction) -> float:
sequence = self._config.ul_per_mm[action]
return pipette_config.piecewise_volume_conversion(ul, sequence)
Expand Down

0 comments on commit b70ae8e

Please sign in to comment.