Skip to content

Commit

Permalink
Merge branch 'edge' into refactor_Modal-for-web
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Jan 7, 2025
2 parents b4b5a8f + be7984e commit 0a454da
Show file tree
Hide file tree
Showing 62 changed files with 2,590 additions and 2,215 deletions.
1 change: 1 addition & 0 deletions abr-testing/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pandas = "*"
pandas-stubs = "*"
paramiko = "*"
prettier = "*"
pydantic = "==2.9.0"

[dev-packages]
atomicwrites = "==1.4.1"
Expand Down
1,261 changes: 569 additions & 692 deletions abr-testing/Pipfile.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion api/src/opentrons/hardware_control/backends/ot3controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,11 @@ async def clean_up(self) -> None:
return

if hasattr(self, "_event_watcher"):
if loop.is_running() and self._event_watcher:
if (
loop.is_running()
and self._event_watcher
and not self._event_watcher.closed
):
self._event_watcher.close()

messenger = getattr(self, "_messenger", None)
Expand Down
6 changes: 4 additions & 2 deletions api/src/opentrons/protocol_api/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
from math import isinf, isnan
from typing_extensions import TypeGuard

from opentrons_shared_data.labware.labware_definition import LabwareRole
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
LabwareRole,
)
from opentrons_shared_data.pipette.types import PipetteNameType
from opentrons_shared_data.robot.types import RobotType

