Skip to content

Commit

Permalink
relocate valid map key to nozzle map
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyBatten committed May 24, 2024
1 parent 8247821 commit 939995f
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 150 deletions.
82 changes: 34 additions & 48 deletions api/src/opentrons/hardware_control/instruments/ot2/pipette.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def __init__(
)
self._nozzle_offset = self._config.nozzle_offset
self._nozzle_manager = (
nozzle_manager.NozzleConfigurationManager.build_from_config(self._config)
nozzle_manager.NozzleConfigurationManager.build_from_config(
self._config, self._valid_nozzle_maps
)
)
self._current_volume = 0.0
self._working_volume = float(self._liquid_class.max_volume)
Expand Down Expand Up @@ -303,7 +305,9 @@ def reset_state(self) -> None:
)

self._nozzle_manager = (
nozzle_manager.NozzleConfigurationManager.build_from_config(self._config)
nozzle_manager.NozzleConfigurationManager.build_from_config(
self._config, self._valid_nozzle_maps
)
)

def reset_pipette_offset(self, mount: Mount, to_default: bool) -> None:
Expand Down Expand Up @@ -531,77 +535,58 @@ def remove_tip(self) -> None:
def has_tip(self) -> bool:
return self._has_tip

def _get_matching_approved_nozzle_map(self) -> str:
for map_key in self._valid_nozzle_maps.maps.keys():
if self._valid_nozzle_maps.maps[map_key] == list(
self._nozzle_manager.current_configuration.map_store.keys()
):
return map_key
raise ValueError(
"Nozzle Configuration does not match any approved map layout for the current pipette."
)

def get_pick_up_speed_by_configuration(
self,
config: PressFitPickUpTipConfiguration,
) -> float:
approved_map = None
for map_key in self._valid_nozzle_maps.maps.keys():
if self._valid_nozzle_maps.maps[map_key] == list(
self._nozzle_manager.current_configuration.map_store.keys()
):
approved_map = map_key
if approved_map is None:
raise ValueError(
"Pick up tip speed request error. Nozzle Configuration does not match any approved map layout for the current pipette."
)

try:
return config.configuration_by_nozzle_map[approved_map][
pip_types.PipetteTipType(self._liquid_class.max_volume).name
].speed
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][pip_types.PipetteTipType(self._liquid_class.max_volume).name].speed
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.speed
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_pick_up_distance_by_configuration(
self,
config: PressFitPickUpTipConfiguration,
) -> float:
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
pip_types.PipetteTipType(self._liquid_class.max_volume).name
].distance
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][pip_types.PipetteTipType(self._liquid_class.max_volume).name].distance
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.distance
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_pick_up_current_by_configuration(
self,
config: PressFitPickUpTipConfiguration,
) -> float:
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
pip_types.PipetteTipType(self._liquid_class.max_volume).name
].current
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][pip_types.PipetteTipType(self._liquid_class.max_volume).name].current
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.current
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_nominal_tip_overlap_dictionary_by_configuration(
Expand All @@ -613,21 +598,22 @@ def get_nominal_tip_overlap_dictionary_by_configuration(
):
if not config:
continue
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][
pip_types.PipetteTipType(self._liquid_class.max_volume).name
].tip_overlap_dictionary
except KeyError:
try:
default = config.configuration_by_nozzle_map[approved_map].get(
"default"
)
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.tip_overlap_dictionary
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)
except KeyError:
# No valid key found for the approved nozzle map under this configuration - try the next
Expand Down
144 changes: 58 additions & 86 deletions api/src/opentrons/hardware_control/instruments/ot3/pipette.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def __init__(
)
self._nozzle_offset = self._config.nozzle_offset
self._nozzle_manager = (
nozzle_manager.NozzleConfigurationManager.build_from_config(self._config)
nozzle_manager.NozzleConfigurationManager.build_from_config(
self._config, self._valid_nozzle_maps
)
)
self._current_volume = 0.0
self._working_volume = float(self._liquid_class.max_volume)
Expand Down Expand Up @@ -265,7 +267,9 @@ def reset_state(self) -> None:
self.get_nominal_tip_overlap_dictionary_by_configuration()
)
self._nozzle_manager = (
nozzle_manager.NozzleConfigurationManager.build_from_config(self._config)
nozzle_manager.NozzleConfigurationManager.build_from_config(
self._config, self._valid_nozzle_maps
)
)

def reset_pipette_offset(self, mount: OT3Mount, to_default: bool) -> None:
Expand Down Expand Up @@ -669,131 +673,100 @@ def set_tip_type(self, tip_type: pip_types.PipetteTipType) -> None:
)
self._working_volume = min(tip_type.value, self.liquid_class.max_volume)

def _get_matching_approved_nozzle_map(self) -> str:
for map_key in self._valid_nozzle_maps.maps.keys():
if self._valid_nozzle_maps.maps[map_key] == list(
self._nozzle_manager.current_configuration.map_store.keys()
):
return map_key
raise ValueError(
"Nozzle Configuration does not match any approved map layout for the current pipette."
)

