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

fix(api): Addition of distribution error to prevent invalid disposal values #13659

Conversation

CaseyBatten
Copy link
Contributor

Overview

Prevents the distribute functionality from accepting a disposal value equal to or greater than the maximum value of the instrument. This was necessary to prevent an infinite looping issue where when disposal values greater than or equal to the maximum volume of an instrument were provided, which would cause the looping component of the _plan_distribute function to get caught in an state that was impossible to complete. This would seek to solve the issue detailed in RSS-347.

Prevents the distribute functionality from accepting a disposal value equal to or greater than the maximum value of the instrument.
@CaseyBatten CaseyBatten requested a review from a team as a code owner September 26, 2023 20:14
@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Merging #13659 (e495aa9) into edge (433c520) will decrease coverage by 0.01%.
Report is 46 commits behind head on edge.
The diff coverage is n/a.

❗ Current head e495aa9 differs from pull request most recent head 5ac7a93. Consider uploading reports for the commit 5ac7a93 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #13659      +/-   ##
==========================================
- Coverage   71.15%   71.15%   -0.01%     
==========================================
  Files        2431     2431              
  Lines       68420    68419       -1     
  Branches     8053     8053              
==========================================
- Hits        48682    48681       -1     
  Misses      17865    17865              
  Partials     1873     1873              
Flag Coverage Δ
g-code-testing 96.44% <ø> (ø)
notify-server 89.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
.../opentrons/protocols/advanced_control/transfers.py 92.85% <ø> (-0.03%) ⬇️


if self._strategy.disposal_volume >= self._instr.max_volume:
raise ValueError(
"The Disposal Volume must be less than the Maximum Volume of the Instrument"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good! We can probably lowercase all these terms in the error text:

Suggested change
"The Disposal Volume must be less than the Maximum Volume of the Instrument"
"The disposal volume must be less than the maximum volume of the pipette"

Updated error message to be consistent with desired message, moved error raise to a validation function call to ensure _plan_distribute is not too complex
Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

Looks great, thank you! A couple notes for moving forward with this.

api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
@SyntaxColoring
Copy link
Contributor

SyntaxColoring commented Sep 27, 2023

Okay, I've done some archeology and found that this was previously reported as GitHub issue #6170 and we tried to fix it in PR #6754. We closed that PR without merging it because of these reasons. 2.5 years later, I no longer think those reasons are good. In particular, screw this:

...by my understanding of our Python Protocol API's versioning policy, we must characterize and preserve that behavior in fixing these bugs. Even though it was undocumented, and didn't make sense, and only happened in incorrectly written protocols.

Versioning in the Python Protocol API is good to avoid flagrantly breaking people's protocols. But it shouldn't prevent us from fixing flagrant bugs like infinite loops. That's not helping anybody.


So, for this PR, here's what we should do:

  1. Let's definitely add tests. Let's start with the ones from PR fix(api): Error instead of infinite-looping when disposal_volume is too high to make progress #6754. We'll have to lightly adapt them to work in our modern codebase, and we'll have to address some pending # todo comments, but it'll be much better than starting from scratch.
  2. As described in the old issue, we should solve this for air_gap, not just disposal_volume. We can crib from the old PR.
  3. Pending the two points above, and another round of code review, let's move forward with merging this despite the versioning concerns that we had 2.5 years ago.

Working volume used to better reflect operating case of distribute, test case added to test transfers regarding distribute test
Test cases added/modified for disposal vol and air gaps, addition of calls to check for this issue across all transfer plans, assertion of check in validation
Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

This looks great, thank you. Here are several minor comments, and then this looks good to merge.

api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
api/src/opentrons/protocols/advanced_control/transfers.py Outdated Show resolved Hide resolved
@@ -796,6 +796,83 @@ def test_all_options(_instr_labware):
assert xfer_plan_list == exp1


def test_invalid_air_gap_disposal_sum_distribute(_instr_labware):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should leave this to a separate PR, but:

This adds a few test functions that differ only in the values that they provide for disposal_volume and air_gap. This would be a good use case for pytest parametrization. We could write this as one function that gets parametrized with the different disposal_volume and air_gap combinations.

We could also parametrize this over the mode of TransferPlan: "distribute", "consolidate", or "transfer". That would be good because our bugfix does touch those other functions.

Adjustment of calls, change over to max volume control, formatting and improvement of test case formatting
@CaseyBatten
Copy link
Contributor Author

Primary fail issues cleared, formatting good, I believe this is ready for merge.

Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

This looks good to merge, assuming CI passes. I'm a little worried about that failing G-code test. I'm checking now to see if it's something that was introduced by this PR, or whether it's the known issue that was fixed in #13670.

Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

G-code tests are failing on edge, so I'm presuming those failures are unrelated to this PR. (I'm running into obscure unrelated errors trying to run them locally, so I can't be sure.)

This looks good to merge. Thank you!

@CaseyBatten CaseyBatten merged commit bf85a29 into edge Oct 3, 2023
20 of 23 checks passed
@CaseyBatten CaseyBatten deleted the Distribute-disposal-value-error-case-to-prevent-invalid-values branch October 3, 2023 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants