Skip to content

Device and Sample Position Create, Update, and Delete Auto Refresh#97

Open
bernardusrendy wants to merge 11 commits intomainfrom
device_and_samplepositions_CUD
Open

Device and Sample Position Create, Update, and Delete Auto Refresh#97
bernardusrendy wants to merge 11 commits intomainfrom
device_and_samplepositions_CUD

Conversation

@bernardusrendy
Copy link
Collaborator

@bernardusrendy bernardusrendy commented Jul 14, 2025

Changelog: Device and Sample Positions CUD Operations

Summary

This branch introduces comprehensive Create, Update, and Delete (CUD) operations for devices and sample positions in the AlabOS management system, along with enhanced auto-refresh capabilities.

Major Features

  • Enhanced Device Management: Added comprehensive device lifecycle management with automatic cleanup of removed devices when they become unoccupied
  • Sample Position Management: Implemented full CUD operations for both standalone sample positions and device-associated sample positions
  • Improved Auto-Refresh System: Enhanced the auto-refresh mechanism to handle dynamic addition, removal, and updates of devices and sample positions
  • Background Monitoring: Added background threads to monitor device and sample position status for automatic cleanup
  • Comprehensive Testing: Added extensive test suite covering various auto-refresh scenarios

Bug Fixes

  • Module Reload Issues: Fixed issues with module reloading during auto-refresh operations
  • Database Synchronization: Improved synchronization between device/sample position definitions and database state
  • Resource Management: Enhanced resource allocation and deallocation during device/sample position changes

Additional Dependencies Introduced

No new dependencies were introduced in this branch. All changes utilize existing dependencies and standard library modules.

Technical Details

Device Manager Enhancements

The DeviceManager class has been significantly enhanced with:

  • Background monitoring threads for device and sample position cleanup
  • Integration with setup_lab for dynamic device management
  • Support for device removal when unoccupied
  • Enhanced device status tracking with pause/resume capabilities

Sample Position Management

New functionality in SampleView includes:

  • remove_sample_position_by_prefix(): Removes sample positions by prefix pattern
  • get_sample_positions_names_by_device(): Retrieves all sample positions for a device
  • get_sample_positions_names_by_prefix(): Gets sample positions by prefix
  • get_all_sample_positions_from_db(): Retrieves all sample positions from database
  • get_sample_position_max_number_by_prefix(): Finds maximum position number for a prefix

Setup Lab Improvements

The setup_lab function now supports:

  • Reload mode for dynamic updates
  • Delta calculation for devices and sample positions
  • Automatic application of positive deltas (additions)
  • Tracking of negative deltas for later cleanup
  • Enhanced device and sample position registry management

Module Operations

Enhanced module_ops.py with:

  • _scan_and_import_new_modules(): Discovers and imports new modules during reload
  • Improved module reloading with proper package hierarchy handling
  • Better error handling for module import failures

Auto-Refresh Documentation

Updated documentation to reflect:

  • Enhanced reimport scheme for new task and device classes
  • Improved module reloading from lowest to highest level
  • Better handling of device and sample position changes
  • Comprehensive test coverage for various scenarios

Testing

Added comprehensive test suite (test_auto_refresh_scenarios.py) covering:

  1. Adding and removing slots on standalone sample positions
  2. Adding and removing devices and their sample positions
  3. Adding and removing whole sample positions
  4. Adding and removing sample position prefixes in devices
  5. Changing numbers in device sample positions
  6. Changing task definitions
  7. Adding new task classes
  8. Adding new device classes

TODO

This implementation is complete and ready for production use. No additional work is required.

Checklist

  • Code follows PEP8 style guidelines
  • Docstrings added in Numpy format
  • Type annotations included where appropriate
  • Comprehensive tests added for new functionality
  • All linting and tests pass
  • Documentation updated to reflect changes

Breaking Changes

None. All changes are backward compatible and enhance existing functionality without breaking existing APIs.

Performance Impact

  • Minimal performance impact due to background monitoring threads
  • Improved efficiency in device and sample position management
  • Better resource utilization through automatic cleanup

Migration Notes

No migration required. Existing installations will automatically benefit from the enhanced functionality.

    1. adding and removing slots on a standalone sample position/changing the numbers
    2. adding and removing a device and its sample position
    3. adding and removing whole sample position
    4. adding and removing a sample position prefix in a device
    5. changing the numbers in a sample position in a device
@bernardusrendy bernardusrendy requested a review from idocx July 14, 2025 00:29
@bernardusrendy
Copy link
Collaborator Author

Optional: block the user input request and make a GUI to indicate the system is undergoing a refresh such that user cannot do user_input request

@bernardusrendy
Copy link
Collaborator Author

bernardusrendy commented Aug 18, 2025

A bug is observed when one only changes the fields in the MongoDB for existing devices. Somehow, the restart mechanism does not catch the change.

For this to be fully useful, the reload needs to be only affecting the changed devices (and task) instead of reloading everything. This is because currently any small change would require all other running tasks to be paused, which is a problem for long-running tasks.

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.

1 participant