def get_pick_up_configuration_for_tip_count(
self, count: int
def get_pick_up_configuration( # noqa: C901
self,
) -> Union[CamActionPickUpTipConfiguration, PressFitPickUpTipConfiguration]:
for config in (
self._config.pick_up_tip_configurations.press_fit,
self._config.pick_up_tip_configurations.cam_action,
):
if not config:
continue
approved_map = self._get_matching_approved_nozzle_map()
config_values = None
try:
config_values = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][self._active_tip_setting_name.name]
except KeyError:
try:
config_values = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if config_values is None:
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)
except KeyError:
# No valid key found for the approved nozzle map under this configuration - try the next
continue
if config_values is not None:
if isinstance(config, PressFitPickUpTipConfiguration) and all(
[
config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].speed,
config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].distance,
config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].current,
config_values.speed,
config_values.distance,
config_values.current,
]
):
return config
elif (
config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].current
is not None
):
elif config_values.current is not None:
return config
except KeyError:
try:
if isinstance(config, PressFitPickUpTipConfiguration) and all(
[
config.configuration_by_nozzle_map[approved_map]
.get("default")
.speed,
config.configuration_by_nozzle_map[approved_map]
.get("default")
.distance,
config.configuration_by_nozzle_map[approved_map]
.get("default")
.current,
]
):
return config
elif (
config.configuration_by_nozzle_map[approved_map]
.get("default")
.current
is not None
):
return config
except KeyError:
# No valid key found for the approved nozzle map under this configuration - try the next
continue

raise CommandPreconditionViolated(
message=f"No pick up tip configuration for {count} tips",
message="No valid pick up tip configuration values found in instrument definition.",
)

def get_pick_up_speed_by_configuration(
self,
config: Union[CamActionPickUpTipConfiguration, PressFitPickUpTipConfiguration],
) -> float:
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].speed
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][self._active_tip_setting_name.name].speed
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.speed
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_pick_up_distance_by_configuration(
self,
config: Union[CamActionPickUpTipConfiguration, PressFitPickUpTipConfiguration],
) -> float:
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].distance
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][self._active_tip_setting_name.name].distance
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.distance
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_pick_up_current_by_configuration(
self,
config: Union[CamActionPickUpTipConfiguration, PressFitPickUpTipConfiguration],
) -> float:
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].current
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][self._active_tip_setting_name.name].current
except KeyError:
default = config.configuration_by_nozzle_map[approved_map].get("default")
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.current
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)

def get_nominal_tip_overlap_dictionary_by_configuration(self) -> Dict[str, float]:
Expand All @@ -803,21 +776,20 @@ def get_nominal_tip_overlap_dictionary_by_configuration(self) -> Dict[str, float
):
if not config:
continue
approved_map = self._get_matching_approved_nozzle_map()

try:
return config.configuration_by_nozzle_map[approved_map][
self._active_tip_setting_name.name
].tip_overlap_dictionary
return config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
][self._active_tip_setting_name.name].tip_overlap_dictionary
except KeyError:
try:
default = config.configuration_by_nozzle_map[approved_map].get(
"default"
)
default = config.configuration_by_nozzle_map[
self._nozzle_manager.current_configuration.valid_map_key
].get("default")
if default is not None:
return default.tip_overlap_dictionary
raise KeyError(
f"Default tip type configuration values do not exist for Nozzle Map {approved_map}."
f"Default tip type configuration values do not exist for Nozzle Map {self._nozzle_manager.current_configuration.valid_map_key}."
)
except KeyError:
# No valid key found for the approved nozzle map under this configuration - try the next
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def plan_ht_pick_up_tip(self, tip_count: int) -> TipActionSpec:
raise UnexpectedTipAttachError("pick_up_tip", instrument.name, mount.name)
self._ihp_log.debug(f"Picking up tip on {mount.name}")

pick_up_config = instrument.get_pick_up_configuration_for_tip_count(tip_count)
pick_up_config = instrument.get_pick_up_configuration()
if not isinstance(pick_up_config, CamActionPickUpTipConfiguration):
raise CommandPreconditionViolated(
f"Low-throughput pick up tip got wrong config for {instrument.name} on {mount.name}"
Expand Down Expand Up @@ -788,7 +788,7 @@ def plan_lt_pick_up_tip(
raise UnexpectedTipAttachError("pick_up_tip", instrument.name, mount.name)
self._ihp_log.debug(f"Picking up tip on {mount.name}")

pick_up_config = instrument.get_pick_up_configuration_for_tip_count(tip_count)
pick_up_config = instrument.get_pick_up_configuration()
if not isinstance(pick_up_config, PressFitPickUpTipConfiguration):
raise CommandPreconditionViolated(
f"Low-throughput pick up tip got wrong config for {instrument.name} on {mount.name}"
Expand Down
Loading

0 comments on commit 939995f

Please sign in to comment.