Skip to content

Commit

Permalink
refactor(step-generation): update nozzles in robotState not from init…
Browse files Browse the repository at this point in the history
…ialRobotState (#14155)
  • Loading branch information
jerader authored and ncdiehl11 committed Dec 19, 2023
1 parent 6e2d573 commit 2664a3d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 91 deletions.
36 changes: 6 additions & 30 deletions protocol-designer/src/file-data/selectors/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,43 +54,19 @@ export const getInitialRobotState: (
stepFormSelectors.getInitialDeckSetup,
stepFormSelectors.getInvariantContext,
getLabwareLiquidState,
stepFormSelectors.getSavedStepForms,
(initialDeckSetup, invariantContext, labwareLiquidState, savedStepForms) => {
const onlyPipettingFormSteps = Object.entries(savedStepForms).filter(
([stepId, form]) =>
form.stepType === 'moveLiquid' || form.stepType === 'mix'
(initialDeckSetup, invariantContext, labwareLiquidState) => {
const pipettes: Record<string, PipetteTemporalProperties> = mapValues(
initialDeckSetup.pipettes,
(p: PipetteOnDeck): PipetteTemporalProperties => ({
mount: p.mount,
})
)
const lastPipetteFormStep =
onlyPipettingFormSteps.length > 0
? onlyPipettingFormSteps[onlyPipettingFormSteps.length - 1]
: null
const lastPipettingStepNozzles =
lastPipetteFormStep != null ? lastPipetteFormStep[1]?.nozzles : undefined

const prevPipetteFormStep =
onlyPipettingFormSteps.length > 1
? onlyPipettingFormSteps[onlyPipettingFormSteps.length - 2]
: null
// NOTE: previous pipetting step nozzles is necessary
// in order to know when to emit the configureNozzleLayout
// command
const prevPipettingStepNozzles =
prevPipetteFormStep != null ? prevPipetteFormStep[1]?.nozzles : undefined
const labware: Record<string, LabwareTemporalProperties> = mapValues(
initialDeckSetup.labware,
(l: LabwareOnDeck): LabwareTemporalProperties => ({
slot: l.slot,
})
)
const pipettes: Record<string, PipetteTemporalProperties> = mapValues(
initialDeckSetup.pipettes,
(p: PipetteOnDeck): PipetteTemporalProperties => ({
mount: p.mount,
nozzles: p.name === 'p1000_96' ? lastPipettingStepNozzles : undefined,
prevNozzles:
p.name === 'p1000_96' ? prevPipettingStepNozzles : undefined,
})
)
const modules: Record<string, ModuleTemporalProperties> = mapValues(
initialDeckSetup.modules,
(m: ModuleOnDeck): ModuleTemporalProperties => {
Expand Down
11 changes: 2 additions & 9 deletions step-generation/src/commandCreators/compound/consolidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
airGapHelper,
dispenseLocationHelper,
moveHelper,
getConfigureNozzleLayoutCommandReset,
getIsTallLabwareWestOf96Channel,
} from '../../utils'
import {
Expand Down Expand Up @@ -465,22 +464,17 @@ export const consolidate: CommandCreator<ConsolidateArgs> = (
const dropTipAfterDispenseAirGap =
airGapAfterDispenseCommands.length > 0 ? dropTipCommand : []

const nozzles = prevRobotState.pipettes[args.pipette].nozzles
const prevNozzles = prevRobotState.pipettes[args.pipette].prevNozzles
const stateNozzles = prevRobotState.pipettes[args.pipette].nozzles
const configureNozzleLayoutCommand: CurriedCommandCreator[] =
// only emit the command if previous nozzle state is different
is96Channel && args.nozzles != null && nozzles !== prevNozzles
is96Channel && args.nozzles != null && args.nozzles !== stateNozzles
? [
curryCommandCreator(configureNozzleLayout, {
nozzles: args.nozzles,
pipetteId: args.pipette,
}),
]
: []
const configureNozzleLayoutCommandReset = getConfigureNozzleLayoutCommandReset(
args.pipette,
prevNozzles
)

return [
...configureNozzleLayoutCommand,
Expand All @@ -496,7 +490,6 @@ export const consolidate: CommandCreator<ConsolidateArgs> = (
...blowoutCommand,
...airGapAfterDispenseCommands,
...dropTipAfterDispenseAirGap,
...configureNozzleLayoutCommandReset,
]
}
)
Expand Down
11 changes: 2 additions & 9 deletions step-generation/src/commandCreators/compound/distribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
blowoutUtil,
wasteChuteCommandsUtil,
getDispenseAirGapLocation,
getConfigureNozzleLayoutCommandReset,
getIsTallLabwareWestOf96Channel,
} from '../../utils'
import {
Expand Down Expand Up @@ -447,22 +446,17 @@ export const distribute: CommandCreator<DistributeArgs> = (
]
: []

const nozzles = prevRobotState.pipettes[args.pipette].nozzles
const prevNozzles = prevRobotState.pipettes[args.pipette].prevNozzles
const stateNozzles = prevRobotState.pipettes[args.pipette].nozzles
const configureNozzleLayoutCommand: CurriedCommandCreator[] =
// only emit the command if previous nozzle state is different
is96Channel && args.nozzles != null && nozzles !== prevNozzles
is96Channel && args.nozzles != null && args.nozzles !== stateNozzles
? [
curryCommandCreator(configureNozzleLayout, {
nozzles: args.nozzles,
pipetteId: args.pipette,
}),
]
: []
const configureNozzleLayoutCommandReset = getConfigureNozzleLayoutCommandReset(
args.pipette,
prevNozzles
)

return [
...configureNozzleLayoutCommand,
Expand All @@ -484,7 +478,6 @@ export const distribute: CommandCreator<DistributeArgs> = (
...blowoutCommands,
...airGapAfterDispenseCommands,
...dropTipAfterDispenseAirGap,
...configureNozzleLayoutCommandReset,
]
}
)
Expand Down
11 changes: 2 additions & 9 deletions step-generation/src/commandCreators/compound/mix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
blowoutUtil,
curryCommandCreator,
reduceCommandCreators,
getConfigureNozzleLayoutCommandReset,
getIsTallLabwareWestOf96Channel,
} from '../../utils'
import * as errorCreators from '../../errorCreators'
Expand Down Expand Up @@ -179,11 +178,10 @@ export const mix: CommandCreator<MixArgs> = (
],
}
}
const nozzles = prevRobotState.pipettes[pipette].nozzles
const prevNozzles = prevRobotState.pipettes[pipette].prevNozzles
const stateNozzles = prevRobotState.pipettes[pipette].nozzles
const configureNozzleLayoutCommand: CurriedCommandCreator[] =
// only emit the command if previous nozzle state is different
is96Channel && data.nozzles != null && nozzles !== prevNozzles
is96Channel && data.nozzles != null && data.nozzles !== stateNozzles
? [
curryCommandCreator(configureNozzleLayout, {
nozzles: data.nozzles,
Expand All @@ -202,10 +200,6 @@ export const mix: CommandCreator<MixArgs> = (
}),
]
: []
const configureNozzleLayoutCommandReset = getConfigureNozzleLayoutCommandReset(
pipette,
prevNozzles
)
// Command generation
const commandCreators = flatMap(
wells,
Expand Down Expand Up @@ -264,7 +258,6 @@ export const mix: CommandCreator<MixArgs> = (
...mixCommands,
...blowoutCommand,
...touchTipCommands,
...configureNozzleLayoutCommandReset,
]
}
)
Expand Down
11 changes: 2 additions & 9 deletions step-generation/src/commandCreators/compound/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
getTrashOrLabware,
dispenseLocationHelper,
moveHelper,
getConfigureNozzleLayoutCommandReset,
getIsTallLabwareWestOf96Channel,
} from '../../utils'
import {
Expand Down Expand Up @@ -274,22 +273,17 @@ export const transfer: CommandCreator<TransferArgs> = (
changeTipNow =
isInitialSubtransfer || destinationWell !== prevDestWell
}
const nozzles = prevRobotState.pipettes[args.pipette].nozzles
const prevNozzles = prevRobotState.pipettes[args.pipette].prevNozzles
const stateNozzles = prevRobotState.pipettes[args.pipette].nozzles
const configureNozzleLayoutCommand: CurriedCommandCreator[] =
// only emit the command if previous nozzle state is different
is96Channel && args.nozzles != null && nozzles !== prevNozzles
is96Channel && args.nozzles != null && args.nozzles !== stateNozzles
? [
curryCommandCreator(configureNozzleLayout, {
nozzles: args.nozzles,
pipetteId: args.pipette,
}),
]
: []
const configureNozzleLayoutCommandReset = getConfigureNozzleLayoutCommandReset(
args.pipette,
prevNozzles
)

const configureForVolumeCommand: CurriedCommandCreator[] = LOW_VOLUME_PIPETTES.includes(
invariantContext.pipetteEntities[args.pipette].name
Expand Down Expand Up @@ -597,7 +591,6 @@ export const transfer: CommandCreator<TransferArgs> = (
...blowoutCommand,
...airGapAfterDispenseCommands,
...dropTipAfterDispenseAirGap,
...configureNozzleLayoutCommandReset,
]
// NOTE: side-effecting
prevSourceWell = sourceWell
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NozzleConfigurationStyle } from '@opentrons/shared-data'
import type { InvariantContext, RobotStateAndWarnings } from '../types'

interface ConfigureNozzleLayoutParams {
pipetteId: string
configurationParams: {
style: NozzleConfigurationStyle
primaryNozzle?: string
}
}

export function forConfigureNozzleLayout(
params: ConfigureNozzleLayoutParams,
invariantContext: InvariantContext,
robotStateAndWarnings: RobotStateAndWarnings
): void {
const { pipetteId, configurationParams } = params
const { robotState } = robotStateAndWarnings

robotState.pipettes[pipetteId].nozzles = configurationParams.style
}
6 changes: 6 additions & 0 deletions step-generation/src/getNextRobotStateAndWarnings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
RobotState,
RobotStateAndWarnings,
} from '../types'
import { forConfigureNozzleLayout } from './forConfigureNozzleLayout'

// WARNING this will mutate the prevRobotState
function _getNextRobotStateAndWarningsSingleCommand(
Expand Down Expand Up @@ -132,6 +133,11 @@ function _getNextRobotStateAndWarningsSingleCommand(
break

case 'configureNozzleLayout':
forConfigureNozzleLayout(
command.params,
invariantContext,
robotStateAndWarnings
)
break

case 'touchTip':
Expand Down
6 changes: 3 additions & 3 deletions step-generation/src/robotStateSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ export function getNextTiprack(
const filteredSortedTipRackIdsFor96Channel = sortedTipracksIds.filter(
tiprackId => {
const tipRackLocation = robotState.labware[tiprackId].slot
const tiprackLocation = invariantContext.labwareEntities[tipRackLocation]
const adapterEntity = invariantContext.labwareEntities[tipRackLocation]
const has96TiprackAdapterId =
tiprackLocation?.def.parameters.loadName ===
adapterEntity?.def.parameters.loadName ===
'opentrons_flex_96_tiprack_adapter' &&
tiprackLocation?.def.namespace === 'opentrons'
adapterEntity?.def.namespace === 'opentrons'

return nozzles === ALL ? has96TiprackAdapterId : !has96TiprackAdapterId
}
Expand Down
1 change: 0 additions & 1 deletion step-generation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface LabwareTemporalProperties {
export interface PipetteTemporalProperties {
mount: Mount
nozzles?: NozzleConfigurationStyle
prevNozzles?: NozzleConfigurationStyle
}

export interface MagneticModuleState {
Expand Down
26 changes: 5 additions & 21 deletions step-generation/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import {
getWellsDepth,
getWellNamePerMultiTip,
WASTE_CHUTE_CUTOUT,
COLUMN,
ALL,
PipetteChannels,
ONE_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
EIGHT_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
NINETY_SIX_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
} from '@opentrons/shared-data'
import { reduceCommandCreators, wasteChuteCommandsUtil } from './index'
import {
aspirate,
configureNozzleLayout,
dispense,
moveToAddressableArea,
moveToWell,
} from '../commandCreators/atomic'
import { blowout } from '../commandCreators/atomic/blowout'
import { curryCommandCreator } from './curryCommandCreator'
import { movableTrashCommandsUtil } from './movableTrashCommandsUtil'
import type {
LabwareDefinition2,
NozzleConfigurationStyle,
} from '@opentrons/shared-data'
import type { LabwareDefinition2 } from '@opentrons/shared-data'
import type { BlowoutParams } from '@opentrons/shared-data/protocol/types/schemaV4'
import type {
AdditionalEquipmentEntities,
Expand Down Expand Up @@ -696,17 +694,3 @@ export const airGapHelper: CommandCreator<AirGapArgs> = (

return reduceCommandCreators(commands, invariantContext, prevRobotState)
}

export const getConfigureNozzleLayoutCommandReset = (
pipetteId: string,
prevNozzles?: NozzleConfigurationStyle
): CurriedCommandCreator[] => {
return prevNozzles === COLUMN
? [
curryCommandCreator(configureNozzleLayout, {
nozzles: ALL,
pipetteId,
}),
]
: []
}

0 comments on commit 2664a3d

Please sign in to comment.