-
Notifications
You must be signed in to change notification settings - Fork 178
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
feat(protocol engine): add helpers for intra-frustum calculations #16189
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can improve the type definitions, organization, and error handling but the math part and approach to testing looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actual body of the added functions look good besides for a couple nitpicks on that and some of the testing.
The bigger change I'm going to request here is moving the @staticmethod
functions added to the GeometryView
to be instead in its own helper function file. The reason for this has more to do with future unit testing than any dislike of static methods. If these methods remain where they are, future testing will have to make sure that any tested value will have to be mathematically accurate, even for unrelated tests or tests for code structure and not functional value testing.
If these are moved to their own file, then we can follow the pattern of monkeypatching out these functions, allowing geometry tests to focus on the higher level organization and let the frustra calculations be tested purely in isolation.
api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Outdated
Show resolved
Hide resolved
api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Outdated
Show resolved
Hide resolved
api/tests/opentrons/protocol_engine/state/test_geometry_view.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Jeremy Leon <[email protected]>
Co-authored-by: Jeremy Leon <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, thanks for the changes.
Overview
Within a given frustum, we know the math for finding both a volume given height, and a height given volume. This adds helper functions which perform that math for all shapes we have thus far (circular, rectangular, spherical).
The math for both the circular and rectangular frusta is found by integrating over the area of every cross section within a frustum, with respect to the height of the frustum.
I didn't personally derive the method for finding the volume of a spherical section, or spherical cap. This is where I got it from: https://www.cuemath.com/measurement/volume-of-a-section-of-a-sphere/
Changelog
height_from_volume_blank
andvolume_from_height_blank
functions for all shapes (we'll have the caller dispatch by shape)numpy.roots
InvalidLiquidHeightFound
error in case we can't return 1 valid solution to our volume polynomialTest Plan
I'm unsure how to go about testing the math for the spherical cap, but for rectangular and circular frusta, the tests are as follows:
I used google sheets to generate csv representations of both circular and rectangular frusta, where the area components (radius, length, width) grow or decay at a constant rate. I then translated each "frustum" into a python dictionary. The csv's are here and here if that's helpful.
The test functions I added use the height at some randomly determined row to find the volume at that height. They then use that volume to analytically determine what the height should be, and then it checks that the found height and the "actual" height from the dictionary are the same.