from opentrons.protocols.api_support.types import APIVersion, ThermocyclerStep
from opentrons.protocols.api_support.util import APIVersionError
from opentrons.protocols.models import LabwareDefinition
from opentrons.protocols.advanced_control.transfers.common import TransferTipPolicyV2
from opentrons.types import (
Mount,
Expand Down
6 changes: 3 additions & 3 deletions api/src/opentrons/protocol_engine/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from enum import Enum
from typing import List, Optional, Union

from opentrons.protocols.models import LabwareDefinition
from opentrons_shared_data.errors import EnumeratedError
from opentrons_shared_data.labware.labware_definition import LabwareDefinition

from opentrons.hardware_control.types import DoorState
from opentrons.hardware_control.modules import LiveData

from opentrons_shared_data.errors import EnumeratedError

from ..commands import (
Command,
CommandCreate,
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_engine/execution/equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from dataclasses import dataclass
from typing import Optional, overload, Union, List

from opentrons_shared_data.labware.labware_definition import LabwareDefinition
from opentrons_shared_data.pipette.types import PipetteNameType

from opentrons.calibration_storage.helpers import uri_from_details
from opentrons.protocols.models import LabwareDefinition
from opentrons.types import MountType
from opentrons.hardware_control import HardwareControlAPI
from opentrons.hardware_control.modules import (
Expand Down
17 changes: 9 additions & 8 deletions api/src/opentrons/protocol_engine/protocol_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
from contextlib import AsyncExitStack
from logging import getLogger
from typing import Dict, Optional, Union, AsyncGenerator, Callable
from opentrons.protocol_engine.actions.actions import (
ResumeFromRecoveryAction,
SetErrorRecoveryPolicyAction,
)

from opentrons.protocols.models import LabwareDefinition
from opentrons.hardware_control import HardwareControlAPI
from opentrons.hardware_control.modules import AbstractModule as HardwareModuleAPI
from opentrons.hardware_control.types import PauseType as HardwarePauseType
from opentrons_shared_data.errors import (
ErrorCodes,
EnumeratedError,
)
from opentrons_shared_data.labware.labware_definition import LabwareDefinition

from opentrons.hardware_control import HardwareControlAPI
from opentrons.hardware_control.modules import AbstractModule as HardwareModuleAPI
from opentrons.hardware_control.types import PauseType as HardwarePauseType

from .actions.actions import (
ResumeFromRecoveryAction,
SetErrorRecoveryPolicyAction,
)
from .errors import ProtocolCommandFailedError, ErrorOccurrence, CommandNotAllowedError
from .errors.exceptions import EStopActivatedError
from .error_recovery_policy import ErrorRecoveryPolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DEFAULT_DECK_DEFINITION_VERSION,
)
from opentrons_shared_data.deck.types import DeckDefinitionV5
from opentrons.protocols.models import LabwareDefinition
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
from opentrons.types import DeckSlotName

from ..types import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import logging
from anyio import to_thread

from opentrons.protocols.models import LabwareDefinition
from opentrons_shared_data.labware.labware_definition import LabwareDefinition

from opentrons.protocols.labware import get_labware_definition

# TODO (lc 09-26-2022) We should conditionally import ot2 or ot3 calibration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Validation file for labware role and location checking functions."""

from opentrons_shared_data.labware.labware_definition import LabwareRole
from opentrons.protocols.models import LabwareDefinition
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
LabwareRole,
)


def is_flex_trash(load_name: str) -> bool:
Expand Down
57 changes: 13 additions & 44 deletions api/src/opentrons/protocol_engine/state/frustum_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,12 @@ def _circular_frustum_polynomial_roots(


def _volume_from_height_circular(
target_height: float,
total_frustum_height: float,
bottom_radius: float,
top_radius: float,
target_height: float, segment: ConicalFrustum
) -> float:
"""Find the volume given a height within a circular frustum."""
a, b, c = _circular_frustum_polynomial_roots(
bottom_radius=bottom_radius,
top_radius=top_radius,
total_frustum_height=total_frustum_height,
)
volume = a * (target_height**3) + b * (target_height**2) + c * target_height
return volume
heights = segment.height_to_volume_table.keys()
best_fit_height = min(heights, key=lambda x: abs(x - target_height))
return segment.height_to_volume_table[best_fit_height]


def _volume_from_height_rectangular(
Expand Down Expand Up @@ -138,26 +131,12 @@ def _volume_from_height_squared_cone(


def _height_from_volume_circular(
volume: float,
total_frustum_height: float,
bottom_radius: float,
top_radius: float,
target_volume: float, segment: ConicalFrustum
) -> float:
"""Find the height given a volume within a circular frustum."""
a, b, c = _circular_frustum_polynomial_roots(
bottom_radius=bottom_radius,
top_radius=top_radius,
total_frustum_height=total_frustum_height,
)
d = volume * -1
x_intercept_roots = (a, b, c, d)

height_from_volume_roots = roots(x_intercept_roots)
height = _reject_unacceptable_heights(
potential_heights=list(height_from_volume_roots),
max_height=total_frustum_height,
)
return height
"""Find the height given a volume within a squared cone segment."""
volumes = segment.volume_to_height_table.keys()
best_fit_volume = min(volumes, key=lambda x: abs(x - target_volume))
return segment.volume_to_height_table[best_fit_volume]


def _height_from_volume_rectangular(
Expand Down Expand Up @@ -243,9 +222,7 @@ def _get_segment_capacity(segment: WellSegment) -> float:
return (
_volume_from_height_circular(
target_height=section_height,
total_frustum_height=section_height,
bottom_radius=(segment.bottomDiameter / 2),
top_radius=(segment.topDiameter / 2),
segment=segment,
)
* segment.count
)
Expand Down Expand Up @@ -293,12 +270,7 @@ def height_at_volume_within_section(
radius_of_curvature=section.radiusOfCurvature,
)
case ConicalFrustum():
return _height_from_volume_circular(
volume=target_volume_relative,
top_radius=(section.bottomDiameter / 2),
bottom_radius=(section.topDiameter / 2),
total_frustum_height=section_height,
)
return _height_from_volume_circular(target_volume_relative, section)
case CuboidalFrustum():
return _height_from_volume_rectangular(
volume=target_volume_relative,
Expand Down Expand Up @@ -334,10 +306,7 @@ def volume_at_height_within_section(
case ConicalFrustum():
return (
_volume_from_height_circular(
target_height=target_height_relative,
total_frustum_height=section_height,
bottom_radius=(section.bottomDiameter / 2),
top_radius=(section.topDiameter / 2),
target_height=target_height_relative, segment=section
)
* section.count
)
Expand Down Expand Up @@ -427,7 +396,7 @@ def _find_height_in_partial_frustum(
if (
bottom_section_volume
< target_volume
< (bottom_section_volume + section_volume)
<= (bottom_section_volume + section_volume)
):
relative_target_volume = target_volume - bottom_section_volume
section_height = section.topHeight - section.bottomHeight
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_engine/state/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

from opentrons_shared_data.errors.exceptions import InvalidStoredData
from opentrons_shared_data.labware.constants import WELL_NAME_PATTERN
from opentrons_shared_data.labware.labware_definition import LabwareDefinition
from opentrons_shared_data.deck.types import CutoutFixture
from opentrons_shared_data.pipette import PIPETTE_X_SPAN
from opentrons_shared_data.pipette.types import ChannelCount
from opentrons.protocols.models import LabwareDefinition

from .. import errors
from ..errors import (
Expand Down
6 changes: 3 additions & 3 deletions api/src/opentrons/protocol_engine/state/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
from opentrons_shared_data.deck.types import DeckDefinitionV5
from opentrons_shared_data.gripper.constants import LABWARE_GRIP_FORCE
from opentrons_shared_data.labware.labware_definition import (
LabwareRole,
InnerWellGeometry,
LabwareDefinition,
LabwareRole,
WellDefinition,
)
from opentrons_shared_data.pipette.types import LabwareUri

from opentrons.types import DeckSlotName, StagingSlotName, MountType
from opentrons.protocols.api_support.constants import OPENTRONS_NAMESPACE
from opentrons.protocols.models import LabwareDefinition, WellDefinition
from opentrons.calibration_storage.helpers import uri_from_details

from .. import errors
Expand Down Expand Up @@ -524,7 +525,6 @@ def get_well_definition(
will be used.
"""
definition = self.get_definition(labware_id)

if well_name is None:
well_name = definition.ordering[0][0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import anyio

from opentrons.protocols.models import LabwareDefinition
from opentrons_shared_data.labware.labware_definition import LabwareDefinition

from .protocol_source import ProtocolFileRole, ProtocolSource, ProtocolType

Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/protocol_reader/file_format_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from opentrons_shared_data.errors.exceptions import PythonException

from opentrons.protocols.models import JsonProtocol as JsonProtocolUpToV5
from opentrons.protocols.models.json_protocol import Model as JsonProtocolUpToV5

from .file_identifier import (
IdentifiedFile,
Expand Down
21 changes: 0 additions & 21 deletions api/src/opentrons/protocols/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
# Convenience re-exports of models that are especially common or important.
# More detailed sub-models are always available through the underlying
# submodules.
#
# If re-exporting something, its name should still make sense when it's separated
# from the name of its parent submodule. e.g. re-exporting models.json_protocol.Labware
# as models.Labware could be confusing.

# TODO(mc, 2022-03-11): remove this re-export when it won't break pickling
# https://opentrons.atlassian.net/browse/RSS-94
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
WellDefinition,
)
from .json_protocol import Model as JsonProtocol

__all__ = [
"LabwareDefinition",
"WellDefinition",
"JsonProtocol",
]
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,18 @@ def mock_messenger(can_message_notifier: MockCanMessageNotifier) -> mock.AsyncMo

@pytest.fixture
def mock_can_driver(mock_messenger: mock.AsyncMock) -> AbstractCanDriver:
return mock.AsyncMock(spec=AbstractCanDriver)
driver = mock.AsyncMock(spec=AbstractCanDriver)

# ignoring this type error because this is a very weird function that will in fact
# do nothing, but has to have the yield in there for the compiler to make it a
# generator function
async def _fake_message_retrieve(d): # type: ignore[no-untyped-def]
while True:
await asyncio.sleep(1)
yield

driver.__aiter__ = _fake_message_retrieve
return driver


@pytest.fixture
Expand All @@ -160,15 +171,19 @@ def mock_eeprom_driver() -> EEPROMDriver:


@pytest.fixture
def controller(
async def controller(
mock_config: OT3Config,
mock_can_driver: AbstractCanDriver,
mock_eeprom_driver: EEPROMDriver,
) -> OT3Controller:
with (mock.patch("opentrons.hardware_control.backends.ot3controller.OT3GPIO")):
return OT3Controller(
) -> AsyncIterator[OT3Controller]:
with mock.patch("opentrons.hardware_control.backends.ot3controller.OT3GPIO"):
controller = OT3Controller(
mock_config, mock_can_driver, eeprom_driver=mock_eeprom_driver
)
try:
yield controller
finally:
await controller.clean_up()


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion api/tests/opentrons/protocol_api/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from opentrons.protocols.advanced_control.transfers.common import TransferTipPolicyV2
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
LabwareRole,
Parameters as LabwareDefinitionParameters,
)
Expand All @@ -33,7 +34,6 @@
HeaterShakerModuleModel,
ThermocyclerStep,
)
from opentrons.protocols.models import LabwareDefinition
from opentrons.protocols.api_support.types import APIVersion
from opentrons.protocols.api_support.util import APIVersionError
from opentrons.protocol_api import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import pytest
from decoy import Decoy

from opentrons_shared_data.labware.labware_definition import LabwareDefinition

from opentrons.types import DeckSlotName
from opentrons.protocols.models import LabwareDefinition

from opentrons.protocol_engine.errors import (
LabwareIsNotAllowedInLocationError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import pytest
from decoy import Decoy, matchers

from opentrons_shared_data.labware.labware_definition import Parameters, Dimensions
from opentrons_shared_data.labware.labware_definition import (
LabwareDefinition,
Parameters,
Dimensions,
)
from opentrons_shared_data.errors.exceptions import (
EnumeratedError,
FailedGripperPickupError,
Expand All @@ -18,7 +22,6 @@

from opentrons.protocol_engine.state import update_types
from opentrons.types import DeckSlotName, Point
from opentrons.protocols.models import LabwareDefinition
from opentrons.protocol_engine import errors, Config
from opentrons.protocol_engine.resources import labware_validation
from opentrons.protocol_engine.resources.model_utils import ModelUtils
Expand Down
Loading

0 comments on commit 0a454da

Please sign in to comment.