Skip to content

Commit

Permalink
Merge branch 'edge' into papi_try_liquid_probe
Browse files Browse the repository at this point in the history
Resolve conflicts in api/tests/opentrons/protocol_api/core/engine/test_instrument_core.py.
  • Loading branch information
SyntaxColoring committed Jul 17, 2024
2 parents ef0eead + e721bbb commit 8112650
Show file tree
Hide file tree
Showing 62 changed files with 948 additions and 669 deletions.
24 changes: 14 additions & 10 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Create ticket for robot with error."""
from typing import List, Tuple, Any, Dict
from typing import List, Tuple, Any, Dict, Optional
from abr_testing.data_collection import read_robot_logs, abr_google_drive, get_run_logs
import requests
import argparse
Expand All @@ -18,7 +18,7 @@
def compare_current_trh_to_average(
robot: str,
start_time: Any,
end_time: Any,
end_time: Optional[Any],
protocol_name: str,
storage_directory: str,
) -> str:
Expand All @@ -38,27 +38,29 @@ def compare_current_trh_to_average(
df_all_trh = pd.DataFrame(all_trh_data)
# Convert timestamps to datetime objects
df_all_trh["Timestamp"] = pd.to_datetime(
df_all_trh["Timestamp"], format="mixed"
df_all_trh["Timestamp"], format="mixed", utc=True
).dt.tz_localize(None)
# Ensure start_time is timezone-naive
start_time = start_time.replace(tzinfo=None)
end_time = end_time.replace(tzinfo=None)
relevant_temp_rhs = df_all_trh[
(df_all_trh["Robot"] == robot)
& (df_all_trh["Timestamp"] >= start_time)
& (df_all_trh["Timestamp"] <= end_time)
(df_all_trh["Robot"] == robot) & (df_all_trh["Timestamp"] >= start_time)
]
try:
avg_temp = round(mean(relevant_temp_rhs["Temp (oC)"]), 2)
avg_rh = round(mean(relevant_temp_rhs["Relative Humidity (%)"]), 2)
except StatisticsError:
avg_temp = None
avg_rh = None
# If there is one value assign it as the average.
if len(relevant_temp_rhs["Temp (oC)"]) == 1:
avg_temp = relevant_temp_rhs["Temp (oC)"][0]
avg_rh = relevant_temp_rhs["Relative Humidity (%)"][0]
else:
avg_temp = None
avg_rh = None
# Get AVG t/rh of runs w/ same robot & protocol newer than 3 wks old with no errors
weeks_ago_3 = start_time - timedelta(weeks=3)
df_all_run_data = pd.DataFrame(all_run_data)
df_all_run_data["Start_Time"] = pd.to_datetime(
df_all_run_data["Start_Time"], format="mixed"
df_all_run_data["Start_Time"], format="mixed", utc=True
).dt.tz_localize(None)
df_all_run_data["Errors"] = pd.to_numeric(df_all_run_data["Errors"])
df_all_run_data["Average Temp (oC)"] = pd.to_numeric(
Expand Down Expand Up @@ -283,7 +285,9 @@ def get_robot_state(
components = match_error_to_component("RABR", reported_string, components)
print(components)
end_time = datetime.now()
print(end_time)
start_time = end_time - timedelta(hours=2)
print(start_time)
# Get current temp/rh compared to historical data
temp_rh_string = compare_current_trh_to_average(
parent, start_time, end_time, "", storage_directory
Expand Down
15 changes: 11 additions & 4 deletions api-client/src/dataFiles/uploadCsvFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ export function uploadCsvFile(
config: HostConfig,
data: FileData
): ResponsePromise<UploadedCsvFileResponse> {
return request<UploadedCsvFileResponse>(
let formData

if (typeof data !== 'string') {
formData = new FormData()
formData.append('file', data)
} else {
formData = data
}
return request<UploadedCsvFileResponse, FormData | string>(
POST,
'/dataFiles',
null,
config,
data
formData,
config
)
}
13 changes: 11 additions & 2 deletions api-client/src/protocols/createProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { POST, request } from '../request'
import type { ResponsePromise } from '../request'
import type { HostConfig } from '../types'
import type { Protocol } from './types'
import type { RunTimeParameterCreateData } from '../runs'
import type {
RunTimeParameterValuesCreateData,
RunTimeParameterFilesCreateData,
} from '../runs'

export function createProtocol(
config: HostConfig,
files: File[],
protocolKey?: string,
protocolKind?: string,
runTimeParameterValues?: RunTimeParameterCreateData
runTimeParameterValues?: RunTimeParameterValuesCreateData,
runTimeParameterFiles?: RunTimeParameterFilesCreateData
): ResponsePromise<Protocol> {
const formData = new FormData()
files.forEach(file => {
Expand All @@ -22,6 +26,11 @@ export function createProtocol(
'runTimeParameterValues',
JSON.stringify(runTimeParameterValues)
)
if (runTimeParameterFiles != null)
formData.append(
'runTimeParameterFiles',
JSON.stringify(runTimeParameterFiles)
)

return request<Protocol, FormData>(POST, '/protocols', formData, config)
}
12 changes: 9 additions & 3 deletions api-client/src/protocols/createProtocolAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@ import { POST, request } from '../request'
import type { ProtocolAnalysisSummary } from '@opentrons/shared-data'
import type { ResponsePromise } from '../request'
import type { HostConfig } from '../types'
import type { RunTimeParameterCreateData } from '../runs'
import type {
RunTimeParameterFilesCreateData,
RunTimeParameterValuesCreateData,
} from '../runs'

interface CreateProtocolAnalysisData {
runTimeParameterValues: RunTimeParameterCreateData
runTimeParameterValues: RunTimeParameterValuesCreateData
runTimeParameterFiles: RunTimeParameterFilesCreateData
forceReAnalyze: boolean
}

export function createProtocolAnalysis(
config: HostConfig,
protocolKey: string,
runTimeParameterValues?: RunTimeParameterCreateData,
runTimeParameterValues?: RunTimeParameterValuesCreateData,
runTimeParameterFiles?: RunTimeParameterFilesCreateData,
forceReAnalyze?: boolean
): ResponsePromise<ProtocolAnalysisSummary[]> {
const data = {
runTimeParameterValues: runTimeParameterValues ?? {},
runTimeParameterFiles: runTimeParameterFiles ?? {},
forceReAnalyze: forceReAnalyze ?? false,
}
const response = request<
Expand Down
8 changes: 2 additions & 6 deletions api-client/src/protocols/getCsvFiles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { v4 as uuidv4 } from 'uuid'

// import { GET, request } from '../request'

// import type { ResponsePromise } from '../request'
Expand All @@ -25,18 +23,16 @@ export function getCsvFiles(
config: HostConfig,
protocolId: string
): Promise<{ data: UploadedCsvFilesResponse }> {
const fileIdOne = uuidv4()
const fileIdTwo = uuidv4()
const stub = {
data: {
files: [
{
id: fileIdOne,
id: '1',
createdAt: '2024-06-07T19:19:56.268029+00:00',
name: 'rtp_mock_file1.csv',
},
{
id: fileIdTwo,
id: '2',
createdAt: '2024-06-17T19:19:56.268029+00:00',
name: 'rtp_mock_file2.csv',
},
Expand Down
6 changes: 4 additions & 2 deletions api-client/src/runs/createRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import type { HostConfig } from '../types'
import type {
Run,
LabwareOffsetCreateData,
RunTimeParameterCreateData,
RunTimeParameterValuesCreateData,
RunTimeParameterFilesCreateData,
} from './types'

export interface CreateRunData {
protocolId?: string
labwareOffsets?: LabwareOffsetCreateData[]
runTimeParameterValues?: RunTimeParameterCreateData
runTimeParameterValues?: RunTimeParameterValuesCreateData
runTimeParameterFiles?: RunTimeParameterFilesCreateData
}

export function createRun(
Expand Down
7 changes: 4 additions & 3 deletions api-client/src/runs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ export interface LabwareOffsetCreateData {
vector: VectorOffset
}

type RunTimeParameterValueType = string | number | boolean | { id: string }
export type RunTimeParameterCreateData = Record<
type RunTimeParameterValuesType = string | number | boolean | { id: string }
export type RunTimeParameterValuesCreateData = Record<
string,
RunTimeParameterValueType
RunTimeParameterValuesType
>
export type RunTimeParameterFilesCreateData = Record<string, string>

export interface CommandData {
data: RunTimeCommand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ async def move(
origin=origin, target_list=[move_target]
)
except ZeroLengthMoveError as zme:
log.warning(f"Not moving because move was zero length {str(zme)}")
log.debug(f"Not moving because move was zero length {str(zme)}")
return
moves = movelist[0]
log.info(f"move: machine {target} from {origin} requires {moves}")
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/hardware_control/ot3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,8 @@ async def liquid_probe(
except PipetteLiquidNotFoundError as lnfe:
error = lnfe
pos = await self.gantry_position(checked_mount, refresh=True)
await self.move_to(checked_mount, probe_start_pos + top_types.Point(z=2))
await self.prepare_for_aspirate(checked_mount)
await self.move_to(checked_mount, probe_start_pos)
if error is not None:
# if we never found liquid raise an error
Expand Down
4 changes: 2 additions & 2 deletions api/src/opentrons/protocol_api/core/engine/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def liquid_probe_with_recovery(self, well_core: WellCore, loc: Location) -> None
labware_id = well_core.labware_id
well_name = well_core.get_name()
well_location = WellLocation(
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=0)
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=2)
)
self._engine_client.execute_command(
cmd.LiquidProbeParams(
Expand All @@ -898,7 +898,7 @@ def liquid_probe_without_recovery(
labware_id = well_core.labware_id
well_name = well_core.get_name()
well_location = WellLocation(
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=0)
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=2)
)
result = self._engine_client.execute_command_without_recovery(
cmd.LiquidProbeParams(
Expand Down
4 changes: 0 additions & 4 deletions api/src/opentrons/protocol_api/protocol_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ def cleanup(self) -> None:
self._unsubscribe_commands()
self._unsubscribe_commands = None

def __del__(self) -> None:
if getattr(self, "_unsubscribe_commands", None):
self._unsubscribe_commands() # type: ignore

@property
@requires_version(2, 0)
def max_speeds(self) -> AxisMaxSpeeds:
Expand Down
5 changes: 4 additions & 1 deletion api/src/opentrons/protocol_engine/commands/liquid_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ async def execute(self, params: _CommonParams) -> _LiquidProbeExecuteReturn:

try:
z_pos = await self._pipetting.liquid_probe_in_place(
pipette_id=pipette_id, labware_id=labware_id, well_name=well_name
pipette_id=pipette_id,
labware_id=labware_id,
well_name=well_name,
well_location=params.wellLocation,
)
except PipetteLiquidNotFoundError as e:
return DefinedErrorData(
Expand Down
8 changes: 6 additions & 2 deletions api/src/opentrons/protocol_engine/execution/pipetting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
InvalidPushOutVolumeError,
InvalidDispenseVolumeError,
)

from opentrons.protocol_engine.types import WellLocation

# 1e-9 µL (1 femtoliter!) is a good value because:
# * It's large relative to rounding errors that occur in practice in protocols. For
Expand Down Expand Up @@ -68,6 +68,7 @@ async def liquid_probe_in_place(
pipette_id: str,
labware_id: str,
well_name: str,
well_location: WellLocation,
) -> float:
"""Detect liquid level."""

Expand Down Expand Up @@ -176,6 +177,7 @@ async def liquid_probe_in_place(
pipette_id: str,
labware_id: str,
well_name: str,
well_location: WellLocation,
) -> float:
"""Detect liquid level."""
hw_pipette = self._state_view.pipettes.get_hardware_pipette(
Expand All @@ -188,7 +190,8 @@ async def liquid_probe_in_place(
pipette_id=pipette_id
)
z_pos = await self._hardware_api.liquid_probe(
mount=hw_pipette.mount, max_z_dist=well_depth - lld_min_height
mount=hw_pipette.mount,
max_z_dist=well_depth - lld_min_height + well_location.offset.z,
)
return float(z_pos)

Expand Down Expand Up @@ -290,6 +293,7 @@ async def liquid_probe_in_place(
pipette_id: str,
labware_id: str,
well_name: str,
well_location: WellLocation,
) -> float:
"""Detect liquid level."""
# TODO (pm, 6-18-24): return a value of worth if needed
Expand Down
6 changes: 5 additions & 1 deletion api/src/opentrons/system/log_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
MAX_RECORDS = 100000
DEFAULT_RECORDS = 50000

UNIT_SELECTORS = ["opentrons-robot-server", "opentrons-robot-app"]
UNIT_SELECTORS = [
"opentrons-robot-server",
"opentrons-update-server",
"opentrons-robot-app",
]
SERIAL_SPECIAL = "ALL_SERIAL"
SERIAL_SELECTORS = [
"opentrons-api-serial",
Expand Down
8 changes: 4 additions & 4 deletions api/tests/opentrons/hardware_control/test_ot3_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ async def test_liquid_probe(
)
fake_max_z_dist = 10.0
await ot3_hardware.liquid_probe(mount, fake_max_z_dist, fake_settings_aspirate)
mock_move_to_plunger_bottom.assert_called_once()
mock_move_to_plunger_bottom.call_count == 2
mock_liquid_probe.assert_called_once_with(
mount,
3.0,
Expand Down Expand Up @@ -910,7 +910,7 @@ async def test_multi_liquid_probe(
await ot3_hardware.liquid_probe(
OT3Mount.LEFT, fake_max_z_dist, fake_settings_aspirate
)
assert mock_move_to_plunger_bottom.call_count == 3
assert mock_move_to_plunger_bottom.call_count == 4
mock_liquid_probe.assert_called_with(
OT3Mount.LEFT,
plunger_positions.bottom - plunger_positions.top,
Expand Down Expand Up @@ -986,8 +986,8 @@ async def _fake_pos_update_and_raise(
await ot3_hardware.liquid_probe(
OT3Mount.LEFT, fake_max_z_dist, fake_settings_aspirate
)
# assert that it went through 3 passes
assert mock_move_to_plunger_bottom.call_count == 3
# assert that it went through 3 passes and then prepared to aspirate
assert mock_move_to_plunger_bottom.call_count == 4


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ def test_liquid_probe_without_recovery(
cmd.LiquidProbeParams(
pipetteId=subject.pipette_id,
wellLocation=WellLocation(
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=0)
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=2)
),
wellName=well_core.get_name(),
labwareId=well_core.labware_id,
Expand Down Expand Up @@ -1402,7 +1402,7 @@ def test_liquid_probe_with_recovery(
cmd.LiquidProbeParams(
pipetteId=subject.pipette_id,
wellLocation=WellLocation(
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=0)
origin=WellOrigin.TOP, offset=WellOffset(x=0, y=0, z=2.0)
),
wellName=well_core.get_name(),
labwareId=well_core.labware_id,
Expand Down
Loading

0 comments on commit 8112650

Please sign in to comment.