Skip to content

Commit

Permalink
return slots ordered and gate staging slots
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleon95 committed Dec 6, 2023
1 parent 41ae9c2 commit 77882c5
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 17 deletions.
8 changes: 7 additions & 1 deletion api/src/opentrons/protocol_api/core/engine/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,15 @@ def get_slot_definition(
return self._engine_client.state.addressable_areas.get_slot_definition(slot.id)

def get_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get the configured or assumed slot definitions from the robot's deck."""
"""Get all standard slot definitions available in the deck definition."""
return self._engine_client.state.addressable_areas.get_deck_slot_definitions()

def get_staging_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get all staging slot definitions available in the deck definition."""
return (
self._engine_client.state.addressable_areas.get_staging_slot_definitions()
)

def _ensure_module_location(
self, slot: DeckSlotName, module_type: ModuleType
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,13 @@ def get_slot_definition(
assert False, "get_slot_definition only supported on engine core"

def get_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get the configured or assumed slot definitions from the robot's deck."""
"""Get all standard slot definitions available in the deck definition."""
assert False, "get_slot_definitions only supported on engine core"

def get_staging_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get all staging slot definitions available in the deck definition."""
assert False, "get_staging_slot_definitions only supported on engine core"

def get_slot_item(
self, slot_name: Union[DeckSlotName, StagingSlotName]
) -> Union[LegacyLabwareCore, legacy_module_core.LegacyModuleCore, None]:
Expand Down
6 changes: 5 additions & 1 deletion api/src/opentrons/protocol_api/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ def get_slot_definition(

@abstractmethod
def get_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get the configured or assumed slot definitions from the robot's deck."""
"""Get all standard slot definitions available in the deck definition."""

@abstractmethod
def get_staging_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get all staging slot definitions available in the deck definition."""

@abstractmethod
def get_slot_item(
Expand Down
6 changes: 6 additions & 0 deletions api/src/opentrons/protocol_api/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

DeckItem = Union[Labware, ModuleContext]

STAGING_SLOT_VERSION_GATE = APIVersion(2, 16)


@dataclass(frozen=True)
class CalibrationPosition:
Expand Down Expand Up @@ -69,6 +71,10 @@ def __init__(
deck_locations = protocol_core.get_deck_definition()["locations"]

self._slot_definitions_by_name = self._protocol_core.get_slot_definitions()
if self._api_version >= STAGING_SLOT_VERSION_GATE:
self._slot_definitions_by_name.update(
self._protocol_core.get_staging_slot_definitions()
)

self._calibration_positions = [
CalibrationPosition(
Expand Down
38 changes: 32 additions & 6 deletions api/src/opentrons/protocol_engine/state/addressable_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from opentrons_shared_data.robot.dev_types import RobotType
from opentrons_shared_data.deck.dev_types import DeckDefinitionV4, SlotDefV3

from opentrons.types import Point, DeckSlotName, StagingSlotName
from opentrons.types import Point, DeckSlotName

from ..commands import (
Command,
Expand Down Expand Up @@ -66,6 +66,24 @@ class AddressableAreaState:
"""See `Config.use_simulated_deck_config`."""


_OT2_ORDERED_SLOTS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
_FLEX_ORDERED_SLOTS = [
"D1",
"D2",
"D3",
"C1",
"C2",
"C3",
"B1",
"B2",
"B3",
"A1",
"A2",
"A3",
]
_FLEX_ORDERED_STAGING_SLOTS = ["D4", "C4", "B4", "A4"]


def _get_conflicting_addressable_areas(
potential_cutout_fixtures: Set[PotentialCutoutFixture],
loaded_addressable_areas: Set[str],
Expand Down Expand Up @@ -461,11 +479,19 @@ def get_slot_definition(self, slot_id: str) -> SlotDefV3:
}

def get_deck_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get all slot definitions either configured for robot or assumed for analysis run so far."""
"""Get all standard slot definitions available in the deck definition."""
if self._state.robot_type == "OT-2 Standard":
slots = {slot.to_ot2_equivalent().id for slot in DeckSlotName}
slots = _OT2_ORDERED_SLOTS
else:
slots = {slot.to_ot3_equivalent().id for slot in DeckSlotName}.union(
slot.id for slot in StagingSlotName
)
slots = _FLEX_ORDERED_SLOTS
return {slot_name: self.get_slot_definition(slot_name) for slot_name in slots}

def get_staging_slot_definitions(self) -> Dict[str, SlotDefV3]:
"""Get all staging slot definitions available in the deck definition."""
if self._state.robot_type == "OT-3 Standard":
return {
slot_name: self.get_slot_definition(slot_name)
for slot_name in _FLEX_ORDERED_STAGING_SLOTS
}
else:
return {}
55 changes: 47 additions & 8 deletions api/tests/opentrons/protocol_api/test_deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def deck_definition() -> DeckDefinitionV4:
@pytest.fixture
def api_version() -> APIVersion:
"""Get a dummy `APIVersion` with which to configure the subject."""
return APIVersion(123, 456)
return APIVersion(1, 234)


@pytest.fixture(autouse=True)
Expand Down Expand Up @@ -72,6 +72,12 @@ def slot_definitions_by_name() -> Dict[str, SlotDefV3]:
return {"1": {}}


@pytest.fixture
def staging_slot_definitions_by_name() -> Dict[str, SlotDefV3]:
"""Get a dictionary of staging slot names to slot definitions."""
return {"2": {}}


@pytest.fixture
def subject(
decoy: Decoy,
Expand All @@ -80,12 +86,16 @@ def subject(
mock_core_map: LoadedCoreMap,
api_version: APIVersion,
slot_definitions_by_name: Dict[str, SlotDefV3],
staging_slot_definitions_by_name: Dict[str, SlotDefV3],
) -> Deck:
"""Get a Deck test subject with its dependencies mocked out."""
decoy.when(mock_protocol_core.get_deck_definition()).then_return(deck_definition)
decoy.when(mock_protocol_core.get_slot_definitions()).then_return(
slot_definitions_by_name
)
decoy.when(mock_protocol_core.get_staging_slot_definitions()).then_return(
staging_slot_definitions_by_name
)

return Deck(
protocol_core=mock_protocol_core,
Expand Down Expand Up @@ -239,13 +249,16 @@ def test_delitem_raises_if_slot_has_module(


@pytest.mark.parametrize(
"slot_definitions_by_name",
[
{
"1": {},
"2": {},
"3": {},
}
argnames=["slot_definitions_by_name", "staging_slot_definitions_by_name"],
argvalues=[
(
{
"1": {},
"2": {},
"3": {},
},
{"4": {}},
)
],
)
def test_slot_keys_iter(subject: Deck) -> None:
Expand All @@ -256,6 +269,32 @@ def test_slot_keys_iter(subject: Deck) -> None:
assert result == ["1", "2", "3"]


@pytest.mark.parametrize(
argnames=[
"slot_definitions_by_name",
"staging_slot_definitions_by_name",
"api_version",
],
argvalues=[
(
{
"1": {},
"2": {},
"3": {},
},
{"4": {}},
APIVersion(2, 16),
)
],
)
def test_slot_keys_iter_with_staging_slots(subject: Deck) -> None:
"""It should provide an iterable interface to deck slots."""
result = list(subject)

assert len(subject) == 4
assert result == ["1", "2", "3", "4"]


@pytest.mark.parametrize(
"slot_definitions_by_name",
[
Expand Down

0 comments on commit 77882c5

Please sign in to comment.