Skip to content
Open
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
6 changes: 5 additions & 1 deletion protocol-designer/src/file-data/selectors/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ export const getInitialRobotState: (
pipetteLocations: pipettes,
})
robotState.liquidState.labware = labwareLiquidState
return robotState
return StepGeneration.enrichRobotStateForStackGraphTraversals(
robotState,
invariantContext.moduleEntities,
invariantContext.labwareEntities
)
}
)

Expand Down
27 changes: 9 additions & 18 deletions protocol-designer/src/file-data/selectors/traversals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createSelector } from 'reselect'

import { getDeckDefFromRobotType } from '@opentrons/shared-data'
import {
enrichRobotStateForStackGraphTraversals,
getAllLargestStacks,
getAllProvidedAddressableAreasFromDeckConfig as getAllProvidedAddressableAreasFromDeckConfigUtil,
getProvidedAddressableAreasExposed,
Expand All @@ -19,26 +18,18 @@ import type {
import type { RobotState } from '@opentrons/step-generation'
import type { Selector } from '../../types'

/** Initial-deck robot state with `stackedOnNode` (and sibling `contains` when applicable) for traversals. */
export const getRobotStateEnrichedForStackGraphFromRobotState: Selector<RobotState> =
createSelector(
getInitialRobotState,
stepFormSelectors.getModuleEntities,
stepFormSelectors.getLabwareEntities,
(robotState, moduleEntities, labwareEntities) =>
enrichRobotStateForStackGraphTraversals(
robotState,
moduleEntities,
labwareEntities
)
)
/**
* Alias of {@link getInitialRobotState}: stack-graph fields (`stackedOnNode`, sibling `contains`)
* are applied once when that selector builds robot state, not when reading timeline frames.
*/
export const getInitialEnrichedRobotState: Selector<RobotState> =
getInitialRobotState

/** All largest `LoadedLabwareLocation` stacks on the initial deck. */
export const getAllLargestStacksForInitialRobotState: Selector<
LoadedLabwareLocation[][]
> = createSelector(
getRobotStateEnrichedForStackGraphFromRobotState,
robotState => getAllLargestStacks(robotState)
> = createSelector(getInitialEnrichedRobotState, robotState =>
getAllLargestStacks(robotState)
)

/** Addressable areas provided by the current deck fixture configuration. */
Expand All @@ -60,7 +51,7 @@ export const getAllProvidedAddressableAreasFromDeckConfig: Selector<
export const getProvidedAddressableAreasExposedForRobotState: Selector<
Set<AddressableAreaName>
> = createSelector(
getRobotStateEnrichedForStackGraphFromRobotState,
getInitialEnrichedRobotState,
getRobotType,
stepFormSelectors.getDeckConfiguration,
stepFormSelectors.getModuleEntities,
Expand Down
45 changes: 13 additions & 32 deletions protocol-designer/src/top-selectors/labware-locations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from '@opentrons/shared-data'
import {
COLUMN_4_SLOTS,
enrichRobotStateForStackGraphTraversals,
getAllLargestStacks,
getProvidedAddressableAreasExposed,
getSlotInLocationStack,
Expand Down Expand Up @@ -382,52 +381,34 @@ export const getDeckSetupForActiveItem: Selector<AllTemporalPropertiesForTimelin
}
)

/** Memoized largest stacks at the active timeline item (`stack` → `stackedOnNode`; sibling `contains` when applicable). */
/**
* Largest stacks at the active timeline item.
* Expects `robotState` from simulation to already carry `stackedOnNode` / `contains` (initial deck
* from {@link getInitialRobotState}, then per-command updaters such as `forMoveLabware`).
*/
export const getAllLargestStacksAtActiveItem: Selector<
LoadedLabwareLocation[][]
> = createSelector(
getRobotStateAtActiveItem,
getModuleEntities,
getLabwareEntities,
(robotState, moduleEntities, labwareEntities) => {
if (robotState == null) {
return []
}
return getAllLargestStacks(
enrichRobotStateForStackGraphTraversals(
robotState,
moduleEntities,
labwareEntities
)
)
> = createSelector(getRobotStateAtActiveItem, robotState => {
if (robotState == null) {
return []
}
)
return getAllLargestStacks(robotState)
})

/** Memoized: provided addressable areas not covered by a labware stack at the timeline’s active item. */
/** Provided addressable areas not covered by a labware stack at the timeline’s active item. */
export const getProvidedAddressableAreasExposedAtActiveItem: Selector<
Set<AddressableAreaName>
> = createSelector(
getRobotStateAtActiveItem,
getRobotType,
stepFormSelectors.getDeckConfiguration,
getModuleEntities,
getLabwareEntities,
(
robotState,
robotType,
deckConfigurationState,
moduleEntities,
labwareEntities
) => {
(robotState, robotType, deckConfigurationState, moduleEntities) => {
if (robotState == null) {
return new Set<AddressableAreaName>()
}
return getProvidedAddressableAreasExposed({
robotState: enrichRobotStateForStackGraphTraversals(
robotState,
moduleEntities,
labwareEntities
),
robotState,
deckConfiguration: deckConfigurationState.deckConfig,
deckDefinition: getDeckDefFromRobotType(robotType),
moduleEntities,
Expand Down
1 change: 0 additions & 1 deletion shared-data/js/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,6 @@ export const replaceCutoutFixtureWithComboFixture = (
cutoutId,
getDeckDefFromRobotType('OT-3 Standard')
)
console.log('addressableAreasById', addressableAreasById)

return addedCutoutConfigs.map(aaCutoutItem => {
// Handle waste chute combo fixtures
Expand Down
6 changes: 4 additions & 2 deletions step-generation/src/utils/__tests__/traversals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ describe('traversals', () => {
it('derives stackedOnNode from PD-style stack for labware on a deck slot', () => {
const result = enrichRobotStateForStackGraphTraversals(
pdStyleStackRobotState,
{} as ModuleEntities
{} as ModuleEntities,
{} as LabwareEntities
)
expect(result.labware.plate).toMatchObject({
stack: ['plate', 'B2'],
Expand All @@ -454,7 +455,8 @@ describe('traversals', () => {
}
const result = enrichRobotStateForStackGraphTraversals(
pdStyleStackRobotState,
{} as ModuleEntities
{} as ModuleEntities,
{} as LabwareEntities
)
expect(result.labware.plate.stackedOnNode).toEqual({ slotName: 'C3' })
})
Expand Down
13 changes: 9 additions & 4 deletions step-generation/src/utils/traversals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,16 @@ export const assignContainsAmongSiblings = (
*
* When `labwareEntities` is passed, pairs of labware that share the same eligible parent
* `stackedOnNode` may set `contains` on the larger footprint to the smaller labware id.
*
* **Protocol Designer:** call once when composing initial robot state (see PD
* {@link getInitialEnrichedRobotState}). After that, timeline `robotState` frames should keep this metadata
* current via command-specific updaters (`forMoveLabware`, stacker handlers, etc.), not by
* re-running this helper on every active step.
*/
export const enrichRobotStateForStackGraphTraversals = (
robotState: RobotState,
moduleEntities: ModuleEntities,
labwareEntities?: LabwareEntities
labwareEntities: LabwareEntities
): RobotState => {
const labwareIds = Object.keys(robotState.labware)
const labwareEntityIds = new Set(labwareIds)
Expand All @@ -609,9 +614,9 @@ export const enrichRobotStateForStackGraphTraversals = (
})
return stackedOnNode != null ? { ...lw, stackedOnNode } : { ...lw }
})
if (labwareEntities != null) {
labware = assignContainsAmongSiblings(labware, labwareEntities)
}
// assign contains among siblings
labware = assignContainsAmongSiblings(labware, labwareEntities)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there is any possibility that labwareEntities gets null/undefined?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this should never be the case. At worst it will be an empty object {}. Typechecks enforce this as well


return {
...robotState,
labware,
Expand Down
Loading