From b70ae8edcb9ff482024e6668bf73549112a440d4 Mon Sep 17 00:00:00 2001 From: amit lissack Date: Tue, 5 Apr 2022 09:46:03 -0400 Subject: [PATCH] move lru_cache to ul_per_mm --- api/src/opentrons/hardware_control/instrument_handler.py | 7 ------- api/src/opentrons/hardware_control/pipette.py | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/api/src/opentrons/hardware_control/instrument_handler.py b/api/src/opentrons/hardware_control/instrument_handler.py index 246b50cb903..506accba70a 100644 --- a/api/src/opentrons/hardware_control/instrument_handler.py +++ b/api/src/opentrons/hardware_control/instrument_handler.py @@ -1,5 +1,4 @@ """Shared code for managing pipette configuration and storage.""" -import functools from dataclasses import dataclass import logging from typing import ( @@ -50,8 +49,6 @@ AxisType = TypeVar("AxisType", Axis, OT3Axis) -PLUNGER_CACHE_LIMIT = 32 - @dataclass(frozen=True) class LiquidActionSpec(Generic[AxisType]): @@ -396,7 +393,6 @@ 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: @@ -404,14 +400,12 @@ def plunger_position( 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: @@ -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: diff --git a/api/src/opentrons/hardware_control/pipette.py b/api/src/opentrons/hardware_control/pipette.py index 905c6257628..dabfa5bf678 100644 --- a/api/src/opentrons/hardware_control/pipette.py +++ b/api/src/opentrons/hardware_control/pipette.py @@ -1,5 +1,7 @@ from __future__ import annotations +import functools + """ Classes and functions for pipette state tracking """ from dataclasses import asdict, replace @@ -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)