Skip to content

Commit

Permalink
well geometry unit tests, some broken
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Dec 10, 2024
1 parent 578984e commit 4fdd13d
Show file tree
Hide file tree
Showing 14 changed files with 1,486 additions and 1,444 deletions.
4 changes: 1 addition & 3 deletions api/src/opentrons/protocol_engine/state/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ def get_by_addressable_area(

def get_definition(self, labware_id: str) -> LabwareDefinition:
"""Get labware definition by the labware's unique identifier."""
ret = self.get_definition_by_uri(
LabwareUri(self.get(labware_id).definitionUri)
)
ret = self.get_definition_by_uri(LabwareUri(self.get(labware_id).definitionUri))
return self.get_definition_by_uri(
LabwareUri(self.get(labware_id).definitionUri)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,99 +8,117 @@
- The other is a nominal top volume, calculated some set distance from the top of the inside of the well.
"""
INNER_WELL_GEOMETRY_TEST_PARAMS = [
# [
# "opentrons_10_tuberack_nest_4x50ml_6x15ml_conical", "conicalWell15mL", 16.7, 15546.9, 3.0, 5.0
# ],
# [
# "opentrons_10_tuberack_nest_4x50ml_6x15ml_conical", "conicalWell50mL", 111.2, 54754.2, 3.0, 5.0
# ],
[
"opentrons_24_tuberack_nest_2ml_screwcap", "conicalWell", 66.6, 2104.9, 3.0, 3.0
"opentrons_10_tuberack_nest_4x50ml_6x15ml_conical",
"conicalWell15mL",
16.7,
15546.9,
3.0,
5.0,
],
# [
# "opentrons_24_tuberack_nest_1.5ml_screwcap", "conicalWell", 19.5, 1750.8, 3.0, 3.0
# ],
[
"nest_1_reservoir_290ml", "cuboidalWell", 16570.4, 271690.5, 3.0, 3.0
"opentrons_10_tuberack_nest_4x50ml_6x15ml_conical",
"conicalWell50mL",
111.2,
56110.3,
3.0,
5.0,
],
# [
# "opentrons_24_tuberack_nest_2ml_snapcap", "conicalWell", 69.6, 2148.5, 3.0, 3.0
# ],
["opentrons_24_tuberack_nest_2ml_screwcap", "conicalWell", 66.6, 2104.9, 3.0, 3.0],
[
"nest_96_wellplate_2ml_deep", "cuboidalWell", 118.3, 2060.4, 3.0, 3.0
"opentrons_24_tuberack_nest_1.5ml_screwcap",
"conicalWell",
19.5,
1750.8,
3.0,
3.0,
],
# weird one
# [
# "opentrons_24_tuberack_nest_1.5ml_snapcap", "conicalWell", 27.8, 1682.3, 3.0, 3.0
# "nest_1_reservoir_290ml", "cuboidalWell", 16570.4, 271690.5, 3.0, 3.0
# ],
[
"nest_12_reservoir_15ml", "cuboidalWell", 1219.0, 13236.1, 3.0, 3.0
],
# failing isclose
# [
# "nest_1_reservoir_195ml", "cuboidalWell", 14034.2, 172301.9, 3.0, 3.0
# ],
# [
# "opentrons_24_tuberack_nest_0.5ml_screwcap", "conicalWell", 21.95, 795.4, 3.0, 3.0
# ],
# [
# "opentrons_96_wellplate_200ul_pcr_full_skirt", "conicalWell", 150.2, 14.3, 3.0, 3.0
# ],
# [
# "nest_96_wellplate_100ul_pcr_full_skirt", "conicalWell", 150.8, 15.5, 3.0, 3.0
# ],
# [
# "nest_96_wellplate_200ul_flat", "conicalWell", 259.8, 96.3, 3.0, 3.0
# ],
# [
# "opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical", "50mlconicalWell", 163.9, 57720.5, 3.0, 3.0
# ],
# [
# "opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical", "15mlconicalWell", 40.8, 15956.6, 3.0, 3.0
# "opentrons_24_tuberack_nest_2ml_snapcap", "conicalWell", 69.6, 2148.5, 3.0, 3.0
# ],
["nest_96_wellplate_2ml_deep", "cuboidalWell", 118.3, 2060.4, 3.0, 3.0],
["opentrons_24_tuberack_nest_1.5ml_snapcap", "conicalWell", 27.8, 1682.3, 3.0, 3.0],
["nest_12_reservoir_15ml", "cuboidalWell", 1219.0, 13236.1, 3.0, 3.0],
# weird one
# [
# "usascientific_12_reservoir_22ml", "cuboidalWell", 61.6, 21111.5, 3.0, 3.0
# "nest_1_reservoir_195ml", "cuboidalWell", 14034.2, 172301.9, 3.0, 3.0
# ],
[
"thermoscientificnunc_96_wellplate_2000ul", "conicalWell", 73.5, 1768.0, 3.0, 3.0
"opentrons_24_tuberack_nest_0.5ml_screwcap",
"conicalWell",
21.95,
795.4,
3.0,
3.0,
],
# skipped usascientific_96_wellplate_2.4ml_deep since it doesnt have a definition yet
[
"agilent_1_reservoir_290ml", "cuboidalWell", 15652.9, 268813.8, 3.0, 3.0
"opentrons_96_wellplate_200ul_pcr_full_skirt",
"conicalWell",
14.3,
150.2,
3.0,
3.0,
],
# skipped opentrons_24_tuberack_eppendorf_2ml_safelock_snapcap
# [
# "opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap", "conicalWell", 25.8, 1576.1, 3.0, 3.0
# ],
# [
# "thermoscientificnunc_96_wellplate_1300ul", "conicalWell", 73.5, 1155.1, 3.0, 3.0
# ],
# [
# "corning_12_wellplate_6.9ml_flat", "conicalWell", 1156.3, 5654.8, 3.0, 3.0
# ],
# [
# "corning_24_wellplate_3.4ml_flat", "conicalWell", 579.0, 2853.4, 3.0, 3.0
# ],
# [
# "corning_6_wellplate_16.8ml_flat", "conicalWell", 2862.1, 13901.9, 3.0, 3.0
# ],
["nest_96_wellplate_100ul_pcr_full_skirt", "conicalWell", 15.5, 150.8, 3.0, 3.0],
["nest_96_wellplate_200ul_flat", "conicalWell", 96.3, 259.8, 3.0, 3.0],
[
"corning_48_wellplate_1.6ml_flat", "conicalWell", 268.9, 1327.0, 3.0, 3.0
"opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical",
"50mlconicalWell",
163.9,
57720.5,
3.0,
3.0,
],
# [
# "biorad_96_wellplate_200ul_pcr", "conicalWell", 17.9, 161.2, 3.0, 3.0
# ],
[
"axygen_1_reservoir_90ml", "cuboidalWell", 22373.4, 70450.6, 3.0, 3.0
"opentrons_10_tuberack_falcon_4x50ml_6x15ml_conical",
"15mlconicalWell",
40.8,
15956.6,
3.0,
3.0,
],
# failed - squared cone
# [
# "corning_384_wellplate_112ul_flat", "conicalWell", 22.4, 77.4, 3.0, 3.0
# "usascientific_12_reservoir_22ml", "cuboidalWell", 61.6, 21111.5, 3.0, 3.0
# ],
["thermoscientificnunc_96_wellplate_2000ul", "conicalWell", 73.5, 1768.0, 3.0, 3.0],
# skipped usascientific_96_wellplate_2.4ml_deep since it doesnt have a definition yet
# weird one
# [
# "corning_96_wellplate_360ul_flat", "conicalWell", 97.2, 257.1, 3.0, 3.0
# "agilent_1_reservoir_290ml", "cuboidalWell", 15652.9, 268813.8, 3.0, 3.0
# ],
[
"opentrons_24_tuberack_eppendorf_1.5ml_safelock_snapcap",
"conicalWell",
25.8,
1576.1,
3.0,
3.0,
],
["thermoscientificnunc_96_wellplate_1300ul", "conicalWell", 73.5, 1155.1, 3.0, 3.0],
["corning_12_wellplate_6.9ml_flat", "conicalWell", 1156.3, 5654.8, 3.0, 3.0],
["corning_24_wellplate_3.4ml_flat", "conicalWell", 579.0, 2853.4, 3.0, 3.0],
["corning_6_wellplate_16.8ml_flat", "conicalWell", 2862.1, 13901.9, 3.0, 3.0],
["corning_48_wellplate_1.6ml_flat", "conicalWell", 268.9, 1327.0, 3.0, 3.0],
["biorad_96_wellplate_200ul_pcr", "conicalWell", 17.9, 161.2, 3.0, 3.0],
["axygen_1_reservoir_90ml", "cuboidalWell", 22373.4, 70450.6, 3.0, 3.0],
# fails- this one thought it was a rectangle ?
# [
# "biorad_384_wellplate_50ul", "conicalWell", 7.7, 27.8, 3.0, 3.0
# "corning_384_wellplate_112ul_flat", "conicalWell", 22.4, 77.4, 3.0, 3.0
# ],
# [
# "appliedbiosystemsmicroamp_384_wellplate_40ul", "conicalWell", 7.44, 26.2, 3.0, 3.0
# ]
]
["corning_96_wellplate_360ul_flat", "conicalWell", 97.2, 257.1, 3.0, 3.0],
["biorad_384_wellplate_50ul", "conicalWell", 7.7, 27.8, 3.0, 3.0],
[
"appliedbiosystemsmicroamp_384_wellplate_40ul",
"conicalWell",
7.44,
26.2,
3.0,
3.0,
],
]
139 changes: 68 additions & 71 deletions api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3364,114 +3364,111 @@ def test_validate_dispense_volume_into_well_meniscus(


@pytest.mark.parametrize(
[
"labware_id",
"well_name",
"input_volume_bottom",
"input_volume_top",
"expected_height_from_bottom_mm",
"expected_height_from_top_mm"
],
INNER_WELL_GEOMETRY_TEST_PARAMS
[
"labware_id",
"well_name",
"input_volume_bottom",
"input_volume_top",
"expected_height_from_bottom_mm",
"expected_height_from_top_mm",
],
INNER_WELL_GEOMETRY_TEST_PARAMS,
)
def test_get_well_height_at_volume(
decoy: Decoy,
subject: GeometryView,
labware_id: str,
well_name: str,
input_volume_bottom: float,
input_volume_top: float,
expected_height_from_bottom_mm: float,
expected_height_from_top_mm: float,
decoy: Decoy,
subject: GeometryView,
labware_id: str,
well_name: str,
input_volume_bottom: float,
input_volume_top: float,
expected_height_from_bottom_mm: float,
expected_height_from_top_mm: float,
) -> None:
def _get_labware_def() -> LabwareDefinition:
def_dir = str(get_shared_data_root()) + f"/labware/definitions/3/{labware_id}"
version_str = max(
[str(version) for version in listdir(def_dir)]
)
version_str = max([str(version) for version in listdir(def_dir)])
def_path = path.join(def_dir, version_str)
_labware_def = LabwareDefinition.parse_obj(
json.loads(
load_shared_data(def_path).decode(
"utf-8"
)
)
json.loads(load_shared_data(def_path).decode("utf-8"))
)
well_geometry = _labware_def.innerLabwareGeometry.get(well_name)
return well_geometry
decoy.when(subject._labware.get_well_geometry(labware_id, well_name)).then_return(_get_labware_def())

decoy.when(subject._labware.get_well_geometry(labware_id, well_name)).then_return(
_get_labware_def()
)

found_height_bottom = subject.get_well_height_at_volume(
labware_id=labware_id,
well_name=well_name,
volume=input_volume_bottom
labware_id=labware_id, well_name=well_name, volume=input_volume_bottom
)
found_height_top = subject.get_well_height_at_volume(
labware_id=labware_id,
well_name=well_name,
volume=input_volume_top
labware_id=labware_id, well_name=well_name, volume=input_volume_top
)
assert isclose(found_height_bottom, expected_height_from_bottom_mm, rel_tol=0.01)
vol_2_expected_height_from_bottom = subject.get_well_height(
labware_id=labware_id, well_name=well_name
) - expected_height_from_top_mm
vol_2_expected_height_from_bottom = (
subject.get_well_height(labware_id=labware_id, well_name=well_name)
- expected_height_from_top_mm
)
assert isclose(found_height_top, vol_2_expected_height_from_bottom, rel_tol=0.01)


@pytest.mark.parametrize(
[
"labware_id",
"well_name",
"expected_volume_bottom",
"expected_volume_top",
"input_height_from_bottom_mm",
"input_height_from_top_mm"
],
INNER_WELL_GEOMETRY_TEST_PARAMS
[
"labware_id",
"well_name",
"expected_volume_bottom",
"expected_volume_top",
"input_height_from_bottom_mm",
"input_height_from_top_mm",
],
INNER_WELL_GEOMETRY_TEST_PARAMS,
)
def test_get_well_volume_at_height(
decoy: Decoy,
subject: GeometryView,
labware_id: str,
well_name: str,
expected_volume_bottom: float,
expected_volume_top: float,
input_height_from_bottom_mm: float,
input_height_from_top_mm: float,
mock_labware_view: LabwareView,
decoy: Decoy,
subject: GeometryView,
labware_id: str,
well_name: str,
expected_volume_bottom: float,
expected_volume_top: float,
input_height_from_bottom_mm: float,
input_height_from_top_mm: float,
mock_labware_view: LabwareView,
) -> None:
def _get_labware_def() -> LabwareDefinition:
def_dir = str(get_shared_data_root()) + f"/labware/definitions/3/{labware_id}"
version_str = max(
[str(version) for version in listdir(def_dir)]
)
version_str = max([str(version) for version in listdir(def_dir)])
def_path = path.join(def_dir, version_str)
_labware_def = LabwareDefinition.parse_obj(
json.loads(
load_shared_data(def_path).decode(
"utf-8"
)
)
json.loads(load_shared_data(def_path).decode("utf-8"))
)
return _labware_def

labware_def = _get_labware_def()
well_geometry = labware_def.innerLabwareGeometry.get(well_name)
well_definition = [well for well in labware_def.wells.values() if well.geometryDefinitionId == well_name][0]
well_definition = [
well
for well in labware_def.wells.values()
if well.geometryDefinitionId == well_name
][0]

decoy.when(mock_labware_view.get_well_geometry(labware_id, well_name)).then_return(well_geometry)
decoy.when(mock_labware_view.get_well_definition(labware_id, well_name)).then_return(well_definition)
decoy.when(mock_labware_view.get_well_geometry(labware_id, well_name)).then_return(
well_geometry
)
decoy.when(
mock_labware_view.get_well_definition(labware_id, well_name)
).then_return(well_definition)

found_volume_bottom = subject.get_well_volume_at_height(
labware_id=labware_id,
well_name=well_name,
height=input_height_from_bottom_mm
labware_id=labware_id, well_name=well_name, height=input_height_from_bottom_mm
)
vol_2_input_height_from_bottom = (
subject.get_well_height(labware_id=labware_id, well_name=well_name)
- input_height_from_top_mm
)
vol_2_input_height_from_bottom = subject.get_well_height(
labware_id=labware_id, well_name=well_name
) - input_height_from_top_mm
found_volume_top = subject.get_well_volume_at_height(
labware_id=labware_id,
well_name=well_name,
height=vol_2_input_height_from_bottom
height=vol_2_input_height_from_bottom,
)
assert isclose(found_volume_bottom, expected_volume_bottom, rel_tol=0.01)
assert isclose(found_volume_top, expected_volume_top, rel_tol=0.01)
Loading

0 comments on commit 4fdd13d

Please sign in to comment.