Skip to content

Commit

Permalink
chore(refactor): Refactor and cleanup volumetric scripts (#13071)
Browse files Browse the repository at this point in the history
* Revert "Merge latest volumetric changes (#13100)"

This reverts commit 773b8a4.

* Revert "fix(hardware-testing): Remove tips using them for finding liquid height (#13064)"

This reverts commit cc0f509.

* Revert "support resupplying tipracks during a 96ch increment test run (#13065)"

This reverts commit 965f02d.

* Pull out all of the common functions between gravimetric and photometric

* move trial generation out of excecute

* combine the load pipette logic

* pull gantry speed out of the photometric config

* refactor out load tipracks

* remove unused method

* fix issues from rebasing

* fixups from rebase and formating

* refactor out trial building from the photometric script

* add additional test targets

* pull out the common elements of trials into a seperate dataclass

* break out even more common code

* break building pm report out of the run method

* break the run trials loop out of the run method

* format/lint

* break building test report out of the run method in gravimetric run method

* add the ui header to the build_report methods

* move all of the dye prep into the dye prep method

* improve LiquidTracker initialization

* move the homing to execute_trials

* refactor out common end script code

* refactor out common get_tips

* fixup things that broke during rebase

* fix the photometric test target

* remove evaporation measurement out of run for readablity

* break out load scale for readablity

* redo: Support resupplying tipracks during a 96ch increment tests

* redo: Remove tips using them for finding liquid height

* fix the tests

* replace all print statements with ui

* move the if-else out of the function to decrease the indent

* make a base class config

* fixup things that were lost in the rebase

* construct the trial directory correctly

* make sure 96 pipette doesn't collide during gravimetric tests

* gracefully handle when the scale is beyond max

* reimplement: Merge latest volumetric changes (#13100)

* add stable flag to the blank gravimetric trials

* Convert the default test volumes to the QC volumes

* add default number of trials and correct volumes to match calculator sheet

* make blank the default

* update makefile to test the correct args for each tip

* update increment test values

* make single channle QC test work with all tips in one run

* last few changes

* fixup typing error

* forgot a docstring for the linter

* support the enviornmental sensor in the volumetric tests

* make the asair prompt for port instead of auto finding

* fix the tests
  • Loading branch information
ryanthecoder committed Jul 26, 2023
1 parent 2f25b8b commit eb39c23
Show file tree
Hide file tree
Showing 20 changed files with 1,522 additions and 1,282 deletions.
4 changes: 2 additions & 2 deletions hardware-testing/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
max-line-length = 100

# max cyclomatic complexity
# NOTE: (andy s) increasing this from 9 to 20 b/c test scripts often handle all logic in main
max-complexity = 20
# NOTE: (andy s) increasing this from 9 to 15 b/c test scripts often handle all logic in main
max-complexity = 15

extend-ignore =
# ignore E203 because black might reformat it
Expand Down
29 changes: 17 additions & 12 deletions hardware-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,29 @@ test-cov:

.PHONY: test-photometric
test-photometric:
$(python) -m hardware_testing.gravimetric --photometric --simulate --pipette 1000 --channels 96 --tip 50 --trials 5
$(python) -m hardware_testing.gravimetric --photometric --simulate --pipette 1000 --channels 96 --tip 200 --trials 5
-$(MAKE) apply-patches-gravimetric
$(python) -m hardware_testing.gravimetric --photometric --simulate --pipette 1000 --channels 96 --tip 50 --trials 1
$(python) -m hardware_testing.gravimetric --photometric --simulate --pipette 1000 --channels 96 --tip 200 --trials 1
-$(MAKE) remove-patches-gravimetric

.PHONY: test-gravimetric-single
test-gravimetric-single:
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --tip 1000 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --tip 200 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --tip 50 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 1 --tip 50 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --tip 1000 --trials 1 --increment
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --extra --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 1 --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 1 --trials 1 --increment --no-blank

.PHONY: test-gravimetric-multi
test-gravimetric-multi:
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 8 --tip 50 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 8 --tip 50 --trials 1 --increment
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 1000 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 200 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 50 --trials 1
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 8 --tip 50 --trials 1 --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 50 --channels 8 --tip 50 --trials 1 --increment --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 1000 --trials 1 --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 200 --trials 1 --extra --no-blank
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 8 --tip 50 --trials 1 --no-blank

.PHONY: test-gravimetric-96
test-gravimetric-96:
$(python) -m hardware_testing.gravimetric --simulate --pipette 1000 --channels 96 --tip 1000 --trials 1 --no-blank

.PHONY: test-gravimetric
test-gravimetric:
Expand Down
15 changes: 14 additions & 1 deletion hardware-testing/hardware_testing/data/ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Production QC User Interface."""

from opentrons.hardware_control import SyncHardwareAPI
from opentrons.hardware_control.types import StatusBarState

PRINT_HEADER_NUM_SPACES = 4
PRINT_HEADER_DASHES = "-" * PRINT_HEADER_NUM_SPACES
Expand All @@ -25,6 +26,13 @@ def get_user_ready(message: str) -> None:
input(f"WAIT: {message}, press ENTER when ready: ")


def alert_user_ready(message: str, hw: SyncHardwareAPI) -> None:
"""Flash the ui lights on the ot3 and then use the get_user_ready."""
hw.set_status_bar_state(StatusBarState.PAUSED)
get_user_ready(message)
hw.set_status_bar_state(StatusBarState.CONFIRMATION)


def print_title(title: str) -> None:
"""Print title."""
"""
Expand Down Expand Up @@ -54,3 +62,8 @@ def print_header(header: str) -> None:
def print_error(message: str) -> None:
"""Print error."""
print(f"ERROR: {message}")


def print_info(message: str) -> None:
"""Print information."""
print(message)
1 change: 0 additions & 1 deletion hardware-testing/hardware_testing/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from serial.tools.list_ports import comports # type: ignore[import]

from .radwag import RadwagScaleBase, RadwagScale, SimRadwagScale
from .asair_sensor import AsairSensor, AsairSensorError


def list_ports_and_select(device_name: str = "") -> str:
Expand Down
22 changes: 18 additions & 4 deletions hardware-testing/hardware_testing/drivers/asair_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import abc
import codecs
import logging
import random
import time
from typing import Tuple
from abc import ABC
from dataclasses import dataclass

from . import list_ports_and_select
import serial # type: ignore[import]
from serial.serialutil import SerialException # type: ignore[import]
from hardware_testing.data import ui

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,6 +66,20 @@ def get_reading(self) -> Reading:
...


def BuildAsairSensor(simulate: bool) -> AsairSensorBase:
"""Try to find and return an Asair sensor, if not found return a simulator."""
ui.print_title("Connecting to Environmental sensor")
if not simulate:
port = list_ports_and_select(device_name="Asair environmental sensor")
try:
sensor = AsairSensor.connect(port)
ui.print_info(f"Found sensor on port {port}")
return sensor
except SerialException:
pass
return SimAsairSensor()


class AsairSensor(AsairSensorBase):
"""Asair sensor driver."""

Expand Down Expand Up @@ -152,6 +166,6 @@ class SimAsairSensor(AsairSensorBase):

def get_reading(self) -> Reading:
"""Get a reading."""
temp = random.uniform(24.5, 25)
relative_hum = random.uniform(45, 40)
temp = 25.0
relative_hum = 50.0
return Reading(temperature=temp, relative_humidity=relative_hum)
19 changes: 12 additions & 7 deletions hardware-testing/hardware_testing/drivers/radwag/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,18 @@ def _on_unstable_measurement(
data = RadwagResponse.build(command, response_list)
# SI ? - 0.00020 g
# TODO: we could accept more unit types if we wanted...
assert response_list[-1] == "g", (
f'Expected units to be grams ("g"), ' f'instead got "{response_list[-1]}"'
)
data.stable = "?" not in response_list
data.measurement = float(response_list[-2])
if "-" in response_list:
data.measurement *= -1
if RadwagResponseCodes.MAX_THRESHOLD_EXCEEDED in response_list:
print("Warning: Scale maximum exceeded returning infinity")
data.stable = False
data.measurement = float("inf")
else:
assert response_list[-1] == "g", (
f'Expected units to be grams ("g"), ' f'instead got "{response_list[-1]}"'
)
data.stable = "?" not in response_list
data.measurement = float(response_list[-2])
if "-" in response_list:
data.measurement *= -1
return data


Expand Down
Loading

0 comments on commit eb39c23

Please sign in to comment.