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(api): be more permissive with accepting int literals for float parameters #14820

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

jbleon95
Copy link
Contributor

@jbleon95 jbleon95 commented Apr 5, 2024

Overview

In the course of integrating runtime parameters frontend and backend work, it was discovered that for floating point parameters with a minimum and maximum range, if a literal int or value with only .0 was entered, the parameter validation would fail as the type int did not match the accepted float.

While discussing this, it was determined that it would be best to allow those values, while also being less strict in the parameter definition creation ParameterContext.add_float. This permissiveness does not go the other way for parameter definitions, if a user adds something like 6.0 as a default for ParameterContext.add_int, that will still raise an error (value sent over to one of the endpoints however will do this conversion, due to how we defined our Pydantic types). Other values sent over will also not be converted but instead raise the appropriate error elsewhere. This includes values like bool which can be type converted in Python, a value of True will also not be converted to 1.

Test Plan

Verified via postman that sending an int literal value for a float parameter override accepts the value and does not error out. Also ensure that this protocol passed analysis.

metadata = {
    'protocolName': 'RTP: Float test',
}

requirements = {
    "robotType": "Flex",
    "apiLevel": "2.18"
}


def add_parameters(parameters):
    parameters.add_float(
        display_name="Volume 1",
        variable_name="volume_1",
        default=20,
        minimum=10,
        maximum=50,
    )
    parameters.add_float(
        display_name="Volume 2",
        variable_name="volume_2",
        default=20.0,
        choices=[
            {"display_name": "Low Volume", "value": 10},
            {"display_name": "Medium Volume", "value": 20},
            {"display_name": "High Volume", "value": 50.0},
        ],
    )


def run(context):
    trash_bin = context.load_trash_bin('A3')
    tip_rack = context.load_labware('opentrons_flex_96_tiprack_50ul', 'D2')
    source = context.load_labware('opentrons_96_wellplate_200ul_pcr_full_skirt', 'C1')
    destination = context.load_labware('opentrons_96_wellplate_200ul_pcr_full_skirt', 'C3')
    pipette = context.load_instrument('flex_1channel_50', mount="left", tip_racks=[tip_rack])

    pipette.pick_up_tip()
    pipette.aspirate(context.params.volume_1, source.wells()[0])
    pipette.dispense(context.params.volume_1, destination.wells()[0])

    pipette.aspirate(context.params.volume_2, source.wells()[0])
    pipette.dispense(context.params.volume_2, destination.wells()[0])
    pipette.drop_tip()

Changelog

  • Allow int literals to be send as parameter override values for float parameters
  • Allow int literals to be used for the default, minimum, maximum and value key of choices for ParameterContext.add_float

Review requests

Risk assessment

Low.

@jbleon95 jbleon95 requested a review from a team as a code owner April 5, 2024 18:46
Copy link

codecov bot commented Apr 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.24%. Comparing base (65885b2) to head (94d7423).
Report is 4 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #14820      +/-   ##
==========================================
- Coverage   67.24%   67.24%   -0.01%     
==========================================
  Files        2495     2495              
  Lines       71254    71250       -4     
  Branches     8937     8937              
==========================================
- Hits        47918    47915       -3     
+ Misses      21235    21234       -1     
  Partials     2101     2101              
Flag Coverage Δ
g-code-testing 92.43% <ø> (ø)

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

Copy link
Member

@sanni-t sanni-t 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!

@jbleon95 jbleon95 merged commit 1175b4f into edge Apr 8, 2024
22 checks passed
@jbleon95 jbleon95 deleted the rtp_more_permissive_floats branch April 8, 2024 14:17
Carlos-fernandez pushed a commit that referenced this pull request May 20, 2024
…at parameters (#14820)

Allow int literals to be used for float parameters in PAPI add_float arguments and robot server endpoints.
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.

2 participants