Skip to content

Commit

Permalink
feat(protocol-designer, step-generation, app): introduce pythonName t…
Browse files Browse the repository at this point in the history
…o each entity (#17463)

closes AUTH-1383

For python/pd interop, we want to add a `pythonName` to `liquidEntity`,
`labwareEntity`, `moduleEntity`, and `pipetteEntity`. This PR does that
by adding them in redux, that way, the `pythonName` is not polluting the
JSON structure. For Quick Transfer, the `pythonName` is generated in
`generateQuickTransferArgs`.

The python name patterning is as follows:
- modules: moduleType minus `Type` in snake case plus the number so
`heater_shaker_module_1` and then `heater_shaker_module_2` for 2
heater-shaker modules
- pipettes: `pipette_left` or `pipette_right`
- labware: the labware displayCategory in snake case plus the number. So
2 well plates and 1 reservoir would be `well_plate_1`, `well_plate_2`,
`reservoir_1`
- liquids: just liquid with the number so `liquid_1`, `liquid_2`, etc.
  • Loading branch information
jerader authored Feb 7, 2025
1 parent f8a5436 commit f687a3a
Show file tree
Hide file tree
Showing 78 changed files with 591 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function createQuickTransferFile(
},
designerApplication: {
name: 'opentrons/quick-transfer',
version: '1.0.0',
version: '1.1.0',
data: quickTransferState,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function getInvariantContextAndRobotState(
tiprackDefURI: [tipRackDefURI],
tiprackLabwareDef: [quickTransferState.tipRack],
spec: quickTransferState.pipette,
pythonName: 'pipette_left',
},
}
const pipetteLocations: RobotState['pipettes'] = {
Expand All @@ -88,6 +89,7 @@ function getInvariantContextAndRobotState(
id: adapterId,
labwareDefURI: adapter96ChannelDefUri,
def: getAllDefinitions()[adapter96ChannelDefUri],
pythonName: 'adapter_1',
},
}
labwareLocations = {
Expand All @@ -96,18 +98,28 @@ function getInvariantContextAndRobotState(
},
}
}
const sourceDisplayCategory =
quickTransferState.source.metadata.displayCategory
const destDisplayCategory =
quickTransferState.destination !== 'source'
? quickTransferState.destination.metadata.displayCategory
: sourceDisplayCategory

const isSameDisplayCategory = sourceDisplayCategory === destDisplayCategory

