Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(step-generation): update nozzles in robotState not from initialRobotState #14155

Merged
merged 6 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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(

Check warning on line 58 in protocol-designer/src/file-data/selectors/commands.ts

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/file-data/selectors/commands.ts#L58

Added line #L58 was not covered by tests
initialDeckSetup.pipettes,
(p: PipetteOnDeck): PipetteTemporalProperties => ({

Check warning on line 60 in protocol-designer/src/file-data/selectors/commands.ts

View check run for this annotation

Codecov / codecov/patch

protocol-designer/src/file-data/selectors/commands.ts#L60

Added line #L60 was not covered by tests
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,
getWasteChuteAddressableAreaNamePip,
} from '../../utils'
Expand Down Expand Up @@ -466,22 +465,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
)
Comment on lines -481 to -484
Copy link
Collaborator Author

@jerader jerader Dec 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't actually needed since the robot will reset the nozzles to "All" at the end of each run. So i removed it to clean it up. Plus it should go in generateRobotStateTimeline instead since that's where the final drop tip commands get emitted


return [
...configureNozzleLayoutCommand,
Expand All @@ -497,7 +491,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,
getWasteChuteAddressableAreaNamePip,
} from '../../utils'
Expand Down Expand Up @@ -448,22 +447,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 @@ -485,7 +479,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,
getWasteChuteAddressableAreaNamePip,
} from '../../utils'
Expand Down Expand Up @@ -275,22 +274,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 @@ -598,7 +592,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 @@ -45,6 +45,7 @@ import type {
RobotState,
RobotStateAndWarnings,
} from '../types'
import { forConfigureNozzleLayout } from './forConfigureNozzleLayout'

// WARNING this will mutate the prevRobotState
function _getNextRobotStateAndWarningsSingleCommand(
Expand Down Expand Up @@ -123,6 +124,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
22 changes: 1 addition & 21 deletions step-generation/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
getWellsDepth,
getWellNamePerMultiTip,
WASTE_CHUTE_CUTOUT,
COLUMN,
ALL,
PipetteChannels,
ONE_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
EIGHT_CHANNEL_WASTE_CHUTE_ADDRESSABLE_AREA,
Expand All @@ -18,18 +16,14 @@ import {
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 @@ -700,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,
}),
]
: []
}
Loading