opentrons 8.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of opentrons might be problematic. Click here for more details.
- opentrons/__init__.py +150 -0
- opentrons/_version.py +34 -0
- opentrons/calibration_storage/__init__.py +54 -0
- opentrons/calibration_storage/deck_configuration.py +62 -0
- opentrons/calibration_storage/encoder_decoder.py +31 -0
- opentrons/calibration_storage/file_operators.py +142 -0
- opentrons/calibration_storage/helpers.py +103 -0
- opentrons/calibration_storage/ot2/__init__.py +34 -0
- opentrons/calibration_storage/ot2/deck_attitude.py +85 -0
- opentrons/calibration_storage/ot2/mark_bad_calibration.py +27 -0
- opentrons/calibration_storage/ot2/models/__init__.py +0 -0
- opentrons/calibration_storage/ot2/models/v1.py +149 -0
- opentrons/calibration_storage/ot2/pipette_offset.py +129 -0
- opentrons/calibration_storage/ot2/tip_length.py +281 -0
- opentrons/calibration_storage/ot3/__init__.py +31 -0
- opentrons/calibration_storage/ot3/deck_attitude.py +83 -0
- opentrons/calibration_storage/ot3/gripper_offset.py +156 -0
- opentrons/calibration_storage/ot3/models/__init__.py +0 -0
- opentrons/calibration_storage/ot3/models/v1.py +122 -0
- opentrons/calibration_storage/ot3/module_offset.py +138 -0
- opentrons/calibration_storage/ot3/pipette_offset.py +95 -0
- opentrons/calibration_storage/types.py +45 -0
- opentrons/cli/__init__.py +21 -0
- opentrons/cli/__main__.py +5 -0
- opentrons/cli/analyze.py +557 -0
- opentrons/config/__init__.py +631 -0
- opentrons/config/advanced_settings.py +871 -0
- opentrons/config/defaults_ot2.py +214 -0
- opentrons/config/defaults_ot3.py +499 -0
- opentrons/config/feature_flags.py +86 -0
- opentrons/config/gripper_config.py +55 -0
- opentrons/config/reset.py +203 -0
- opentrons/config/robot_configs.py +187 -0
- opentrons/config/types.py +183 -0
- opentrons/drivers/__init__.py +0 -0
- opentrons/drivers/absorbance_reader/__init__.py +11 -0
- opentrons/drivers/absorbance_reader/abstract.py +72 -0
- opentrons/drivers/absorbance_reader/async_byonoy.py +352 -0
- opentrons/drivers/absorbance_reader/driver.py +81 -0
- opentrons/drivers/absorbance_reader/hid_protocol.py +161 -0
- opentrons/drivers/absorbance_reader/simulator.py +84 -0
- opentrons/drivers/asyncio/__init__.py +0 -0
- opentrons/drivers/asyncio/communication/__init__.py +22 -0
- opentrons/drivers/asyncio/communication/async_serial.py +187 -0
- opentrons/drivers/asyncio/communication/errors.py +88 -0
- opentrons/drivers/asyncio/communication/serial_connection.py +557 -0
- opentrons/drivers/command_builder.py +102 -0
- opentrons/drivers/flex_stacker/__init__.py +13 -0
- opentrons/drivers/flex_stacker/abstract.py +214 -0
- opentrons/drivers/flex_stacker/driver.py +768 -0
- opentrons/drivers/flex_stacker/errors.py +68 -0
- opentrons/drivers/flex_stacker/simulator.py +309 -0
- opentrons/drivers/flex_stacker/types.py +367 -0
- opentrons/drivers/flex_stacker/utils.py +19 -0
- opentrons/drivers/heater_shaker/__init__.py +5 -0
- opentrons/drivers/heater_shaker/abstract.py +76 -0
- opentrons/drivers/heater_shaker/driver.py +204 -0
- opentrons/drivers/heater_shaker/simulator.py +94 -0
- opentrons/drivers/mag_deck/__init__.py +6 -0
- opentrons/drivers/mag_deck/abstract.py +44 -0
- opentrons/drivers/mag_deck/driver.py +208 -0
- opentrons/drivers/mag_deck/simulator.py +63 -0
- opentrons/drivers/rpi_drivers/__init__.py +33 -0
- opentrons/drivers/rpi_drivers/dev_types.py +94 -0
- opentrons/drivers/rpi_drivers/gpio.py +282 -0
- opentrons/drivers/rpi_drivers/gpio_simulator.py +127 -0
- opentrons/drivers/rpi_drivers/interfaces.py +15 -0
- opentrons/drivers/rpi_drivers/types.py +364 -0
- opentrons/drivers/rpi_drivers/usb.py +102 -0
- opentrons/drivers/rpi_drivers/usb_simulator.py +22 -0
- opentrons/drivers/serial_communication.py +151 -0
- opentrons/drivers/smoothie_drivers/__init__.py +4 -0
- opentrons/drivers/smoothie_drivers/connection.py +51 -0
- opentrons/drivers/smoothie_drivers/constants.py +121 -0
- opentrons/drivers/smoothie_drivers/driver_3_0.py +1933 -0
- opentrons/drivers/smoothie_drivers/errors.py +49 -0
- opentrons/drivers/smoothie_drivers/parse_utils.py +143 -0
- opentrons/drivers/smoothie_drivers/simulator.py +99 -0
- opentrons/drivers/smoothie_drivers/types.py +16 -0
- opentrons/drivers/temp_deck/__init__.py +10 -0
- opentrons/drivers/temp_deck/abstract.py +54 -0
- opentrons/drivers/temp_deck/driver.py +197 -0
- opentrons/drivers/temp_deck/simulator.py +57 -0
- opentrons/drivers/thermocycler/__init__.py +12 -0
- opentrons/drivers/thermocycler/abstract.py +99 -0
- opentrons/drivers/thermocycler/driver.py +395 -0
- opentrons/drivers/thermocycler/simulator.py +126 -0
- opentrons/drivers/types.py +107 -0
- opentrons/drivers/utils.py +222 -0
- opentrons/execute.py +742 -0
- opentrons/hardware_control/__init__.py +65 -0
- opentrons/hardware_control/__main__.py +77 -0
- opentrons/hardware_control/adapters.py +98 -0
- opentrons/hardware_control/api.py +1347 -0
- opentrons/hardware_control/backends/__init__.py +7 -0
- opentrons/hardware_control/backends/controller.py +400 -0
- opentrons/hardware_control/backends/errors.py +9 -0
- opentrons/hardware_control/backends/estop_state.py +164 -0
- opentrons/hardware_control/backends/flex_protocol.py +497 -0
- opentrons/hardware_control/backends/ot3controller.py +1930 -0
- opentrons/hardware_control/backends/ot3simulator.py +900 -0
- opentrons/hardware_control/backends/ot3utils.py +664 -0
- opentrons/hardware_control/backends/simulator.py +442 -0
- opentrons/hardware_control/backends/status_bar_state.py +240 -0
- opentrons/hardware_control/backends/subsystem_manager.py +431 -0
- opentrons/hardware_control/backends/tip_presence_manager.py +173 -0
- opentrons/hardware_control/backends/types.py +14 -0
- opentrons/hardware_control/constants.py +6 -0
- opentrons/hardware_control/dev_types.py +125 -0
- opentrons/hardware_control/emulation/__init__.py +0 -0
- opentrons/hardware_control/emulation/abstract_emulator.py +21 -0
- opentrons/hardware_control/emulation/app.py +56 -0
- opentrons/hardware_control/emulation/connection_handler.py +38 -0
- opentrons/hardware_control/emulation/heater_shaker.py +150 -0
- opentrons/hardware_control/emulation/magdeck.py +60 -0
- opentrons/hardware_control/emulation/module_server/__init__.py +8 -0
- opentrons/hardware_control/emulation/module_server/client.py +78 -0
- opentrons/hardware_control/emulation/module_server/helpers.py +130 -0
- opentrons/hardware_control/emulation/module_server/models.py +31 -0
- opentrons/hardware_control/emulation/module_server/server.py +110 -0
- opentrons/hardware_control/emulation/parser.py +74 -0
- opentrons/hardware_control/emulation/proxy.py +241 -0
- opentrons/hardware_control/emulation/run_emulator.py +68 -0
- opentrons/hardware_control/emulation/scripts/__init__.py +0 -0
- opentrons/hardware_control/emulation/scripts/run_app.py +54 -0
- opentrons/hardware_control/emulation/scripts/run_module_emulator.py +72 -0
- opentrons/hardware_control/emulation/scripts/run_smoothie.py +37 -0
- opentrons/hardware_control/emulation/settings.py +119 -0
- opentrons/hardware_control/emulation/simulations.py +133 -0
- opentrons/hardware_control/emulation/smoothie.py +192 -0
- opentrons/hardware_control/emulation/tempdeck.py +69 -0
- opentrons/hardware_control/emulation/thermocycler.py +128 -0
- opentrons/hardware_control/emulation/types.py +10 -0
- opentrons/hardware_control/emulation/util.py +38 -0
- opentrons/hardware_control/errors.py +43 -0
- opentrons/hardware_control/execution_manager.py +164 -0
- opentrons/hardware_control/instruments/__init__.py +5 -0
- opentrons/hardware_control/instruments/instrument_abc.py +39 -0
- opentrons/hardware_control/instruments/ot2/__init__.py +0 -0
- opentrons/hardware_control/instruments/ot2/instrument_calibration.py +152 -0
- opentrons/hardware_control/instruments/ot2/pipette.py +777 -0
- opentrons/hardware_control/instruments/ot2/pipette_handler.py +995 -0
- opentrons/hardware_control/instruments/ot3/__init__.py +0 -0
- opentrons/hardware_control/instruments/ot3/gripper.py +420 -0
- opentrons/hardware_control/instruments/ot3/gripper_handler.py +173 -0
- opentrons/hardware_control/instruments/ot3/instrument_calibration.py +214 -0
- opentrons/hardware_control/instruments/ot3/pipette.py +858 -0
- opentrons/hardware_control/instruments/ot3/pipette_handler.py +1030 -0
- opentrons/hardware_control/module_control.py +332 -0
- opentrons/hardware_control/modules/__init__.py +69 -0
- opentrons/hardware_control/modules/absorbance_reader.py +373 -0
- opentrons/hardware_control/modules/errors.py +7 -0
- opentrons/hardware_control/modules/flex_stacker.py +948 -0
- opentrons/hardware_control/modules/heater_shaker.py +426 -0
- opentrons/hardware_control/modules/lid_temp_status.py +35 -0
- opentrons/hardware_control/modules/magdeck.py +233 -0
- opentrons/hardware_control/modules/mod_abc.py +245 -0
- opentrons/hardware_control/modules/module_calibration.py +93 -0
- opentrons/hardware_control/modules/plate_temp_status.py +61 -0
- opentrons/hardware_control/modules/tempdeck.py +299 -0
- opentrons/hardware_control/modules/thermocycler.py +731 -0
- opentrons/hardware_control/modules/types.py +417 -0
- opentrons/hardware_control/modules/update.py +255 -0
- opentrons/hardware_control/modules/utils.py +73 -0
- opentrons/hardware_control/motion_utilities.py +318 -0
- opentrons/hardware_control/nozzle_manager.py +422 -0
- opentrons/hardware_control/ot3_calibration.py +1171 -0
- opentrons/hardware_control/ot3api.py +3227 -0
- opentrons/hardware_control/pause_manager.py +31 -0
- opentrons/hardware_control/poller.py +112 -0
- opentrons/hardware_control/protocols/__init__.py +106 -0
- opentrons/hardware_control/protocols/asyncio_configurable.py +11 -0
- opentrons/hardware_control/protocols/calibratable.py +45 -0
- opentrons/hardware_control/protocols/chassis_accessory_manager.py +90 -0
- opentrons/hardware_control/protocols/configurable.py +48 -0
- opentrons/hardware_control/protocols/event_sourcer.py +18 -0
- opentrons/hardware_control/protocols/execution_controllable.py +33 -0
- opentrons/hardware_control/protocols/flex_calibratable.py +96 -0
- opentrons/hardware_control/protocols/flex_instrument_configurer.py +52 -0
- opentrons/hardware_control/protocols/gripper_controller.py +55 -0
- opentrons/hardware_control/protocols/hardware_manager.py +51 -0
- opentrons/hardware_control/protocols/identifiable.py +16 -0
- opentrons/hardware_control/protocols/instrument_configurer.py +206 -0
- opentrons/hardware_control/protocols/liquid_handler.py +266 -0
- opentrons/hardware_control/protocols/module_provider.py +16 -0
- opentrons/hardware_control/protocols/motion_controller.py +243 -0
- opentrons/hardware_control/protocols/position_estimator.py +45 -0
- opentrons/hardware_control/protocols/simulatable.py +10 -0
- opentrons/hardware_control/protocols/stoppable.py +9 -0
- opentrons/hardware_control/protocols/types.py +27 -0
- opentrons/hardware_control/robot_calibration.py +224 -0
- opentrons/hardware_control/scripts/README.md +28 -0
- opentrons/hardware_control/scripts/__init__.py +1 -0
- opentrons/hardware_control/scripts/gripper_control.py +208 -0
- opentrons/hardware_control/scripts/ot3gripper +7 -0
- opentrons/hardware_control/scripts/ot3repl +7 -0
- opentrons/hardware_control/scripts/repl.py +187 -0
- opentrons/hardware_control/scripts/tc_control.py +97 -0
- opentrons/hardware_control/scripts/update_module_fw.py +274 -0
- opentrons/hardware_control/simulator_setup.py +260 -0
- opentrons/hardware_control/thread_manager.py +431 -0
- opentrons/hardware_control/threaded_async_lock.py +97 -0
- opentrons/hardware_control/types.py +792 -0
- opentrons/hardware_control/util.py +234 -0
- opentrons/legacy_broker.py +53 -0
- opentrons/legacy_commands/__init__.py +1 -0
- opentrons/legacy_commands/commands.py +483 -0
- opentrons/legacy_commands/helpers.py +153 -0
- opentrons/legacy_commands/module_commands.py +276 -0
- opentrons/legacy_commands/protocol_commands.py +54 -0
- opentrons/legacy_commands/publisher.py +155 -0
- opentrons/legacy_commands/robot_commands.py +51 -0
- opentrons/legacy_commands/types.py +1186 -0
- opentrons/motion_planning/__init__.py +32 -0
- opentrons/motion_planning/adjacent_slots_getters.py +168 -0
- opentrons/motion_planning/deck_conflict.py +501 -0
- opentrons/motion_planning/errors.py +35 -0
- opentrons/motion_planning/types.py +42 -0
- opentrons/motion_planning/waypoints.py +218 -0
- opentrons/ordered_set.py +138 -0
- opentrons/protocol_api/__init__.py +105 -0
- opentrons/protocol_api/_liquid.py +157 -0
- opentrons/protocol_api/_liquid_properties.py +814 -0
- opentrons/protocol_api/_nozzle_layout.py +31 -0
- opentrons/protocol_api/_parameter_context.py +300 -0
- opentrons/protocol_api/_parameters.py +31 -0
- opentrons/protocol_api/_transfer_liquid_validation.py +108 -0
- opentrons/protocol_api/_types.py +43 -0
- opentrons/protocol_api/config.py +23 -0
- opentrons/protocol_api/core/__init__.py +23 -0
- opentrons/protocol_api/core/common.py +33 -0
- opentrons/protocol_api/core/core_map.py +74 -0
- opentrons/protocol_api/core/engine/__init__.py +22 -0
- opentrons/protocol_api/core/engine/_default_labware_versions.py +179 -0
- opentrons/protocol_api/core/engine/deck_conflict.py +400 -0
- opentrons/protocol_api/core/engine/exceptions.py +19 -0
- opentrons/protocol_api/core/engine/instrument.py +2391 -0
- opentrons/protocol_api/core/engine/labware.py +238 -0
- opentrons/protocol_api/core/engine/load_labware_params.py +73 -0
- opentrons/protocol_api/core/engine/module_core.py +1027 -0
- opentrons/protocol_api/core/engine/overlap_versions.py +20 -0
- opentrons/protocol_api/core/engine/pipette_movement_conflict.py +358 -0
- opentrons/protocol_api/core/engine/point_calculations.py +64 -0
- opentrons/protocol_api/core/engine/protocol.py +1153 -0
- opentrons/protocol_api/core/engine/robot.py +139 -0
- opentrons/protocol_api/core/engine/stringify.py +74 -0
- opentrons/protocol_api/core/engine/transfer_components_executor.py +1006 -0
- opentrons/protocol_api/core/engine/well.py +241 -0
- opentrons/protocol_api/core/instrument.py +459 -0
- opentrons/protocol_api/core/labware.py +151 -0
- opentrons/protocol_api/core/legacy/__init__.py +11 -0
- opentrons/protocol_api/core/legacy/_labware_geometry.py +37 -0
- opentrons/protocol_api/core/legacy/deck.py +369 -0
- opentrons/protocol_api/core/legacy/labware_offset_provider.py +108 -0
- opentrons/protocol_api/core/legacy/legacy_instrument_core.py +709 -0
- opentrons/protocol_api/core/legacy/legacy_labware_core.py +235 -0
- opentrons/protocol_api/core/legacy/legacy_module_core.py +592 -0
- opentrons/protocol_api/core/legacy/legacy_protocol_core.py +612 -0
- opentrons/protocol_api/core/legacy/legacy_well_core.py +162 -0
- opentrons/protocol_api/core/legacy/load_info.py +67 -0
- opentrons/protocol_api/core/legacy/module_geometry.py +547 -0
- opentrons/protocol_api/core/legacy/well_geometry.py +148 -0
- opentrons/protocol_api/core/legacy_simulator/__init__.py +16 -0
- opentrons/protocol_api/core/legacy_simulator/legacy_instrument_core.py +624 -0
- opentrons/protocol_api/core/legacy_simulator/legacy_protocol_core.py +85 -0
- opentrons/protocol_api/core/module.py +484 -0
- opentrons/protocol_api/core/protocol.py +311 -0
- opentrons/protocol_api/core/robot.py +51 -0
- opentrons/protocol_api/core/well.py +116 -0
- opentrons/protocol_api/core/well_grid.py +45 -0
- opentrons/protocol_api/create_protocol_context.py +177 -0
- opentrons/protocol_api/deck.py +223 -0
- opentrons/protocol_api/disposal_locations.py +244 -0
- opentrons/protocol_api/instrument_context.py +3272 -0
- opentrons/protocol_api/labware.py +1579 -0
- opentrons/protocol_api/module_contexts.py +1447 -0
- opentrons/protocol_api/module_validation_and_errors.py +61 -0
- opentrons/protocol_api/protocol_context.py +1688 -0
- opentrons/protocol_api/robot_context.py +303 -0
- opentrons/protocol_api/validation.py +761 -0
- opentrons/protocol_engine/__init__.py +155 -0
- opentrons/protocol_engine/actions/__init__.py +65 -0
- opentrons/protocol_engine/actions/action_dispatcher.py +30 -0
- opentrons/protocol_engine/actions/action_handler.py +13 -0
- opentrons/protocol_engine/actions/actions.py +302 -0
- opentrons/protocol_engine/actions/get_state_update.py +38 -0
- opentrons/protocol_engine/clients/__init__.py +5 -0
- opentrons/protocol_engine/clients/sync_client.py +174 -0
- opentrons/protocol_engine/clients/transports.py +197 -0
- opentrons/protocol_engine/commands/__init__.py +757 -0
- opentrons/protocol_engine/commands/absorbance_reader/__init__.py +61 -0
- opentrons/protocol_engine/commands/absorbance_reader/close_lid.py +154 -0
- opentrons/protocol_engine/commands/absorbance_reader/common.py +6 -0
- opentrons/protocol_engine/commands/absorbance_reader/initialize.py +151 -0
- opentrons/protocol_engine/commands/absorbance_reader/open_lid.py +154 -0
- opentrons/protocol_engine/commands/absorbance_reader/read.py +226 -0
- opentrons/protocol_engine/commands/air_gap_in_place.py +162 -0
- opentrons/protocol_engine/commands/aspirate.py +244 -0
- opentrons/protocol_engine/commands/aspirate_in_place.py +184 -0
- opentrons/protocol_engine/commands/aspirate_while_tracking.py +211 -0
- opentrons/protocol_engine/commands/blow_out.py +146 -0
- opentrons/protocol_engine/commands/blow_out_in_place.py +119 -0
- opentrons/protocol_engine/commands/calibration/__init__.py +60 -0
- opentrons/protocol_engine/commands/calibration/calibrate_gripper.py +166 -0
- opentrons/protocol_engine/commands/calibration/calibrate_module.py +117 -0
- opentrons/protocol_engine/commands/calibration/calibrate_pipette.py +96 -0
- opentrons/protocol_engine/commands/calibration/move_to_maintenance_position.py +156 -0
- opentrons/protocol_engine/commands/command.py +308 -0
- opentrons/protocol_engine/commands/command_unions.py +974 -0
- opentrons/protocol_engine/commands/comment.py +57 -0
- opentrons/protocol_engine/commands/configure_for_volume.py +108 -0
- opentrons/protocol_engine/commands/configure_nozzle_layout.py +115 -0
- opentrons/protocol_engine/commands/custom.py +67 -0
- opentrons/protocol_engine/commands/dispense.py +194 -0
- opentrons/protocol_engine/commands/dispense_in_place.py +179 -0
- opentrons/protocol_engine/commands/dispense_while_tracking.py +204 -0
- opentrons/protocol_engine/commands/drop_tip.py +232 -0
- opentrons/protocol_engine/commands/drop_tip_in_place.py +205 -0
- opentrons/protocol_engine/commands/flex_stacker/__init__.py +64 -0
- opentrons/protocol_engine/commands/flex_stacker/common.py +900 -0
- opentrons/protocol_engine/commands/flex_stacker/empty.py +293 -0
- opentrons/protocol_engine/commands/flex_stacker/fill.py +281 -0
- opentrons/protocol_engine/commands/flex_stacker/retrieve.py +339 -0
- opentrons/protocol_engine/commands/flex_stacker/set_stored_labware.py +328 -0
- opentrons/protocol_engine/commands/flex_stacker/store.py +339 -0
- opentrons/protocol_engine/commands/generate_command_schema.py +61 -0
- opentrons/protocol_engine/commands/get_next_tip.py +134 -0
- opentrons/protocol_engine/commands/get_tip_presence.py +87 -0
- opentrons/protocol_engine/commands/hash_command_params.py +38 -0
- opentrons/protocol_engine/commands/heater_shaker/__init__.py +102 -0
- opentrons/protocol_engine/commands/heater_shaker/close_labware_latch.py +83 -0
- opentrons/protocol_engine/commands/heater_shaker/deactivate_heater.py +82 -0
- opentrons/protocol_engine/commands/heater_shaker/deactivate_shaker.py +84 -0
- opentrons/protocol_engine/commands/heater_shaker/open_labware_latch.py +110 -0
- opentrons/protocol_engine/commands/heater_shaker/set_and_wait_for_shake_speed.py +125 -0
- opentrons/protocol_engine/commands/heater_shaker/set_target_temperature.py +90 -0
- opentrons/protocol_engine/commands/heater_shaker/wait_for_temperature.py +102 -0
- opentrons/protocol_engine/commands/home.py +100 -0
- opentrons/protocol_engine/commands/identify_module.py +86 -0
- opentrons/protocol_engine/commands/labware_handling_common.py +29 -0
- opentrons/protocol_engine/commands/liquid_probe.py +464 -0
- opentrons/protocol_engine/commands/load_labware.py +210 -0
- opentrons/protocol_engine/commands/load_lid.py +154 -0
- opentrons/protocol_engine/commands/load_lid_stack.py +272 -0
- opentrons/protocol_engine/commands/load_liquid.py +95 -0
- opentrons/protocol_engine/commands/load_liquid_class.py +144 -0
- opentrons/protocol_engine/commands/load_module.py +223 -0
- opentrons/protocol_engine/commands/load_pipette.py +167 -0
- opentrons/protocol_engine/commands/magnetic_module/__init__.py +32 -0
- opentrons/protocol_engine/commands/magnetic_module/disengage.py +97 -0
- opentrons/protocol_engine/commands/magnetic_module/engage.py +119 -0
- opentrons/protocol_engine/commands/move_labware.py +546 -0
- opentrons/protocol_engine/commands/move_relative.py +102 -0
- opentrons/protocol_engine/commands/move_to_addressable_area.py +176 -0
- opentrons/protocol_engine/commands/move_to_addressable_area_for_drop_tip.py +198 -0
- opentrons/protocol_engine/commands/move_to_coordinates.py +107 -0
- opentrons/protocol_engine/commands/move_to_well.py +119 -0
- opentrons/protocol_engine/commands/movement_common.py +338 -0
- opentrons/protocol_engine/commands/pick_up_tip.py +241 -0
- opentrons/protocol_engine/commands/pipetting_common.py +443 -0
- opentrons/protocol_engine/commands/prepare_to_aspirate.py +121 -0
- opentrons/protocol_engine/commands/pressure_dispense.py +155 -0
- opentrons/protocol_engine/commands/reload_labware.py +90 -0
- opentrons/protocol_engine/commands/retract_axis.py +75 -0
- opentrons/protocol_engine/commands/robot/__init__.py +70 -0
- opentrons/protocol_engine/commands/robot/close_gripper_jaw.py +96 -0
- opentrons/protocol_engine/commands/robot/common.py +18 -0
- opentrons/protocol_engine/commands/robot/move_axes_relative.py +101 -0
- opentrons/protocol_engine/commands/robot/move_axes_to.py +100 -0
- opentrons/protocol_engine/commands/robot/move_to.py +94 -0
- opentrons/protocol_engine/commands/robot/open_gripper_jaw.py +86 -0
- opentrons/protocol_engine/commands/save_position.py +109 -0
- opentrons/protocol_engine/commands/seal_pipette_to_tip.py +353 -0
- opentrons/protocol_engine/commands/set_rail_lights.py +67 -0
- opentrons/protocol_engine/commands/set_status_bar.py +89 -0
- opentrons/protocol_engine/commands/temperature_module/__init__.py +46 -0
- opentrons/protocol_engine/commands/temperature_module/deactivate.py +86 -0
- opentrons/protocol_engine/commands/temperature_module/set_target_temperature.py +97 -0
- opentrons/protocol_engine/commands/temperature_module/wait_for_temperature.py +104 -0
- opentrons/protocol_engine/commands/thermocycler/__init__.py +152 -0
- opentrons/protocol_engine/commands/thermocycler/close_lid.py +87 -0
- opentrons/protocol_engine/commands/thermocycler/deactivate_block.py +80 -0
- opentrons/protocol_engine/commands/thermocycler/deactivate_lid.py +80 -0
- opentrons/protocol_engine/commands/thermocycler/open_lid.py +87 -0
- opentrons/protocol_engine/commands/thermocycler/run_extended_profile.py +171 -0
- opentrons/protocol_engine/commands/thermocycler/run_profile.py +124 -0
- opentrons/protocol_engine/commands/thermocycler/set_target_block_temperature.py +140 -0
- opentrons/protocol_engine/commands/thermocycler/set_target_lid_temperature.py +100 -0
- opentrons/protocol_engine/commands/thermocycler/wait_for_block_temperature.py +93 -0
- opentrons/protocol_engine/commands/thermocycler/wait_for_lid_temperature.py +89 -0
- opentrons/protocol_engine/commands/touch_tip.py +189 -0
- opentrons/protocol_engine/commands/unsafe/__init__.py +161 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_blow_out_in_place.py +100 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_drop_tip_in_place.py +121 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_engage_axes.py +82 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_place_labware.py +208 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_stacker_close_latch.py +94 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_stacker_manual_retrieve.py +295 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_stacker_open_latch.py +91 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_stacker_prepare_shuttle.py +136 -0
- opentrons/protocol_engine/commands/unsafe/unsafe_ungrip_labware.py +77 -0
- opentrons/protocol_engine/commands/unsafe/update_position_estimators.py +90 -0
- opentrons/protocol_engine/commands/unseal_pipette_from_tip.py +153 -0
- opentrons/protocol_engine/commands/verify_tip_presence.py +100 -0
- opentrons/protocol_engine/commands/wait_for_duration.py +76 -0
- opentrons/protocol_engine/commands/wait_for_resume.py +75 -0
- opentrons/protocol_engine/create_protocol_engine.py +193 -0
- opentrons/protocol_engine/engine_support.py +28 -0
- opentrons/protocol_engine/error_recovery_policy.py +81 -0
- opentrons/protocol_engine/errors/__init__.py +191 -0
- opentrons/protocol_engine/errors/error_occurrence.py +182 -0
- opentrons/protocol_engine/errors/exceptions.py +1308 -0
- opentrons/protocol_engine/execution/__init__.py +50 -0
- opentrons/protocol_engine/execution/command_executor.py +216 -0
- opentrons/protocol_engine/execution/create_queue_worker.py +102 -0
- opentrons/protocol_engine/execution/door_watcher.py +119 -0
- opentrons/protocol_engine/execution/equipment.py +819 -0
- opentrons/protocol_engine/execution/error_recovery_hardware_state_synchronizer.py +101 -0
- opentrons/protocol_engine/execution/gantry_mover.py +686 -0
- opentrons/protocol_engine/execution/hardware_stopper.py +147 -0
- opentrons/protocol_engine/execution/heater_shaker_movement_flagger.py +207 -0
- opentrons/protocol_engine/execution/labware_movement.py +297 -0
- opentrons/protocol_engine/execution/movement.py +350 -0
- opentrons/protocol_engine/execution/pipetting.py +607 -0
- opentrons/protocol_engine/execution/queue_worker.py +86 -0
- opentrons/protocol_engine/execution/rail_lights.py +25 -0
- opentrons/protocol_engine/execution/run_control.py +33 -0
- opentrons/protocol_engine/execution/status_bar.py +34 -0
- opentrons/protocol_engine/execution/thermocycler_movement_flagger.py +188 -0
- opentrons/protocol_engine/execution/thermocycler_plate_lifter.py +81 -0
- opentrons/protocol_engine/execution/tip_handler.py +550 -0
- opentrons/protocol_engine/labware_offset_standardization.py +194 -0
- opentrons/protocol_engine/notes/__init__.py +17 -0
- opentrons/protocol_engine/notes/notes.py +59 -0
- opentrons/protocol_engine/plugins.py +104 -0
- opentrons/protocol_engine/protocol_engine.py +683 -0
- opentrons/protocol_engine/resources/__init__.py +26 -0
- opentrons/protocol_engine/resources/deck_configuration_provider.py +232 -0
- opentrons/protocol_engine/resources/deck_data_provider.py +94 -0
- opentrons/protocol_engine/resources/file_provider.py +161 -0
- opentrons/protocol_engine/resources/fixture_validation.py +68 -0
- opentrons/protocol_engine/resources/labware_data_provider.py +106 -0
- opentrons/protocol_engine/resources/labware_validation.py +73 -0
- opentrons/protocol_engine/resources/model_utils.py +32 -0
- opentrons/protocol_engine/resources/module_data_provider.py +44 -0
- opentrons/protocol_engine/resources/ot3_validation.py +21 -0
- opentrons/protocol_engine/resources/pipette_data_provider.py +379 -0
- opentrons/protocol_engine/slot_standardization.py +128 -0
- opentrons/protocol_engine/state/__init__.py +1 -0
- opentrons/protocol_engine/state/_abstract_store.py +27 -0
- opentrons/protocol_engine/state/_axis_aligned_bounding_box.py +50 -0
- opentrons/protocol_engine/state/_labware_origin_math.py +636 -0
- opentrons/protocol_engine/state/_move_types.py +83 -0
- opentrons/protocol_engine/state/_well_math.py +193 -0
- opentrons/protocol_engine/state/addressable_areas.py +699 -0
- opentrons/protocol_engine/state/command_history.py +309 -0
- opentrons/protocol_engine/state/commands.py +1164 -0
- opentrons/protocol_engine/state/config.py +39 -0
- opentrons/protocol_engine/state/files.py +57 -0
- opentrons/protocol_engine/state/fluid_stack.py +138 -0
- opentrons/protocol_engine/state/geometry.py +2408 -0
- opentrons/protocol_engine/state/inner_well_math_utils.py +548 -0
- opentrons/protocol_engine/state/labware.py +1432 -0
- opentrons/protocol_engine/state/liquid_classes.py +82 -0
- opentrons/protocol_engine/state/liquids.py +73 -0
- opentrons/protocol_engine/state/module_substates/__init__.py +45 -0
- opentrons/protocol_engine/state/module_substates/absorbance_reader_substate.py +35 -0
- opentrons/protocol_engine/state/module_substates/flex_stacker_substate.py +112 -0
- opentrons/protocol_engine/state/module_substates/heater_shaker_module_substate.py +115 -0
- opentrons/protocol_engine/state/module_substates/magnetic_block_substate.py +17 -0
- opentrons/protocol_engine/state/module_substates/magnetic_module_substate.py +65 -0
- opentrons/protocol_engine/state/module_substates/temperature_module_substate.py +67 -0
- opentrons/protocol_engine/state/module_substates/thermocycler_module_substate.py +163 -0
- opentrons/protocol_engine/state/modules.py +1515 -0
- opentrons/protocol_engine/state/motion.py +373 -0
- opentrons/protocol_engine/state/pipettes.py +905 -0
- opentrons/protocol_engine/state/state.py +421 -0
- opentrons/protocol_engine/state/state_summary.py +36 -0
- opentrons/protocol_engine/state/tips.py +420 -0
- opentrons/protocol_engine/state/update_types.py +904 -0
- opentrons/protocol_engine/state/wells.py +290 -0
- opentrons/protocol_engine/types/__init__.py +310 -0
- opentrons/protocol_engine/types/automatic_tip_selection.py +39 -0
- opentrons/protocol_engine/types/command_annotations.py +53 -0
- opentrons/protocol_engine/types/deck_configuration.py +81 -0
- opentrons/protocol_engine/types/execution.py +96 -0
- opentrons/protocol_engine/types/hardware_passthrough.py +25 -0
- opentrons/protocol_engine/types/instrument.py +47 -0
- opentrons/protocol_engine/types/instrument_sensors.py +47 -0
- opentrons/protocol_engine/types/labware.py +131 -0
- opentrons/protocol_engine/types/labware_movement.py +22 -0
- opentrons/protocol_engine/types/labware_offset_location.py +111 -0
- opentrons/protocol_engine/types/labware_offset_vector.py +16 -0
- opentrons/protocol_engine/types/liquid.py +40 -0
- opentrons/protocol_engine/types/liquid_class.py +59 -0
- opentrons/protocol_engine/types/liquid_handling.py +13 -0
- opentrons/protocol_engine/types/liquid_level_detection.py +191 -0
- opentrons/protocol_engine/types/location.py +194 -0
- opentrons/protocol_engine/types/module.py +310 -0
- opentrons/protocol_engine/types/partial_tip_configuration.py +76 -0
- opentrons/protocol_engine/types/run_time_parameters.py +133 -0
- opentrons/protocol_engine/types/tip.py +18 -0
- opentrons/protocol_engine/types/util.py +21 -0
- opentrons/protocol_engine/types/well_position.py +124 -0
- opentrons/protocol_reader/__init__.py +37 -0
- opentrons/protocol_reader/extract_labware_definitions.py +66 -0
- opentrons/protocol_reader/file_format_validator.py +152 -0
- opentrons/protocol_reader/file_hasher.py +27 -0
- opentrons/protocol_reader/file_identifier.py +284 -0
- opentrons/protocol_reader/file_reader_writer.py +90 -0
- opentrons/protocol_reader/input_file.py +16 -0
- opentrons/protocol_reader/protocol_files_invalid_error.py +6 -0
- opentrons/protocol_reader/protocol_reader.py +188 -0
- opentrons/protocol_reader/protocol_source.py +124 -0
- opentrons/protocol_reader/role_analyzer.py +86 -0
- opentrons/protocol_runner/__init__.py +26 -0
- opentrons/protocol_runner/create_simulating_orchestrator.py +118 -0
- opentrons/protocol_runner/json_file_reader.py +55 -0
- opentrons/protocol_runner/json_translator.py +314 -0
- opentrons/protocol_runner/legacy_command_mapper.py +852 -0
- opentrons/protocol_runner/legacy_context_plugin.py +116 -0
- opentrons/protocol_runner/protocol_runner.py +530 -0
- opentrons/protocol_runner/python_protocol_wrappers.py +179 -0
- opentrons/protocol_runner/run_orchestrator.py +496 -0
- opentrons/protocol_runner/task_queue.py +95 -0
- opentrons/protocols/__init__.py +6 -0
- opentrons/protocols/advanced_control/__init__.py +0 -0
- opentrons/protocols/advanced_control/common.py +38 -0
- opentrons/protocols/advanced_control/mix.py +60 -0
- opentrons/protocols/advanced_control/transfers/__init__.py +0 -0
- opentrons/protocols/advanced_control/transfers/common.py +180 -0
- opentrons/protocols/advanced_control/transfers/transfer.py +972 -0
- opentrons/protocols/advanced_control/transfers/transfer_liquid_utils.py +231 -0
- opentrons/protocols/api_support/__init__.py +0 -0
- opentrons/protocols/api_support/constants.py +8 -0
- opentrons/protocols/api_support/deck_type.py +110 -0
- opentrons/protocols/api_support/definitions.py +18 -0
- opentrons/protocols/api_support/instrument.py +151 -0
- opentrons/protocols/api_support/labware_like.py +233 -0
- opentrons/protocols/api_support/tip_tracker.py +175 -0
- opentrons/protocols/api_support/types.py +32 -0
- opentrons/protocols/api_support/util.py +403 -0
- opentrons/protocols/bundle.py +89 -0
- opentrons/protocols/duration/__init__.py +4 -0
- opentrons/protocols/duration/errors.py +5 -0
- opentrons/protocols/duration/estimator.py +628 -0
- opentrons/protocols/execution/__init__.py +0 -0
- opentrons/protocols/execution/dev_types.py +181 -0
- opentrons/protocols/execution/errors.py +40 -0
- opentrons/protocols/execution/execute.py +84 -0
- opentrons/protocols/execution/execute_json_v3.py +275 -0
- opentrons/protocols/execution/execute_json_v4.py +359 -0
- opentrons/protocols/execution/execute_json_v5.py +28 -0
- opentrons/protocols/execution/execute_python.py +169 -0
- opentrons/protocols/execution/json_dispatchers.py +87 -0
- opentrons/protocols/execution/types.py +7 -0
- opentrons/protocols/geometry/__init__.py +0 -0
- opentrons/protocols/geometry/planning.py +297 -0
- opentrons/protocols/labware.py +312 -0
- opentrons/protocols/models/__init__.py +0 -0
- opentrons/protocols/models/json_protocol.py +679 -0
- opentrons/protocols/parameters/__init__.py +0 -0
- opentrons/protocols/parameters/csv_parameter_definition.py +77 -0
- opentrons/protocols/parameters/csv_parameter_interface.py +96 -0
- opentrons/protocols/parameters/exceptions.py +34 -0
- opentrons/protocols/parameters/parameter_definition.py +272 -0
- opentrons/protocols/parameters/types.py +17 -0
- opentrons/protocols/parameters/validation.py +267 -0
- opentrons/protocols/parse.py +671 -0
- opentrons/protocols/types.py +159 -0
- opentrons/py.typed +0 -0
- opentrons/resources/scripts/lpc21isp +0 -0
- opentrons/resources/smoothie-edge-8414642.hex +23010 -0
- opentrons/simulate.py +1065 -0
- opentrons/system/__init__.py +6 -0
- opentrons/system/camera.py +51 -0
- opentrons/system/log_control.py +59 -0
- opentrons/system/nmcli.py +856 -0
- opentrons/system/resin.py +24 -0
- opentrons/system/smoothie_update.py +15 -0
- opentrons/system/wifi.py +204 -0
- opentrons/tools/__init__.py +0 -0
- opentrons/tools/args_handler.py +22 -0
- opentrons/tools/write_pipette_memory.py +157 -0
- opentrons/types.py +618 -0
- opentrons/util/__init__.py +1 -0
- opentrons/util/async_helpers.py +166 -0
- opentrons/util/broker.py +84 -0
- opentrons/util/change_notifier.py +47 -0
- opentrons/util/entrypoint_util.py +278 -0
- opentrons/util/get_union_elements.py +26 -0
- opentrons/util/helpers.py +6 -0
- opentrons/util/linal.py +178 -0
- opentrons/util/logging_config.py +265 -0
- opentrons/util/logging_queue_handler.py +61 -0
- opentrons/util/performance_helpers.py +157 -0
- opentrons-8.6.0.dist-info/METADATA +37 -0
- opentrons-8.6.0.dist-info/RECORD +601 -0
- opentrons-8.6.0.dist-info/WHEEL +4 -0
- opentrons-8.6.0.dist-info/entry_points.txt +3 -0
- opentrons-8.6.0.dist-info/licenses/LICENSE +202 -0
opentrons/simulate.py
ADDED
|
@@ -0,0 +1,1065 @@
|
|
|
1
|
+
""" opentrons.simulate: functions and entrypoints for simulating protocols
|
|
2
|
+
|
|
3
|
+
This module has functions that provide a console entrypoint for simulating
|
|
4
|
+
a protocol from the command line.
|
|
5
|
+
"""
|
|
6
|
+
import argparse
|
|
7
|
+
import asyncio
|
|
8
|
+
import atexit
|
|
9
|
+
from contextlib import ExitStack, contextmanager
|
|
10
|
+
import sys
|
|
11
|
+
import logging
|
|
12
|
+
import os
|
|
13
|
+
import pathlib
|
|
14
|
+
import queue
|
|
15
|
+
from typing import (
|
|
16
|
+
TYPE_CHECKING,
|
|
17
|
+
Generator,
|
|
18
|
+
Any,
|
|
19
|
+
Dict,
|
|
20
|
+
List,
|
|
21
|
+
Mapping,
|
|
22
|
+
TextIO,
|
|
23
|
+
Tuple,
|
|
24
|
+
BinaryIO,
|
|
25
|
+
Optional,
|
|
26
|
+
Union,
|
|
27
|
+
)
|
|
28
|
+
from typing_extensions import Literal
|
|
29
|
+
|
|
30
|
+
from opentrons_shared_data.robot.types import RobotType
|
|
31
|
+
|
|
32
|
+
import opentrons
|
|
33
|
+
from opentrons import should_use_ot3
|
|
34
|
+
from opentrons.hardware_control import (
|
|
35
|
+
API as OT2API,
|
|
36
|
+
ThreadManager,
|
|
37
|
+
ThreadManagedHardware,
|
|
38
|
+
)
|
|
39
|
+
from opentrons.hardware_control.types import HardwareFeatureFlags
|
|
40
|
+
|
|
41
|
+
from opentrons.hardware_control.simulator_setup import load_simulator
|
|
42
|
+
from opentrons.protocol_api.core.engine import ENGINE_CORE_API_VERSION
|
|
43
|
+
from opentrons.protocol_api.protocol_context import ProtocolContext
|
|
44
|
+
from opentrons.protocol_engine.create_protocol_engine import (
|
|
45
|
+
create_protocol_engine_in_thread,
|
|
46
|
+
create_protocol_engine,
|
|
47
|
+
)
|
|
48
|
+
from opentrons.protocol_engine import error_recovery_policy
|
|
49
|
+
from opentrons.protocol_engine.state.config import Config
|
|
50
|
+
from opentrons.protocol_engine.types import DeckType, EngineStatus, PostRunHardwareState
|
|
51
|
+
from opentrons.protocol_reader.protocol_source import ProtocolSource
|
|
52
|
+
from opentrons.protocol_runner.protocol_runner import create_protocol_runner, LiveRunner
|
|
53
|
+
from opentrons.protocol_runner import RunOrchestrator
|
|
54
|
+
from opentrons.protocols.duration import DurationEstimator
|
|
55
|
+
from opentrons.protocols.execution import execute
|
|
56
|
+
from opentrons.legacy_broker import LegacyBroker
|
|
57
|
+
from opentrons.config import IS_ROBOT
|
|
58
|
+
from opentrons import protocol_api
|
|
59
|
+
from opentrons.legacy_commands import types as command_types
|
|
60
|
+
|
|
61
|
+
from opentrons.protocols import parse, bundle
|
|
62
|
+
from opentrons.protocols.types import (
|
|
63
|
+
ApiDeprecationError,
|
|
64
|
+
Protocol,
|
|
65
|
+
PythonProtocol,
|
|
66
|
+
BundleContents,
|
|
67
|
+
)
|
|
68
|
+
from opentrons.protocols.api_support.deck_type import (
|
|
69
|
+
for_simulation as deck_type_for_simulation,
|
|
70
|
+
should_load_fixed_trash,
|
|
71
|
+
should_load_fixed_trash_labware_for_python_protocol,
|
|
72
|
+
)
|
|
73
|
+
from opentrons.protocols.api_support.types import APIVersion
|
|
74
|
+
from opentrons_shared_data.labware.labware_definition import (
|
|
75
|
+
labware_definition_type_adapter,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
from .util import entrypoint_util
|
|
79
|
+
|
|
80
|
+
if TYPE_CHECKING:
|
|
81
|
+
from opentrons_shared_data.labware.types import (
|
|
82
|
+
LabwareDefinition as LabwareDefinitionDict,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# See Jira RCORE-535.
|
|
87
|
+
_JSON_TOO_NEW_MESSAGE = (
|
|
88
|
+
"Protocols created by recent versions of Protocol Designer"
|
|
89
|
+
" cannot currently be simulated with"
|
|
90
|
+
" the opentrons_simulate command-line tool"
|
|
91
|
+
" or the opentrons.simulate.simulate() function."
|
|
92
|
+
" Use the Opentrons App instead."
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# When a ProtocolContext is using a ProtocolEngine to control the robot,
|
|
97
|
+
# it requires some long-lived resources. There's a background thread,
|
|
98
|
+
# an asyncio event loop in that thread, and some ProtocolEngine-controlled background tasks in that
|
|
99
|
+
# event loop.
|
|
100
|
+
#
|
|
101
|
+
# When we're executing a protocol file beginning-to-end, we can clean up those resources after it
|
|
102
|
+
# completes. However, when someone gets a live ProtocolContext through get_protocol_api(), we have
|
|
103
|
+
# no way of knowing when they're done with it. So, as a hack, we keep these resources open
|
|
104
|
+
# indefinitely, letting them leak.
|
|
105
|
+
#
|
|
106
|
+
# We keep this at module scope so that the contained context managers aren't garbage-collected.
|
|
107
|
+
# If they're garbage collected, they can close their resources prematurely.
|
|
108
|
+
# https://stackoverflow.com/a/69155026/497934
|
|
109
|
+
_LIVE_PROTOCOL_ENGINE_CONTEXTS = ExitStack()
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# TODO(mm, 2023-10-05): Deduplicate this with opentrons.protocols.parse().
|
|
113
|
+
_UserSpecifiedRobotType = Literal["OT-2", "Flex"]
|
|
114
|
+
"""The user-facing robot type specifier.
|
|
115
|
+
|
|
116
|
+
This should match what `opentrons.protocols.parse()` accepts in a protocol's `requirements` dict.
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# TODO(mm, 2023-10-05): Type _SimulateResultRunLog more precisely by using TypedDicts from
|
|
121
|
+
# opentrons.legacy_commands.
|
|
122
|
+
_SimulateResultRunLog = List[Mapping[str, Any]]
|
|
123
|
+
_SimulateResult = Tuple[_SimulateResultRunLog, Optional[BundleContents]]
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class _AccumulatingHandler(logging.Handler):
|
|
127
|
+
def __init__(
|
|
128
|
+
self,
|
|
129
|
+
level: str,
|
|
130
|
+
command_queue: "queue.Queue[object]",
|
|
131
|
+
) -> None:
|
|
132
|
+
"""Create the handler
|
|
133
|
+
|
|
134
|
+
:param level: The logging level to capture
|
|
135
|
+
:param command_queue: The queue.Queue to use for messages
|
|
136
|
+
"""
|
|
137
|
+
self._command_queue = command_queue
|
|
138
|
+
super().__init__(level)
|
|
139
|
+
|
|
140
|
+
def emit(self, record: object) -> None:
|
|
141
|
+
self._command_queue.put(record)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class _CommandScraper:
|
|
145
|
+
def __init__(
|
|
146
|
+
self, logger: logging.Logger, level: str, broker: LegacyBroker
|
|
147
|
+
) -> None:
|
|
148
|
+
"""An object that handles scraping the broker for commands and integrating log messages
|
|
149
|
+
with them.
|
|
150
|
+
|
|
151
|
+
Params:
|
|
152
|
+
logger: The logger to integrate messages from, e.g. ``logging.getLogger("opentrons")``.
|
|
153
|
+
level: The log level to scrape.
|
|
154
|
+
broker: The broker to subscribe to for commands.
|
|
155
|
+
"""
|
|
156
|
+
self._logger = logger
|
|
157
|
+
self._level = level
|
|
158
|
+
self._broker = broker
|
|
159
|
+
self._commands: _SimulateResultRunLog = []
|
|
160
|
+
|
|
161
|
+
@property
|
|
162
|
+
def commands(self) -> _SimulateResultRunLog:
|
|
163
|
+
"""The list of commands scraped while `.scrape()` was open, integrated with log messages.
|
|
164
|
+
|
|
165
|
+
See :py:obj:`simulate` for the return type.
|
|
166
|
+
"""
|
|
167
|
+
return self._commands
|
|
168
|
+
|
|
169
|
+
@contextmanager
|
|
170
|
+
def scrape(self) -> Generator[None, None, None]:
|
|
171
|
+
"""While this context manager is open, scrape the broker for commands and integrate log
|
|
172
|
+
messages with them. The accumulated commands will be accessible through `.commands`.
|
|
173
|
+
"""
|
|
174
|
+
log_queue: "queue.Queue[object]" = queue.Queue()
|
|
175
|
+
|
|
176
|
+
depth = 0
|
|
177
|
+
|
|
178
|
+
def handle_command(message: command_types.CommandMessage) -> None:
|
|
179
|
+
"""The callback that we will subscribe to the broker."""
|
|
180
|
+
nonlocal depth
|
|
181
|
+
payload = message["payload"]
|
|
182
|
+
if message["$"] == "before":
|
|
183
|
+
self._commands.append({"level": depth, "payload": payload, "logs": []})
|
|
184
|
+
depth += 1
|
|
185
|
+
else:
|
|
186
|
+
while not log_queue.empty():
|
|
187
|
+
self._commands[-1]["logs"].append(log_queue.get())
|
|
188
|
+
depth = max(depth - 1, 0)
|
|
189
|
+
|
|
190
|
+
if self._level != "none":
|
|
191
|
+
# The simulation entry points probably leave logging unconfigured, so the level will be
|
|
192
|
+
# Python's default. Set it to what the user asked to make sure we see the expected
|
|
193
|
+
# records.
|
|
194
|
+
#
|
|
195
|
+
# TODO(mm, 2023-10-03): This is a bit too intrusive for something whose job is just to
|
|
196
|
+
# "scrape." The entry point function should be responsible for setting the underlying
|
|
197
|
+
# logger's level. Also, we should probably restore the original level when we're done.
|
|
198
|
+
level = getattr(logging, self._level.upper(), logging.WARNING)
|
|
199
|
+
self._logger.setLevel(level)
|
|
200
|
+
|
|
201
|
+
log_handler: Optional[_AccumulatingHandler] = _AccumulatingHandler(
|
|
202
|
+
self._level.upper(), log_queue
|
|
203
|
+
)
|
|
204
|
+
else:
|
|
205
|
+
log_handler = None
|
|
206
|
+
|
|
207
|
+
with ExitStack() as exit_stack:
|
|
208
|
+
if log_handler is not None:
|
|
209
|
+
self._logger.addHandler(log_handler)
|
|
210
|
+
exit_stack.callback(self._logger.removeHandler, log_handler)
|
|
211
|
+
|
|
212
|
+
unsubscribe_from_broker = self._broker.subscribe(
|
|
213
|
+
command_types.COMMAND, handle_command
|
|
214
|
+
)
|
|
215
|
+
exit_stack.callback(unsubscribe_from_broker)
|
|
216
|
+
|
|
217
|
+
yield
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def get_protocol_api(
|
|
221
|
+
version: Union[str, APIVersion],
|
|
222
|
+
bundled_labware: Optional[Dict[str, "LabwareDefinitionDict"]] = None,
|
|
223
|
+
bundled_data: Optional[Dict[str, bytes]] = None,
|
|
224
|
+
extra_labware: Optional[Dict[str, "LabwareDefinitionDict"]] = None,
|
|
225
|
+
hardware_simulator: Optional[ThreadManagedHardware] = None,
|
|
226
|
+
# Additional arguments are kw-only to make mistakes harder in environments without
|
|
227
|
+
# type checking, like Jupyter Notebook.
|
|
228
|
+
*,
|
|
229
|
+
robot_type: Optional[_UserSpecifiedRobotType] = None,
|
|
230
|
+
use_virtual_hardware: bool = True,
|
|
231
|
+
) -> protocol_api.ProtocolContext:
|
|
232
|
+
"""
|
|
233
|
+
Build and return a ``protocol_api.ProtocolContext`` that simulates robot control.
|
|
234
|
+
|
|
235
|
+
This can be used to simulate protocols from interactive Python sessions
|
|
236
|
+
such as Jupyter or an interpreter on the command line:
|
|
237
|
+
|
|
238
|
+
.. code-block:: python
|
|
239
|
+
|
|
240
|
+
>>> from opentrons.simulate import get_protocol_api
|
|
241
|
+
>>> protocol = get_protocol_api('2.0')
|
|
242
|
+
>>> instr = protocol.load_instrument('p300_single', 'right')
|
|
243
|
+
>>> instr.home()
|
|
244
|
+
|
|
245
|
+
:param version: The API version to use. This must be lower than
|
|
246
|
+
``opentrons.protocol_api.MAX_SUPPORTED_VERSION``.
|
|
247
|
+
It may be specified either as a string (``'2.0'``) or
|
|
248
|
+
as a ``protocols.types.APIVersion``
|
|
249
|
+
(``APIVersion(2, 0)``).
|
|
250
|
+
:param bundled_labware: If specified, a mapping from labware names to
|
|
251
|
+
labware definitions for labware to consider in the
|
|
252
|
+
protocol. Note that if you specify this, *only*
|
|
253
|
+
labware in this argument will be allowed in the
|
|
254
|
+
protocol. This is preparation for a beta feature
|
|
255
|
+
and is best not used.
|
|
256
|
+
:param bundled_data: If specified, a mapping from filenames to contents
|
|
257
|
+
for data to be available in the protocol from
|
|
258
|
+
:py:obj:`opentrons.protocol_api.ProtocolContext.bundled_data`.
|
|
259
|
+
:param extra_labware: A mapping from labware load names to custom labware definitions.
|
|
260
|
+
If this is ``None`` (the default), and this function is called on a robot,
|
|
261
|
+
it will look for labware in the ``labware`` subdirectory of the Jupyter
|
|
262
|
+
data directory.
|
|
263
|
+
:param hardware_simulator: This is only for internal use by Opentrons. If specified,
|
|
264
|
+
it's a hardware simulator instance to reuse instead of creating a fresh one.
|
|
265
|
+
:param robot_type: The type of robot to simulate: either ``"Flex"`` or ``"OT-2"``.
|
|
266
|
+
If you're running this function on a robot, the default is the type of that
|
|
267
|
+
robot. Otherwise, the default is ``"OT-2"``, for backwards compatibility.
|
|
268
|
+
:param use_virtual_hardware: This is only for internal use by Opentrons.
|
|
269
|
+
If ``True``, use the Protocol Engine's virtual hardware. If ``False``, use the
|
|
270
|
+
lower level hardware simulator.
|
|
271
|
+
:return: The protocol context.
|
|
272
|
+
"""
|
|
273
|
+
if isinstance(version, str):
|
|
274
|
+
checked_version = parse.version_from_string(version)
|
|
275
|
+
elif not isinstance(version, APIVersion):
|
|
276
|
+
raise TypeError("version must be either a string or an APIVersion")
|
|
277
|
+
else:
|
|
278
|
+
checked_version = version
|
|
279
|
+
|
|
280
|
+
current_robot_type = _get_current_robot_type()
|
|
281
|
+
if robot_type is None:
|
|
282
|
+
if current_robot_type is None:
|
|
283
|
+
parsed_robot_type: RobotType = "OT-2 Standard"
|
|
284
|
+
else:
|
|
285
|
+
parsed_robot_type = current_robot_type
|
|
286
|
+
else:
|
|
287
|
+
# TODO(mm, 2023-10-09): This raises a slightly wrong error message, mentioning the camelCase
|
|
288
|
+
# `robotType` field in Python files instead of the snake_case `robot_type` argument for this
|
|
289
|
+
# function.
|
|
290
|
+
parsed_robot_type = parse.robot_type_from_python_identifier(robot_type)
|
|
291
|
+
_validate_can_simulate_for_robot_type(parsed_robot_type)
|
|
292
|
+
deck_type = deck_type_for_simulation(parsed_robot_type)
|
|
293
|
+
|
|
294
|
+
if extra_labware is None:
|
|
295
|
+
extra_labware = {
|
|
296
|
+
uri: details.definition
|
|
297
|
+
for uri, details in (entrypoint_util.find_jupyter_labware() or {}).items()
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
checked_hardware = _make_hardware_simulator(
|
|
301
|
+
override=hardware_simulator, robot_type=parsed_robot_type
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
if checked_version < ENGINE_CORE_API_VERSION:
|
|
305
|
+
context = _create_live_context_non_pe(
|
|
306
|
+
api_version=checked_version,
|
|
307
|
+
deck_type=deck_type,
|
|
308
|
+
hardware_api=checked_hardware,
|
|
309
|
+
bundled_labware=bundled_labware,
|
|
310
|
+
bundled_data=bundled_data,
|
|
311
|
+
extra_labware=extra_labware,
|
|
312
|
+
)
|
|
313
|
+
else:
|
|
314
|
+
if bundled_labware is not None:
|
|
315
|
+
# Protocol Engine has a deep assumption that standard labware definitions are always
|
|
316
|
+
# implicitly loadable.
|
|
317
|
+
raise NotImplementedError(
|
|
318
|
+
f"The bundled_labware argument is not currently supported for Python protocols"
|
|
319
|
+
f" with apiLevel {ENGINE_CORE_API_VERSION} or newer."
|
|
320
|
+
)
|
|
321
|
+
context = _create_live_context_pe(
|
|
322
|
+
api_version=checked_version,
|
|
323
|
+
robot_type=parsed_robot_type,
|
|
324
|
+
deck_type=deck_type,
|
|
325
|
+
hardware_api=checked_hardware,
|
|
326
|
+
bundled_data=bundled_data,
|
|
327
|
+
extra_labware=extra_labware,
|
|
328
|
+
use_pe_virtual_hardware=use_virtual_hardware,
|
|
329
|
+
)
|
|
330
|
+
|
|
331
|
+
# Intentional difference from execute.get_protocol_api():
|
|
332
|
+
# For the caller's convenience, we home the virtual hardware so they don't get MustHomeErrors.
|
|
333
|
+
# Since this hardware is virtual, there's no harm in commanding this "movement" implicitly.
|
|
334
|
+
#
|
|
335
|
+
# Calling `checked_hardware_sync.home()` is a hack. It ought to be redundant with
|
|
336
|
+
# `context.home()`. We need it here to work around a Protocol Engine simulation bug
|
|
337
|
+
# where both the `HardwareControlAPI` level and the `ProtocolEngine` level need to
|
|
338
|
+
# be homed for certain commands to work. https://opentrons.atlassian.net/browse/EXEC-646
|
|
339
|
+
checked_hardware.sync.home()
|
|
340
|
+
context.home()
|
|
341
|
+
|
|
342
|
+
return context
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def _make_hardware_simulator(
|
|
346
|
+
override: Optional[ThreadManagedHardware], robot_type: RobotType
|
|
347
|
+
) -> ThreadManagedHardware:
|
|
348
|
+
if override:
|
|
349
|
+
return override
|
|
350
|
+
elif robot_type == "OT-3 Standard":
|
|
351
|
+
# Local import because this isn't available on OT-2s.
|
|
352
|
+
from opentrons.hardware_control.ot3api import OT3API
|
|
353
|
+
|
|
354
|
+
return ThreadManager(
|
|
355
|
+
OT3API.build_hardware_simulator,
|
|
356
|
+
feature_flags=HardwareFeatureFlags.build_from_ff(),
|
|
357
|
+
)
|
|
358
|
+
elif robot_type == "OT-2 Standard":
|
|
359
|
+
return ThreadManager(
|
|
360
|
+
OT2API.build_hardware_simulator,
|
|
361
|
+
feature_flags=HardwareFeatureFlags.build_from_ff(),
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
@contextmanager
|
|
366
|
+
def _make_hardware_simulator_cm(
|
|
367
|
+
config_file_path: Optional[pathlib.Path], robot_type: RobotType
|
|
368
|
+
) -> Generator[ThreadManagedHardware, None, None]:
|
|
369
|
+
if config_file_path is not None:
|
|
370
|
+
result = ThreadManager(
|
|
371
|
+
load_simulator,
|
|
372
|
+
pathlib.Path(config_file_path),
|
|
373
|
+
)
|
|
374
|
+
try:
|
|
375
|
+
yield result
|
|
376
|
+
finally:
|
|
377
|
+
result.clean_up()
|
|
378
|
+
else:
|
|
379
|
+
result = _make_hardware_simulator(override=None, robot_type=robot_type)
|
|
380
|
+
try:
|
|
381
|
+
yield result
|
|
382
|
+
finally:
|
|
383
|
+
result.clean_up()
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _get_current_robot_type() -> Optional[RobotType]:
|
|
387
|
+
"""Return the type of robot that we're running on, or None if we're not on a robot."""
|
|
388
|
+
if IS_ROBOT:
|
|
389
|
+
return "OT-3 Standard" if should_use_ot3() else "OT-2 Standard"
|
|
390
|
+
else:
|
|
391
|
+
return None
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
def _validate_can_simulate_for_robot_type(robot_type: RobotType) -> None:
|
|
395
|
+
"""Raise if this device cannot simulate protocols written for the given robot type."""
|
|
396
|
+
current_robot_type = _get_current_robot_type()
|
|
397
|
+
if current_robot_type is None:
|
|
398
|
+
# When installed locally, this package can simulate protocols for any robot type.
|
|
399
|
+
pass
|
|
400
|
+
elif robot_type != current_robot_type:
|
|
401
|
+
# Match robot server behavior: raise an early error if we're on a robot and the caller
|
|
402
|
+
# tries to simulate a protocol written for a different robot type.
|
|
403
|
+
|
|
404
|
+
# FIXME: This exposes the internal strings "OT-2 Standard" and "OT-3 Standard".
|
|
405
|
+
# https://opentrons.atlassian.net/browse/RSS-370
|
|
406
|
+
raise RuntimeError(
|
|
407
|
+
f'This robot is of type "{current_robot_type}",'
|
|
408
|
+
f' so it can\'t simulate protocols for robot type "{robot_type}"'
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def bundle_from_sim(
|
|
413
|
+
protocol: PythonProtocol, context: opentrons.protocol_api.ProtocolContext
|
|
414
|
+
) -> BundleContents:
|
|
415
|
+
"""
|
|
416
|
+
From a protocol, and the context that has finished simulating that
|
|
417
|
+
protocol, determine what needs to go in a bundle for the protocol.
|
|
418
|
+
"""
|
|
419
|
+
bundled_labware: Dict[str, "LabwareDefinitionDict"] = {}
|
|
420
|
+
for lw in context.loaded_labwares.values():
|
|
421
|
+
if (
|
|
422
|
+
isinstance(lw, opentrons.protocol_api.labware.Labware)
|
|
423
|
+
and lw.uri not in bundled_labware
|
|
424
|
+
):
|
|
425
|
+
bundled_labware[lw.uri] = lw._core.get_definition()
|
|
426
|
+
|
|
427
|
+
return BundleContents(
|
|
428
|
+
protocol.text,
|
|
429
|
+
bundled_data=context.bundled_data,
|
|
430
|
+
bundled_labware=bundled_labware,
|
|
431
|
+
bundled_python={},
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def simulate(
|
|
436
|
+
protocol_file: Union[BinaryIO, TextIO],
|
|
437
|
+
file_name: Optional[str] = None,
|
|
438
|
+
custom_labware_paths: Optional[List[str]] = None,
|
|
439
|
+
custom_data_paths: Optional[List[str]] = None,
|
|
440
|
+
propagate_logs: bool = False,
|
|
441
|
+
hardware_simulator_file_path: Optional[str] = None,
|
|
442
|
+
duration_estimator: Optional[DurationEstimator] = None,
|
|
443
|
+
log_level: str = "warning",
|
|
444
|
+
) -> _SimulateResult:
|
|
445
|
+
"""
|
|
446
|
+
Simulate the protocol itself.
|
|
447
|
+
|
|
448
|
+
This is a one-stop function to simulate a protocol, whether Python or JSON,
|
|
449
|
+
no matter the API version, from external (i.e. not bound up in other
|
|
450
|
+
internal server infrastructure) sources.
|
|
451
|
+
|
|
452
|
+
To simulate an opentrons protocol from other places, pass in a file-like
|
|
453
|
+
object as ``protocol_file``; this function either returns (if the simulation
|
|
454
|
+
has no problems) or raises an exception.
|
|
455
|
+
|
|
456
|
+
To call from the command line, use either the autogenerated entrypoint
|
|
457
|
+
``opentrons_simulate`` (``opentrons_simulate.exe``, on windows) or
|
|
458
|
+
``python -m opentrons.simulate``.
|
|
459
|
+
|
|
460
|
+
The return value is the run log, a list of dicts that represent the
|
|
461
|
+
commands executed by the robot; and either the contents of the protocol
|
|
462
|
+
that would be required to bundle, or ``None``.
|
|
463
|
+
|
|
464
|
+
Each dict element in the run log has the following keys:
|
|
465
|
+
|
|
466
|
+
- ``level``: The depth at which this command is nested. If this an
|
|
467
|
+
aspirate inside a mix inside a transfer, for instance, it would be 3.
|
|
468
|
+
|
|
469
|
+
- ``payload``: The command. The human-readable run log text is available at
|
|
470
|
+
``payload["text"]``. The other keys of ``payload`` are command-dependent;
|
|
471
|
+
see ``opentrons.legacy_commands``.
|
|
472
|
+
|
|
473
|
+
.. note::
|
|
474
|
+
In older software versions, ``payload["text"]`` was a
|
|
475
|
+
`format string <https://docs.python.org/3/library/string.html#formatstrings>`_.
|
|
476
|
+
To get human-readable text, you had to do ``payload["text"].format(**payload)``.
|
|
477
|
+
Don't do that anymore. If ``payload["text"]`` happens to contain any
|
|
478
|
+
``{`` or ``}`` characters, it can confuse ``.format()`` and cause it to raise a
|
|
479
|
+
``KeyError``.
|
|
480
|
+
|
|
481
|
+
- ``logs``: Any log messages that occurred during execution of this
|
|
482
|
+
command, as a standard Python :py:obj:`~logging.LogRecord`.
|
|
483
|
+
|
|
484
|
+
:param protocol_file: The protocol file to simulate.
|
|
485
|
+
:param file_name: The name of the file
|
|
486
|
+
:param custom_labware_paths: A list of directories to search for custom labware.
|
|
487
|
+
Loads valid labware from these paths and makes them available
|
|
488
|
+
to the protocol context. If this is ``None`` (the default), and
|
|
489
|
+
this function is called on a robot, it will look in the ``labware``
|
|
490
|
+
subdirectory of the Jupyter data directory.
|
|
491
|
+
:param custom_data_paths: A list of directories or files to load custom
|
|
492
|
+
data files from. Ignored if the apiv2 feature
|
|
493
|
+
flag if not set. Entries may be either files or
|
|
494
|
+
directories. Specified files and the
|
|
495
|
+
non-recursive contents of specified directories
|
|
496
|
+
are presented by the protocol context in
|
|
497
|
+
``protocol_api.ProtocolContext.bundled_data``.
|
|
498
|
+
:param hardware_simulator_file_path: A path to a JSON file defining the simulated
|
|
499
|
+
hardware. This is mainly for internal use by Opentrons, and is not necessary
|
|
500
|
+
to simulate protocols.
|
|
501
|
+
:param duration_estimator: For internal use only.
|
|
502
|
+
Optional duration estimator object.
|
|
503
|
+
:param propagate_logs: Whether this function should allow logs from the
|
|
504
|
+
Opentrons stack to propagate up to the root handler.
|
|
505
|
+
This can be useful if you're integrating this
|
|
506
|
+
function in a larger application, but most logs that
|
|
507
|
+
occur during protocol simulation are best associated
|
|
508
|
+
with the actions in the protocol that cause them.
|
|
509
|
+
Default: ``False``
|
|
510
|
+
:param log_level: The level of logs to capture in the run log:
|
|
511
|
+
``"debug"``, ``"info"``, ``"warning"``, or ``"error"``.
|
|
512
|
+
Defaults to ``"warning"``.
|
|
513
|
+
:returns: A tuple of a run log for user output, and possibly the required
|
|
514
|
+
data to write to a bundle to bundle this protocol. The bundle is
|
|
515
|
+
only emitted if bundling is allowed
|
|
516
|
+
and this is an unbundled Protocol API
|
|
517
|
+
v2 python protocol. In other cases it is None.
|
|
518
|
+
"""
|
|
519
|
+
stack_logger = logging.getLogger("opentrons")
|
|
520
|
+
stack_logger.propagate = propagate_logs
|
|
521
|
+
# _CommandScraper will set the level of this logger.
|
|
522
|
+
|
|
523
|
+
# TODO(mm, 2023-10-02): Switch this truthy check to `is not None`
|
|
524
|
+
# to match documented behavior.
|
|
525
|
+
# See notes in https://github.com/Opentrons/opentrons/pull/13107
|
|
526
|
+
if custom_labware_paths:
|
|
527
|
+
extra_labware = entrypoint_util.labware_from_paths(custom_labware_paths)
|
|
528
|
+
else:
|
|
529
|
+
extra_labware = entrypoint_util.find_jupyter_labware() or {}
|
|
530
|
+
|
|
531
|
+
if custom_data_paths:
|
|
532
|
+
extra_data = entrypoint_util.datafiles_from_paths(custom_data_paths)
|
|
533
|
+
else:
|
|
534
|
+
extra_data = {}
|
|
535
|
+
|
|
536
|
+
contents = protocol_file.read()
|
|
537
|
+
try:
|
|
538
|
+
protocol = parse.parse(
|
|
539
|
+
contents,
|
|
540
|
+
file_name,
|
|
541
|
+
extra_labware={
|
|
542
|
+
uri: details.definition for uri, details in extra_labware.items()
|
|
543
|
+
},
|
|
544
|
+
extra_data=extra_data,
|
|
545
|
+
)
|
|
546
|
+
except parse.JSONSchemaVersionTooNewError as e:
|
|
547
|
+
# opentrons.protocols.parse() doesn't support new JSON protocols.
|
|
548
|
+
# The code to do that should be moved from opentrons.protocol_reader.
|
|
549
|
+
# See https://opentrons.atlassian.net/browse/PLAT-94.
|
|
550
|
+
raise NotImplementedError(_JSON_TOO_NEW_MESSAGE) from e
|
|
551
|
+
|
|
552
|
+
if protocol.api_level < APIVersion(2, 0):
|
|
553
|
+
raise ApiDeprecationError(version=protocol.api_level)
|
|
554
|
+
|
|
555
|
+
_validate_can_simulate_for_robot_type(protocol.robot_type)
|
|
556
|
+
|
|
557
|
+
with _make_hardware_simulator_cm(
|
|
558
|
+
config_file_path=(
|
|
559
|
+
None
|
|
560
|
+
if hardware_simulator_file_path is None
|
|
561
|
+
else pathlib.Path(hardware_simulator_file_path)
|
|
562
|
+
),
|
|
563
|
+
robot_type=protocol.robot_type,
|
|
564
|
+
) as hardware_simulator:
|
|
565
|
+
if protocol.api_level < ENGINE_CORE_API_VERSION:
|
|
566
|
+
return _run_file_non_pe(
|
|
567
|
+
protocol=protocol,
|
|
568
|
+
hardware_api=hardware_simulator,
|
|
569
|
+
logger=stack_logger,
|
|
570
|
+
level=log_level,
|
|
571
|
+
duration_estimator=duration_estimator,
|
|
572
|
+
)
|
|
573
|
+
else:
|
|
574
|
+
# TODO(mm, 2023-07-06): Once these NotImplementedErrors are resolved, consider removing
|
|
575
|
+
# the enclosing if-else block and running everything through _run_file_pe() for simplicity.
|
|
576
|
+
if custom_data_paths:
|
|
577
|
+
raise NotImplementedError(
|
|
578
|
+
f"The custom_data_paths argument is not currently supported for Python protocols"
|
|
579
|
+
f" with apiLevel {ENGINE_CORE_API_VERSION} or newer."
|
|
580
|
+
)
|
|
581
|
+
protocol_file.seek(0)
|
|
582
|
+
return _run_file_pe(
|
|
583
|
+
protocol=protocol,
|
|
584
|
+
robot_type=protocol.robot_type,
|
|
585
|
+
hardware_api=hardware_simulator,
|
|
586
|
+
stack_logger=stack_logger,
|
|
587
|
+
log_level=log_level,
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def format_runlog(runlog: List[Mapping[str, Any]]) -> str:
|
|
592
|
+
"""
|
|
593
|
+
Format a run log (return value of :py:obj:`simulate`) into a
|
|
594
|
+
human-readable string
|
|
595
|
+
|
|
596
|
+
:param runlog: The output of a call to :py:obj:`simulate`
|
|
597
|
+
"""
|
|
598
|
+
to_ret = []
|
|
599
|
+
for command in runlog:
|
|
600
|
+
to_ret.append("\t" * command["level"] + command["payload"].get("text", ""))
|
|
601
|
+
if command["logs"]:
|
|
602
|
+
to_ret.append("\t" * command["level"] + "Logs from this command:")
|
|
603
|
+
to_ret.extend(
|
|
604
|
+
[
|
|
605
|
+
"\t" * command["level"]
|
|
606
|
+
+ f"{l.levelname} ({l.module}): {l.msg}" % l.args
|
|
607
|
+
for l in command["logs"] # noqa: E741
|
|
608
|
+
]
|
|
609
|
+
)
|
|
610
|
+
return "\n".join(to_ret)
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def _get_bundle_args(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
|
|
614
|
+
parser.add_argument(
|
|
615
|
+
"-b",
|
|
616
|
+
"--bundle",
|
|
617
|
+
nargs="?",
|
|
618
|
+
const="PROTOCOL.ot2.zip",
|
|
619
|
+
default=None,
|
|
620
|
+
action="store",
|
|
621
|
+
type=str,
|
|
622
|
+
help="Bundle the specified protocol file, any labware used in it, and "
|
|
623
|
+
"any files in the data directories specified with -D into a "
|
|
624
|
+
"bundle. This bundle can be executed on a robot and carries with "
|
|
625
|
+
"it all the custom labware and data required to run. Without a "
|
|
626
|
+
"value specified in this argument, the bundle will be called "
|
|
627
|
+
"(protocol name without the .py).ot2.zip, but you can specify "
|
|
628
|
+
"a different output name. \n"
|
|
629
|
+
"These bundles are a beta feature, and their behavior may change",
|
|
630
|
+
)
|
|
631
|
+
return parser
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
def allow_bundle() -> bool:
|
|
635
|
+
"""
|
|
636
|
+
Check if bundling is allowed with a special not-exposed-to-the-app flag.
|
|
637
|
+
|
|
638
|
+
Returns ``True`` if the environment variable
|
|
639
|
+
``OT_API_FF_allowBundleCreation`` is ``"1"``
|
|
640
|
+
"""
|
|
641
|
+
return os.getenv("OT_API_FF_allowBundleCreation") == "1"
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
def get_arguments(parser: argparse.ArgumentParser) -> argparse.ArgumentParser:
|
|
645
|
+
"""Get the argument parser for this module
|
|
646
|
+
|
|
647
|
+
Useful if you want to use this module as a component of another CLI program
|
|
648
|
+
and want to add its arguments.
|
|
649
|
+
|
|
650
|
+
:param parser: A parser to add arguments to. If not specified, one will be created.
|
|
651
|
+
:returns argparse.ArgumentParser: The parser with arguments added.
|
|
652
|
+
"""
|
|
653
|
+
parser.add_argument(
|
|
654
|
+
"-l",
|
|
655
|
+
"--log-level",
|
|
656
|
+
choices=["debug", "info", "warning", "error", "none"],
|
|
657
|
+
default="warning",
|
|
658
|
+
help="Specify the level filter for logs to show on the command line. "
|
|
659
|
+
'Log levels below warning can be chatty. If "none", do not show logs',
|
|
660
|
+
)
|
|
661
|
+
|
|
662
|
+
parser.add_argument(
|
|
663
|
+
"-L",
|
|
664
|
+
"--custom-labware-path",
|
|
665
|
+
action="append",
|
|
666
|
+
default=[os.getcwd()],
|
|
667
|
+
help="Specify directories to search for custom labware definitions. "
|
|
668
|
+
"You can specify this argument multiple times. Once you specify "
|
|
669
|
+
"a directory in this way, labware definitions in that directory "
|
|
670
|
+
"will become available in ProtocolContext.load_labware(). "
|
|
671
|
+
"Only directories specified directly by "
|
|
672
|
+
"this argument are searched, not their children. JSON files that "
|
|
673
|
+
"do not define labware will be ignored with a message. "
|
|
674
|
+
"The current directory (the one from which you are "
|
|
675
|
+
"invoking this program) will always be included implicitly, "
|
|
676
|
+
"in addition to any directories that you specify.",
|
|
677
|
+
)
|
|
678
|
+
parser.add_argument(
|
|
679
|
+
"-D",
|
|
680
|
+
"--custom-data-path",
|
|
681
|
+
action="append",
|
|
682
|
+
nargs="?",
|
|
683
|
+
const=".",
|
|
684
|
+
default=[],
|
|
685
|
+
help="Specify directories to search for custom data files. "
|
|
686
|
+
"You can specify this argument multiple times. Once you specify "
|
|
687
|
+
"a directory in this way, files located in the specified "
|
|
688
|
+
"directory will be available in ProtocolContext.bundled_data. "
|
|
689
|
+
"Note that bundle execution will still only allow data files in "
|
|
690
|
+
"the bundle. If you specify this without a path, it will "
|
|
691
|
+
"add the current path implicitly. If you do not specify this "
|
|
692
|
+
"argument at all, no data files will be added. Any file in the "
|
|
693
|
+
"specified paths will be loaded into memory and included in the "
|
|
694
|
+
"bundle if --bundle is passed, so be careful that any directory "
|
|
695
|
+
"you specify has only the files you want. It is usually a "
|
|
696
|
+
"better idea to use -d so no files are accidentally included. "
|
|
697
|
+
"Also note that data files are made available as their name, not "
|
|
698
|
+
"their full path, so name them uniquely.",
|
|
699
|
+
)
|
|
700
|
+
parser.add_argument(
|
|
701
|
+
"-s",
|
|
702
|
+
"--custom-hardware-simulator-file",
|
|
703
|
+
type=str,
|
|
704
|
+
default=None,
|
|
705
|
+
help="Specify a file that describes the features present in the "
|
|
706
|
+
"hardware simulator. Features can be instruments, modules, and "
|
|
707
|
+
"configuration.",
|
|
708
|
+
)
|
|
709
|
+
parser.add_argument(
|
|
710
|
+
"-d",
|
|
711
|
+
"--custom-data-file",
|
|
712
|
+
action="append",
|
|
713
|
+
default=[],
|
|
714
|
+
help="Specify data files to be made available in "
|
|
715
|
+
"ProtocolContext.bundled_data (and possibly bundled if --bundle "
|
|
716
|
+
"is passed). Can be specified multiple times with different "
|
|
717
|
+
"files. It is usually a better idea to use this than -D because "
|
|
718
|
+
"there is less possibility of accidentally including something.",
|
|
719
|
+
)
|
|
720
|
+
if allow_bundle():
|
|
721
|
+
parser = _get_bundle_args(parser)
|
|
722
|
+
|
|
723
|
+
parser.add_argument(
|
|
724
|
+
"-e",
|
|
725
|
+
"--estimate-duration",
|
|
726
|
+
action="store_true",
|
|
727
|
+
# TODO (AL, 2021-07-26): Better wording.
|
|
728
|
+
help="Estimate how long the protocol will take to complete."
|
|
729
|
+
" This is an experimental feature.",
|
|
730
|
+
)
|
|
731
|
+
|
|
732
|
+
parser.add_argument(
|
|
733
|
+
"protocol",
|
|
734
|
+
metavar="PROTOCOL",
|
|
735
|
+
type=argparse.FileType("rb"),
|
|
736
|
+
help="The protocol file to simulate. If you pass '-', you can pipe "
|
|
737
|
+
"the protocol via stdin; this could be useful if you want to use this "
|
|
738
|
+
"utility as part of an automated workflow.",
|
|
739
|
+
)
|
|
740
|
+
parser.add_argument(
|
|
741
|
+
"-v",
|
|
742
|
+
"--version",
|
|
743
|
+
action="version",
|
|
744
|
+
version=f"%(prog)s {opentrons.__version__}",
|
|
745
|
+
help="Print the opentrons package version and exit",
|
|
746
|
+
)
|
|
747
|
+
parser.add_argument(
|
|
748
|
+
"-o",
|
|
749
|
+
"--output",
|
|
750
|
+
action="store",
|
|
751
|
+
help="What to output during simulations",
|
|
752
|
+
choices=["runlog", "nothing"],
|
|
753
|
+
default="runlog",
|
|
754
|
+
)
|
|
755
|
+
return parser
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
def _get_bundle_dest(
|
|
759
|
+
bundle_name: Optional[str], default_key: str, proto_name: str
|
|
760
|
+
) -> Optional[BinaryIO]:
|
|
761
|
+
if bundle_name == default_key:
|
|
762
|
+
protopath = pathlib.Path(proto_name)
|
|
763
|
+
# strip all the suffixes since protocols are often named
|
|
764
|
+
# .ot2.zip
|
|
765
|
+
if protopath.name.endswith(".ot2.py"):
|
|
766
|
+
protoname = pathlib.Path(protopath.stem).stem
|
|
767
|
+
else:
|
|
768
|
+
protoname = protopath.stem
|
|
769
|
+
bundle_name = str((pathlib.Path.cwd() / protoname).with_suffix(".ot2.zip"))
|
|
770
|
+
return open(bundle_name, "wb")
|
|
771
|
+
elif bundle_name:
|
|
772
|
+
return open(bundle_name, "wb")
|
|
773
|
+
else:
|
|
774
|
+
return None
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
def _create_live_context_non_pe(
|
|
778
|
+
api_version: APIVersion,
|
|
779
|
+
hardware_api: ThreadManagedHardware,
|
|
780
|
+
deck_type: str,
|
|
781
|
+
extra_labware: Optional[Dict[str, "LabwareDefinitionDict"]],
|
|
782
|
+
bundled_labware: Optional[Dict[str, "LabwareDefinitionDict"]],
|
|
783
|
+
bundled_data: Optional[Dict[str, bytes]],
|
|
784
|
+
) -> ProtocolContext:
|
|
785
|
+
"""Return a live ProtocolContext.
|
|
786
|
+
|
|
787
|
+
This controls the robot through the older infrastructure, instead of through Protocol Engine.
|
|
788
|
+
"""
|
|
789
|
+
assert api_version < ENGINE_CORE_API_VERSION
|
|
790
|
+
return protocol_api.create_protocol_context(
|
|
791
|
+
api_version=api_version,
|
|
792
|
+
deck_type=deck_type,
|
|
793
|
+
hardware_api=hardware_api,
|
|
794
|
+
bundled_labware=bundled_labware,
|
|
795
|
+
bundled_data=bundled_data,
|
|
796
|
+
extra_labware=extra_labware,
|
|
797
|
+
)
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
def _create_live_context_pe(
|
|
801
|
+
api_version: APIVersion,
|
|
802
|
+
hardware_api: ThreadManagedHardware,
|
|
803
|
+
robot_type: RobotType,
|
|
804
|
+
deck_type: str,
|
|
805
|
+
extra_labware: Dict[str, "LabwareDefinitionDict"],
|
|
806
|
+
bundled_data: Optional[Dict[str, bytes]],
|
|
807
|
+
use_pe_virtual_hardware: bool = True,
|
|
808
|
+
) -> ProtocolContext:
|
|
809
|
+
"""Return a live ProtocolContext that controls the robot through ProtocolEngine."""
|
|
810
|
+
assert api_version >= ENGINE_CORE_API_VERSION
|
|
811
|
+
hardware_api_wrapped = hardware_api.wrapped()
|
|
812
|
+
global _LIVE_PROTOCOL_ENGINE_CONTEXTS
|
|
813
|
+
pe, loop = _LIVE_PROTOCOL_ENGINE_CONTEXTS.enter_context(
|
|
814
|
+
create_protocol_engine_in_thread(
|
|
815
|
+
hardware_api=hardware_api_wrapped,
|
|
816
|
+
config=_get_protocol_engine_config(
|
|
817
|
+
robot_type, use_pe_virtual_hardware=use_pe_virtual_hardware
|
|
818
|
+
),
|
|
819
|
+
deck_configuration=None,
|
|
820
|
+
file_provider=None,
|
|
821
|
+
error_recovery_policy=error_recovery_policy.never_recover,
|
|
822
|
+
drop_tips_after_run=False,
|
|
823
|
+
post_run_hardware_state=PostRunHardwareState.STAY_ENGAGED_IN_PLACE,
|
|
824
|
+
load_fixed_trash=should_load_fixed_trash_labware_for_python_protocol(
|
|
825
|
+
api_version
|
|
826
|
+
),
|
|
827
|
+
)
|
|
828
|
+
)
|
|
829
|
+
|
|
830
|
+
# `async def` so we can use loop.run_coroutine_threadsafe() to wait for its completion.
|
|
831
|
+
# Non-async would use call_soon_threadsafe(), which makes the waiting harder.
|
|
832
|
+
async def add_all_extra_labware() -> None:
|
|
833
|
+
for labware_definition_dict in extra_labware.values():
|
|
834
|
+
labware_definition = labware_definition_type_adapter.validate_python(
|
|
835
|
+
labware_definition_dict
|
|
836
|
+
)
|
|
837
|
+
pe.add_labware_definition(labware_definition)
|
|
838
|
+
|
|
839
|
+
# Add extra_labware to ProtocolEngine, being careful not to modify ProtocolEngine from this
|
|
840
|
+
# thread. See concurrency notes in ProtocolEngine docstring.
|
|
841
|
+
future = asyncio.run_coroutine_threadsafe(add_all_extra_labware(), loop)
|
|
842
|
+
future.result()
|
|
843
|
+
|
|
844
|
+
return protocol_api.create_protocol_context(
|
|
845
|
+
api_version=api_version,
|
|
846
|
+
hardware_api=hardware_api,
|
|
847
|
+
deck_type=deck_type,
|
|
848
|
+
protocol_engine=pe,
|
|
849
|
+
protocol_engine_loop=loop,
|
|
850
|
+
bundled_data=bundled_data,
|
|
851
|
+
)
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def _run_file_non_pe(
|
|
855
|
+
protocol: Protocol,
|
|
856
|
+
hardware_api: ThreadManagedHardware,
|
|
857
|
+
logger: logging.Logger,
|
|
858
|
+
level: str,
|
|
859
|
+
duration_estimator: Optional[DurationEstimator],
|
|
860
|
+
) -> _SimulateResult:
|
|
861
|
+
"""Run a protocol file without Protocol Engine, with the older infrastructure instead."""
|
|
862
|
+
if isinstance(protocol, PythonProtocol):
|
|
863
|
+
extra_labware = protocol.extra_labware
|
|
864
|
+
bundled_labware = protocol.bundled_labware
|
|
865
|
+
bundled_data = protocol.bundled_data
|
|
866
|
+
else:
|
|
867
|
+
# JSON protocols do have "bundled labware" embedded in them, but those aren't represented in
|
|
868
|
+
# the parsed Protocol object and we don't need to create the ProtocolContext with them.
|
|
869
|
+
# execute_apiv2.run_protocol() will pull them out of the JSON and load them into the
|
|
870
|
+
# ProtocolContext.
|
|
871
|
+
extra_labware = None
|
|
872
|
+
bundled_labware = None
|
|
873
|
+
bundled_data = None
|
|
874
|
+
|
|
875
|
+
context = _create_live_context_non_pe(
|
|
876
|
+
api_version=protocol.api_level,
|
|
877
|
+
hardware_api=hardware_api,
|
|
878
|
+
deck_type=deck_type_for_simulation(protocol.robot_type),
|
|
879
|
+
extra_labware=extra_labware,
|
|
880
|
+
bundled_labware=bundled_labware,
|
|
881
|
+
bundled_data=bundled_data,
|
|
882
|
+
)
|
|
883
|
+
|
|
884
|
+
scraper = _CommandScraper(logger=logger, level=level, broker=context.broker)
|
|
885
|
+
if duration_estimator:
|
|
886
|
+
context.broker.subscribe(command_types.COMMAND, duration_estimator.on_message)
|
|
887
|
+
|
|
888
|
+
context.home()
|
|
889
|
+
with scraper.scrape():
|
|
890
|
+
try:
|
|
891
|
+
execute.run_protocol(
|
|
892
|
+
protocol, context, run_time_parameters_with_overrides=None
|
|
893
|
+
)
|
|
894
|
+
if (
|
|
895
|
+
isinstance(protocol, PythonProtocol)
|
|
896
|
+
and protocol.api_level >= APIVersion(2, 0)
|
|
897
|
+
and protocol.bundled_labware is None
|
|
898
|
+
and allow_bundle()
|
|
899
|
+
):
|
|
900
|
+
bundle_contents: Optional[BundleContents] = bundle_from_sim(
|
|
901
|
+
protocol, context
|
|
902
|
+
)
|
|
903
|
+
else:
|
|
904
|
+
bundle_contents = None
|
|
905
|
+
|
|
906
|
+
finally:
|
|
907
|
+
context.cleanup()
|
|
908
|
+
|
|
909
|
+
return scraper.commands, bundle_contents
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
def _run_file_pe(
|
|
913
|
+
protocol: Protocol,
|
|
914
|
+
robot_type: RobotType,
|
|
915
|
+
hardware_api: ThreadManagedHardware,
|
|
916
|
+
stack_logger: logging.Logger,
|
|
917
|
+
log_level: str,
|
|
918
|
+
) -> _SimulateResult:
|
|
919
|
+
"""Run a protocol file with Protocol Engine."""
|
|
920
|
+
# TODO (spp, 2024-03-18): use run-time param overrides once enabled for cli protocol simulation.
|
|
921
|
+
|
|
922
|
+
async def run(protocol_source: ProtocolSource) -> _SimulateResult:
|
|
923
|
+
hardware_api_wrapped = hardware_api.wrapped()
|
|
924
|
+
protocol_engine = await create_protocol_engine(
|
|
925
|
+
hardware_api=hardware_api_wrapped,
|
|
926
|
+
config=_get_protocol_engine_config(
|
|
927
|
+
robot_type, use_pe_virtual_hardware=True
|
|
928
|
+
),
|
|
929
|
+
error_recovery_policy=error_recovery_policy.never_recover,
|
|
930
|
+
load_fixed_trash=should_load_fixed_trash(protocol_source.config),
|
|
931
|
+
)
|
|
932
|
+
|
|
933
|
+
protocol_runner = create_protocol_runner(
|
|
934
|
+
protocol_config=protocol_source.config,
|
|
935
|
+
protocol_engine=protocol_engine,
|
|
936
|
+
hardware_api=hardware_api_wrapped,
|
|
937
|
+
)
|
|
938
|
+
|
|
939
|
+
orchestrator = RunOrchestrator(
|
|
940
|
+
hardware_api=hardware_api_wrapped,
|
|
941
|
+
protocol_engine=protocol_engine,
|
|
942
|
+
json_or_python_protocol_runner=protocol_runner,
|
|
943
|
+
fixit_runner=LiveRunner(
|
|
944
|
+
protocol_engine=protocol_engine, hardware_api=hardware_api_wrapped
|
|
945
|
+
),
|
|
946
|
+
setup_runner=LiveRunner(
|
|
947
|
+
protocol_engine=protocol_engine, hardware_api=hardware_api_wrapped
|
|
948
|
+
),
|
|
949
|
+
protocol_live_runner=LiveRunner(
|
|
950
|
+
protocol_engine=protocol_engine, hardware_api=hardware_api_wrapped
|
|
951
|
+
),
|
|
952
|
+
)
|
|
953
|
+
|
|
954
|
+
# TODO(mm, 2024-08-06): This home is theoretically redundant with Protocol
|
|
955
|
+
# Engine `home` commands within the `RunOrchestrator`. However, we need this to
|
|
956
|
+
# work around Protocol Engine bugs where both the `HardwareControlAPI` level
|
|
957
|
+
# and the `ProtocolEngine` level need to be homed for certain commands to work.
|
|
958
|
+
# https://opentrons.atlassian.net/browse/EXEC-646
|
|
959
|
+
await hardware_api_wrapped.home()
|
|
960
|
+
|
|
961
|
+
scraper = _CommandScraper(stack_logger, log_level, protocol_runner.broker)
|
|
962
|
+
with scraper.scrape():
|
|
963
|
+
result = await orchestrator.run(
|
|
964
|
+
# deck_configuration=[] is a placeholder value, ignored because
|
|
965
|
+
# the Protocol Engine config specifies use_simulated_deck_config=True.
|
|
966
|
+
deck_configuration=[],
|
|
967
|
+
protocol_source=protocol_source,
|
|
968
|
+
)
|
|
969
|
+
|
|
970
|
+
if result.state_summary.status != EngineStatus.SUCCEEDED:
|
|
971
|
+
raise entrypoint_util.ProtocolEngineExecuteError(
|
|
972
|
+
result.state_summary.errors
|
|
973
|
+
)
|
|
974
|
+
|
|
975
|
+
# We don't currently support returning bundle contents from protocols run through
|
|
976
|
+
# Protocol Engine. To get them, bundle_from_sim() requires direct access to the
|
|
977
|
+
# ProtocolContext, which opentrons.protocol_runner does not grant us.
|
|
978
|
+
bundle_contents = None
|
|
979
|
+
|
|
980
|
+
return scraper.commands, bundle_contents
|
|
981
|
+
|
|
982
|
+
with entrypoint_util.adapt_protocol_source(protocol) as protocol_source:
|
|
983
|
+
return asyncio.run(run(protocol_source))
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
def _get_protocol_engine_config(
|
|
987
|
+
robot_type: RobotType, use_pe_virtual_hardware: bool
|
|
988
|
+
) -> Config:
|
|
989
|
+
"""Return a Protocol Engine config to execute protocols on this device."""
|
|
990
|
+
return Config(
|
|
991
|
+
robot_type=robot_type,
|
|
992
|
+
deck_type=DeckType(deck_type_for_simulation(robot_type)),
|
|
993
|
+
ignore_pause=True,
|
|
994
|
+
use_virtual_pipettes=use_pe_virtual_hardware,
|
|
995
|
+
use_virtual_modules=use_pe_virtual_hardware,
|
|
996
|
+
use_virtual_gripper=use_pe_virtual_hardware,
|
|
997
|
+
use_simulated_deck_config=True,
|
|
998
|
+
)
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
@atexit.register
|
|
1002
|
+
def _clear_live_protocol_engine_contexts() -> None:
|
|
1003
|
+
global _LIVE_PROTOCOL_ENGINE_CONTEXTS
|
|
1004
|
+
_LIVE_PROTOCOL_ENGINE_CONTEXTS.close()
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
# Note - this script is also set up as a setuptools entrypoint and thus does
|
|
1008
|
+
# an absolute minimum of work since setuptools does something odd generating
|
|
1009
|
+
# the scripts
|
|
1010
|
+
def main() -> int:
|
|
1011
|
+
"""Run the simulation"""
|
|
1012
|
+
parser = argparse.ArgumentParser(
|
|
1013
|
+
prog="opentrons_simulate",
|
|
1014
|
+
description="Simulate a protocol for an Opentrons robot",
|
|
1015
|
+
)
|
|
1016
|
+
parser = get_arguments(parser)
|
|
1017
|
+
|
|
1018
|
+
args = parser.parse_args()
|
|
1019
|
+
|
|
1020
|
+
# TODO(mm, 2022-12-01): Configure the DurationEstimator with the correct deck type.
|
|
1021
|
+
duration_estimator = DurationEstimator() if args.estimate_duration else None
|
|
1022
|
+
|
|
1023
|
+
try:
|
|
1024
|
+
runlog, maybe_bundle = simulate(
|
|
1025
|
+
protocol_file=args.protocol,
|
|
1026
|
+
file_name=args.protocol.name,
|
|
1027
|
+
custom_labware_paths=args.custom_labware_path,
|
|
1028
|
+
custom_data_paths=(args.custom_data_path + args.custom_data_file),
|
|
1029
|
+
duration_estimator=duration_estimator,
|
|
1030
|
+
hardware_simulator_file_path=getattr(
|
|
1031
|
+
args, "custom_hardware_simulator_file"
|
|
1032
|
+
),
|
|
1033
|
+
log_level=args.log_level,
|
|
1034
|
+
)
|
|
1035
|
+
except entrypoint_util.ProtocolEngineExecuteError as error:
|
|
1036
|
+
print(error.to_stderr_string(), file=sys.stderr)
|
|
1037
|
+
return 1
|
|
1038
|
+
|
|
1039
|
+
if maybe_bundle:
|
|
1040
|
+
bundle_name = getattr(args, "bundle", None)
|
|
1041
|
+
if bundle_name == args.protocol.name:
|
|
1042
|
+
raise RuntimeError("Bundle path and input path must be different")
|
|
1043
|
+
bundle_dest = _get_bundle_dest(
|
|
1044
|
+
bundle_name, "PROTOCOL.ot2.zip", args.protocol.name
|
|
1045
|
+
)
|
|
1046
|
+
if bundle_dest:
|
|
1047
|
+
bundle.create_bundle(maybe_bundle, bundle_dest)
|
|
1048
|
+
|
|
1049
|
+
if args.output == "runlog":
|
|
1050
|
+
print(format_runlog(runlog))
|
|
1051
|
+
|
|
1052
|
+
if duration_estimator:
|
|
1053
|
+
duration_seconds = duration_estimator.get_total_duration()
|
|
1054
|
+
hours = int(duration_seconds / 60 / 60)
|
|
1055
|
+
minutes = int((duration_seconds % (60 * 60)) / 60)
|
|
1056
|
+
print("--------------------------------------------------------------")
|
|
1057
|
+
print(f"Estimated protocol duration: {hours}h:{minutes}m")
|
|
1058
|
+
print("--------------------------------------------------------------")
|
|
1059
|
+
print("WARNING: Protocol duration estimation is an experimental feature")
|
|
1060
|
+
|
|
1061
|
+
return 0
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
if __name__ == "__main__":
|
|
1065
|
+
sys.exit(main())
|