labwareEntities = {
...labwareEntities,
[tipRackId]: {
id: tipRackId,
labwareDefURI: tipRackDefURI,
def: quickTransferState.tipRack,
pythonName: 'tip_rack_1',
},
[sourceLabwareId]: {
id: sourceLabwareId,
labwareDefURI: sourceLabwareURI,
def: quickTransferState.source,
pythonName: `${sourceDisplayCategory}_1`,
},
}
labwareLocations = {
Expand All @@ -129,6 +141,9 @@ function getInvariantContextAndRobotState(
id: destLabwareId,
labwareDefURI: destLabwareURI,
def: quickTransferState.destination,
pythonName: isSameDisplayCategory
? `${destDisplayCategory}_2`
: `${destDisplayCategory}_1`,
},
}
labwareLocations = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"pythonName": "liquid_1",
"liquidGroupId": "0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"pythonName": "liquid_1",
"liquidGroupId": "0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"pythonName": "liquid_1",
"liquidGroupId": "0"
},
"1": {
"displayName": "Samples",
"displayColor": "#ffd600",
"description": null,
"pythonName": "liquid_2",
"liquidGroupId": "1"
}
},
Expand Down
2 changes: 0 additions & 2 deletions protocol-designer/fixtures/protocol/8/doItAllV8.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
"displayName": "h20",
"description": null,
"liquidGroupId": "0",
"pythonName": "liquid_1",
"displayColor": "#b925ff"
},
"1": {
"displayName": "sample",
"description": null,
"liquidGroupId": "1",
"pythonName": "liquid_2",
"displayColor": "#ffd600"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
"displayName": "samples",
"description": null,
"displayColor": "#b925ff",
"pythonName": "liquid_1",
"liquidGroupId": "0"
},
"1": {
"displayName": "dna",
"description": null,
"pythonName": "liquid_2",
"displayColor": "#ffd600",
"liquidGroupId": "1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"displayName": "123",
"displayColor": "#b925ff",
"description": null,
"pythonName": "liquid_1",
"liquidGroupId": "0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ export const labwareEntities: LabwareEntities = {
labwareDefURI: 'opentrons/opentrons_1_trash_1100ml_fixed/1',
id: 'fixedTrash',
def: fixtureTrash,
pythonName: 'mockPythonName',
},
tiprackId: {
labwareDefURI: 'opentrons/opentrons_96_tiprack_10ul/1',
id: 'tiprackId',
def: fixtureTiprack10ul,
pythonName: 'mockPythonName',
},
plateId: {
labwareDefURI: 'opentrons/nest_96_wellplate_100ul_pcr_full_skirt/1',
id: 'plateId',
def: fixture96Plate,
pythonName: 'mockPythonName',
},
}
export const pipetteEntities: PipetteEntities = {
Expand All @@ -59,6 +62,7 @@ export const pipetteEntities: PipetteEntities = {
spec: fixtureP10SingleV2Specs,
tiprackDefURI: ['opentrons/opentrons_96_tiprack_10ul/1'],
tiprackLabwareDef: [fixtureTiprack10ul],
pythonName: 'mockPythonName',
},
}
export const labwareNicknamesById: Record<string, string> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ export const moduleEntities: ModuleEntities = {
id: 'magneticModuleId',
type: 'magneticModuleType',
model: 'magneticModuleV1',
pythonName: 'mockPythonName',
},
}
2 changes: 2 additions & 0 deletions protocol-designer/src/file-data/__tests__/createFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ describe('getLabwareDefinitionsInUse util', () => {
id: 'someLabwareId',
def: assignedTiprackOnDeckDef as LabwareDefinition2,
labwareDefURI: 'assignedTiprackOnDeckURI',
pythonName: 'mockPythonName',
},
otherLabwareId: {
id: 'otherLabwareId',
def: nonTiprackLabwareOnDeckDef as LabwareDefinition2,
labwareDefURI: 'nonTiprackLabwareOnDeckURI',
pythonName: 'mockPythonName',
},
}
const allLabwareDefsByURI: LabwareDefByDefURI = {
Expand Down
3 changes: 3 additions & 0 deletions protocol-designer/src/file-data/__tests__/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('getPipettesLoadInfo', () => {
name: fixtureP1000SingleV2Specs.displayName as PipetteName,
id: pipId,
tiprackDefURI: [],
pythonName: 'mockPythonName',
},
})
).toEqual(results)
Expand All @@ -46,6 +47,7 @@ describe('getModuleLoadInfo', () => {
id: moduleId,
model: 'magneticModuleV2',
type: 'magneticModuleType',
pythonName: 'mockPythonName',
},
})
).toEqual(results)
Expand Down Expand Up @@ -73,6 +75,7 @@ describe('getLabwareLoadInfo', () => {
id: labwareId,
labwareDefURI: uri,
def: fixture96Plate as LabwareDefinition2,
pythonName: 'mockPythonName',
},
},
labwareNicknamesById
Expand Down
26 changes: 25 additions & 1 deletion protocol-designer/src/file-data/selectors/fileCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
PipetteEntity,
LabwareEntities,
PipetteEntities,
Ingredients,
} from '@opentrons/step-generation'
import type {
CommandAnnotationV1Mixin,
Expand Down Expand Up @@ -140,6 +141,29 @@ export const createFile: Selector<ProtocolFile> = createSelector(
const savedOrderedStepIds = orderedStepIds.filter(
stepId => savedStepForms[stepId]
)

const ingredients: Ingredients = Object.entries(liquidEntities).reduce(
(acc: Ingredients, [liquidId, liquidData]) => {
const {
displayName,
description,
displayColor,
liquidGroupId,
liquidClass,
} = liquidData

acc[liquidId] = {
displayName,
description,
displayColor,
liquidGroupId,
liquidClass,
}
return acc
},
{}
)

const designerApplication = {
name: 'opentrons/protocol-designer',
version: applicationVersion,
Expand All @@ -151,7 +175,7 @@ export const createFile: Selector<ProtocolFile> = createSelector(
p.tiprackDefURI
),
dismissedWarnings,
ingredients: liquidEntities,
ingredients,
ingredLocations,
savedStepForms,
orderedStepIds: savedOrderedStepIds,
Expand Down
4 changes: 2 additions & 2 deletions protocol-designer/src/file-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
PipetteName,
ProtocolFile,
} from '@opentrons/shared-data'
import type { LiquidEntities } from '@opentrons/step-generation'
import type { Ingredients } from '@opentrons/step-generation'
import type { RootState as IngredRoot } from './labware-ingred/reducers'
import type { RootState as StepformRoot } from './step-forms'
import type { RootState as DismissRoot } from './dismiss'
Expand All @@ -25,7 +25,7 @@ export interface PDMetadata {
// pipetteId to tiprackModel
pipetteTiprackAssignments: Record<string, string[]>
dismissedWarnings: DismissRoot['dismissedWarnings']
ingredients: LiquidEntities
ingredients: Ingredients
ingredLocations: IngredRoot['ingredLocations']
savedStepForms: StepformRoot['savedStepForms']
orderedStepIds: StepformRoot['orderedStepIds']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ describe('createContainer', () => {
id: 'fakeUuid:someLabwareDefURI',
labwareDefURI: 'someLabwareDefURI',
slot: '4',
displayCategory: 'wellPlate',
},
},
]
Expand Down Expand Up @@ -163,6 +164,7 @@ describe('createContainer', () => {
id: 'fakeUuid:someLabwareDefURI',
labwareDefURI: 'someLabwareDefURI',
slot: '3',
displayCategory: 'wellPlate',
},
},
]
Expand Down Expand Up @@ -254,6 +256,7 @@ describe('createContainer', () => {
id: 'fakeUuid:someLabwareDefURI',
labwareDefURI: 'someLabwareDefURI',
slot: '4',
displayCategory: 'tipRack',
},
},
{
Expand Down
27 changes: 16 additions & 11 deletions protocol-designer/src/labware-ingred/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { selectors } from '../selectors'
import type { StepFieldName } from '../../form-types'
import type { DeckSlot, ThunkAction } from '../../types'
import type { Fixture, IngredInputs } from '../types'
import type { CutoutId, ModuleModel } from '@opentrons/shared-data'
import type {
CutoutId,
LabwareDisplayCategory,
ModuleModel,
} from '@opentrons/shared-data'
import type { LiquidEntities, LiquidEntity } from '@opentrons/step-generation'

// ===== Labware selector actions =====
export interface OpenAddLabwareModalAction {
Expand Down Expand Up @@ -69,6 +74,7 @@ export interface CreateContainerAction {
payload: CreateContainerArgs & {
slot: DeckSlot
id: string
displayCategory: LabwareDisplayCategory
}
}
export interface DeleteContainerAction {
Expand All @@ -77,10 +83,6 @@ export interface DeleteContainerAction {
labwareId: string
}
}
// @ts-expect-error(sa, 2021-6-20): creatActions doesn't return exact actions
export const deleteContainer: (payload: {
labwareId: string
}) => DeleteContainerAction = createAction('DELETE_CONTAINER')
// ===========
export interface SwapSlotContentsAction {
type: 'MOVE_DECK_ITEM'
Expand Down Expand Up @@ -108,6 +110,7 @@ export interface DuplicateLabwareAction {
duplicateLabwareId: string
duplicateLabwareNickname: string
slot: DeckSlot
displayCategory: LabwareDisplayCategory
}
}

Expand All @@ -128,7 +131,7 @@ export const removeWellsContents: (

export interface EditMultipleLiquidGroupsAction {
type: 'EDIT_MULTIPLE_LIQUID_GROUPS_PYTHON_NAME'
payload: Record<string, IngredInputs> // Updated liquid group pythonName
payload: LiquidEntities // Updated liquid group pythonName
}

export interface DeleteLiquidGroupAction {
Expand Down Expand Up @@ -163,7 +166,7 @@ export const deleteLiquidGroup: (

const updatedLiquidGroupPythonName = Object.keys(remainingLiquidEntities)
.sort() // sort to ensure correct order
.reduce<Record<string, IngredInputs>>((acc, oldId, index) => {
.reduce<Record<string, LiquidEntity>>((acc, oldId, index) => {
acc[oldId] = {
...remainingLiquidEntities[oldId],
pythonName: `liquid_${index + 1}`,
Expand Down Expand Up @@ -227,20 +230,22 @@ export interface EditLiquidGroupAction {
type: 'EDIT_LIQUID_GROUP'
payload: IngredInputs & {
liquidGroupId: string
pythonName: string
}
}
// NOTE: with no ID, a new one is assigned
export const editLiquidGroup: (
args: IngredInputs
) => ThunkAction<EditLiquidGroupAction> = args => (dispatch, getState) => {
const { liquidGroupId, ...payloadArgs } = args // NOTE: separate liquidGroupId for flow to understand unpacking :/

const { liquidGroupId: liquidGroupIdFromArg, ...payloadArgs } = args
const liquidGroupId =
liquidGroupIdFromArg || selectors.getNextLiquidGroupId(getState())
dispatch({
type: 'EDIT_LIQUID_GROUP',
payload: {
...payloadArgs,
liquidGroupId:
args.liquidGroupId || selectors.getNextLiquidGroupId(getState()),
liquidGroupId,
pythonName: `liquid_${parseInt(liquidGroupId) + 1}`,
},
})
}
Expand Down
Loading

0 comments on commit f687a3a

Please sign in to comment.