-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(api): reorganize existing transfer planner (#16724)
Preparation for AUTH-843 # Overview This PR moves the existing transfer planner to a new `transfers` directory and moves some functions into a common location in anticipation of the new `transfer_liquid` planner, which will be using the common functions.
- Loading branch information
Showing
12 changed files
with
218 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Common resources for all advanced control functions.""" | ||
import enum | ||
from typing import NamedTuple, Optional | ||
|
||
|
||
class MixStrategy(enum.Enum): | ||
BOTH = enum.auto() | ||
BEFORE = enum.auto() | ||
AFTER = enum.auto() | ||
NEVER = enum.auto() | ||
|
||
|
||
class MixOpts(NamedTuple): | ||
""" | ||
Options to customize behavior of mix. | ||
These options will be passed to | ||
:py:meth:`InstrumentContext.mix` when it is called during the | ||
transfer. | ||
""" | ||
|
||
repetitions: Optional[int] = None | ||
volume: Optional[float] = None | ||
rate: Optional[float] = None | ||
|
||
|
||
MixOpts.repetitions.__doc__ = ":py:class:`int`" | ||
MixOpts.volume.__doc__ = ":py:class:`float`" | ||
MixOpts.rate.__doc__ = ":py:class:`float`" | ||
|
||
|
||
class Mix(NamedTuple): | ||
""" | ||
Options to control mix behavior before aspirate and after dispense. | ||
""" | ||
|
||
mix_before: MixOpts = MixOpts() | ||
mix_after: MixOpts = MixOpts() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
45 changes: 45 additions & 0 deletions
45
api/src/opentrons/protocols/advanced_control/transfers/common.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Common functions between v1 transfer and liquid-class-based transfer.""" | ||
from typing import Iterable, Generator, Tuple, TypeVar | ||
|
||
Target = TypeVar("Target") | ||
|
||
|
||
def check_valid_volume_parameters( | ||
disposal_volume: float, air_gap: float, max_volume: float | ||
) -> None: | ||
if air_gap >= max_volume: | ||
raise ValueError( | ||
"The air gap must be less than the maximum volume of the pipette" | ||
) | ||
elif disposal_volume >= max_volume: | ||
raise ValueError( | ||
"The disposal volume must be less than the maximum volume of the pipette" | ||
) | ||
elif disposal_volume + air_gap >= max_volume: | ||
raise ValueError( | ||
"The sum of the air gap and disposal volume must be less than" | ||
" the maximum volume of the pipette" | ||
) | ||
|
||
|
||
def expand_for_volume_constraints( | ||
volumes: Iterable[float], | ||
targets: Iterable[Target], | ||
max_volume: float, | ||
) -> Generator[Tuple[float, "Target"], None, None]: | ||
"""Split a sequence of proposed transfers if necessary to keep each | ||
transfer under the given max volume. | ||
""" | ||
# A final defense against an infinite loop. | ||
# Raising a proper exception with a helpful message is left to calling code, | ||
# because it has more context about what the user is trying to do. | ||
assert max_volume > 0 | ||
for volume, target in zip(volumes, targets): | ||
while volume > max_volume * 2: | ||
yield max_volume, target | ||
volume -= max_volume | ||
|
||
if volume > max_volume: | ||
volume /= 2 | ||
yield volume, target | ||
yield volume, target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.