feat: add Python bridge device support (UniCore support)#86
Open
tlambert03 wants to merge 45 commits into
Open
feat: add Python bridge device support (UniCore support)#86tlambert03 wants to merge 45 commits into
tlambert03 wants to merge 45 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
==========================================
- Coverage 77.65% 72.34% -5.32%
==========================================
Files 2 4 +2
Lines 1253 2108 +855
Branches 973 1266 +293
==========================================
+ Hits 973 1525 +552
- Misses 80 302 +222
- Partials 200 281 +81 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…PyBridgeShutter, and PyBridgeAdapter destructors
…e, AutoFocus, Generic, Hub, and SLM
…updates and update related protocols and tests
… conversions are explicit in SetImage methods
…ag and improve error handling
…adata and add corresponding tests
…date Python interface
Member
Author
|
well... it's grown quite a bit now. but i think the pattern is working well! and it's getting pretty fully featured, including dynamic property changes, device notification callbacks, buffer insertions, etc... |
…and rethrowing as runtime_error
… to use zero-copy ndarray
…thods for channel handling and exposure sequenceability
… for position handling and motion control
…ing in DeviceCallbacks and MinimalCamera
…imalState initialization
…s for device detection
…y acquisition handling
…numpy compatibility
…tests for clarity
…s to reduce Python bridge crossings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@marktsuchida, here's what claude came up with. I think it looks pretty clean actually. All of the conveniences that hide the ugliness of the full C++ device API could be done in pymmcore-plus with ready-to-go ABCs that build off of a device-specific
BridgeABCthat has all the mandatory methods required on the C side.the tests show the basic idea in practice
any high level thoughts about cleanup/safety/etc?
autogenerated docs at: https://github.com/tlambert03/pymmcore-nano/tree/unicore/docs/bridge-devices.md
New methods on
CMMCoreloadPyDeviceAdapter(adapter_name: str, adapter: DeviceAdapter) -> None— register a multi-device adapter; CMMCore takes ownership.loadPyDevice(label: str, py_device, type: DeviceType) -> None— convenience that wraps a single pre-instantiated Python device in a one-off adapter and loads it.After loading, the standard CMMCore flow (
getAvailableDevices,loadDevice,initializeDevice, …) works against the Python device.New module
pymmcore_nano.protocols@runtime_checkableProtocolclasses documenting what each device-type bridge expects on the Python side. All inherit fromPyDevice, which requires:initialize_bridge(create_property: CreatePropertyFn, notify: DeviceCallbacks) -> Noneshutdown() -> Nonebusy() -> boolNew classes on
pymmcore_nanoDeviceAdapterA collection of Python device classes that acts as an MM device adapter library.
DeviceAdapter()— construct an empty adapteradd_device_class(name: str, device_class: type, device_type: DeviceType, description: str) -> NonePropertyHandleReturned by the
create_property()callable passed toinitialize_bridge(). Used for dynamic constraint updates after a property is registered (valid for the device's entire lifetime).set_limits(lower, upper)set_allowed_values(values)set_sequence_max_length(max_length)DeviceCallbacksNotification channel handed to
initialize_bridge()so a Python device can reach back into CMMCore (the equivalent of callingGetCoreCallback()->OnXyz()in C++).on_property_changed(name, value)on_properties_changed()on_stage_position_changed(pos)on_xy_stage_position_changed(x, y)on_exposure_changed(exposure)on_shutter_open_changed(open)set_position_label(pos, label)log_message(msg, debug_only=False)acq_finished(status_code=0)Behavior change worth noting
CMMCore.popNextImage()now uses the metadata fast-path (popNextImageMD) to avoid Python-bridge round trips forPyBridgeCameracameras — same return type, ~5% slower for pure-C++ cameras, big win for Python cameras.setSLMImage/loadSLMSequencenow validate againstgetSLMNumberOfComponents(), accepting 3- or 4-channel RGB(A) images instead of only 3-channel.