Compare commits

..

4 Commits

Author SHA1 Message Date
Xuwznln
8580b84167 Fix update with different spot and same parent 2026-01-08 03:46:44 +08:00
Xuwznln
3f80349d7d Force update resource when adding new resource / transfer to another resource
location not passed to ItemizedCarrier when assign child resource

Fix size not pass through.
2026-01-08 03:08:01 +08:00
Xuwznln
024156848e Fix build on macos-intel 2026-01-07 21:11:33 +08:00
Xuwznln
8066c200b9 Update README.md
Modify resource_tracker file module path.
2026-01-07 20:54:20 +08:00
22 changed files with 73 additions and 52 deletions

View File

@@ -24,7 +24,7 @@ jobs:
platform: linux-64
env_file: unilabos-linux-64.yaml
script_ext: sh
- os: macos-13 # Intel
- os: macos-15 # Intel (via Rosetta)
platform: osx-64
env_file: unilabos-osx-64.yaml
script_ext: sh

View File

@@ -27,7 +27,7 @@ jobs:
- os: ubuntu-latest
platform: linux-64
env_file: unilabos-linux-64.yaml
- os: macos-13 # Intel
- os: macos-15 # Intel (via Rosetta)
platform: osx-64
env_file: unilabos-osx-64.yaml
- os: macos-latest # ARM64

View File

@@ -26,7 +26,7 @@ jobs:
include:
- os: ubuntu-latest
platform: linux-64
- os: macos-13 # Intel
- os: macos-15 # Intel (via Rosetta)
platform: osx-64
- os: macos-latest # ARM64
platform: osx-arm64

View File

@@ -31,7 +31,9 @@ Detailed documentation can be found at:
## Quick Start
Uni-Lab-OS recommends using `mamba` for environment management. Choose the appropriate environment file for your operating system:
1. Setup Conda Environment
Uni-Lab-OS recommends using `mamba` for environment management:
```bash
# Create new environment
@@ -40,7 +42,7 @@ mamba activate unilab
mamba install -n unilab uni-lab::unilabos -c robostack-staging -c conda-forge
```
## Install Dev Uni-Lab-OS
2. Install Dev Uni-Lab-OS
```bash
# Clone the repository
@@ -51,17 +53,21 @@ cd Uni-Lab-OS
pip install .
```
3. Start Uni-Lab System:
3. Start Uni-Lab System
Please refer to [Documentation - Boot Examples](https://deepmodeling.github.io/Uni-Lab-OS/boot_examples/index.html)
4. Best Practice
See [Best Practice Guide](https://deepmodeling.github.io/Uni-Lab-OS/user_guide/best_practice.html)
## Message Format
Uni-Lab-OS uses pre-built `unilabos_msgs` for system communication. You can find the built versions on the [GitHub Releases](https://github.com/deepmodeling/Uni-Lab-OS/releases) page.
## Citation
If you use Uni-Lab-OS in academic research, please cite:
If you use [Uni-Lab-OS](https://arxiv.org/abs/2512.21766) in academic research, please cite:
```bibtex
@article{gao2025unilabos,

View File

@@ -53,17 +53,21 @@ cd Uni-Lab-OS
pip install .
```
3. 启动 Uni-Lab 系统:
3. 启动 Uni-Lab 系统
请见[文档-启动样例](https://deepmodeling.github.io/Uni-Lab-OS/boot_examples/index.html)
4. 最佳实践
请见[最佳实践指南](https://deepmodeling.github.io/Uni-Lab-OS/user_guide/best_practice.html)
## 消息格式
Uni-Lab-OS 使用预构建的 `unilabos_msgs` 进行系统通信。您可以在 [GitHub Releases](https://github.com/deepmodeling/Uni-Lab-OS/releases) 页面找到已构建的版本。
## 引用
如果您在学术研究中使用 Uni-Lab-OS请引用
如果您在学术研究中使用 [Uni-Lab-OS](https://arxiv.org/abs/2512.21766),请引用:
```bibtex
@article{gao2025unilabos,

View File

@@ -463,7 +463,7 @@ Uni-Lab 使用 `ResourceDictInstance.get_resource_instance_from_dict()` 方法
### 使用示例
```python
from unilabos.ros.nodes.resource_tracker import ResourceDictInstance
from unilabos.resources.resource_tracker import ResourceDictInstance
# 旧格式节点
old_format_node = {
@@ -477,10 +477,10 @@ old_format_node = {
instance = ResourceDictInstance.get_resource_instance_from_dict(old_format_node)
# 访问标准化后的数据
print(instance.res_content.id) # "pump_1"
print(instance.res_content.uuid) # 自动生成的 UUID
print(instance.res_content.id) # "pump_1"
print(instance.res_content.uuid) # 自动生成的 UUID
print(instance.res_content.config) # {}
print(instance.res_content.data) # {}
print(instance.res_content.data) # {}
```
### 格式迁移建议

View File

@@ -2,9 +2,8 @@ import pytest
import json
import os
from pylabrobot.resources import Resource as ResourcePLR
from unilabos.resources.graphio import resource_bioyond_to_plr
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet
from unilabos.resources.resource_tracker import ResourceTreeSet
from unilabos.registry.registry import lab_registry
from unilabos.resources.bioyond.decks import BIOYOND_PolymerReactionStation_Deck

View File

@@ -1,6 +1,6 @@
import threading
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet
from unilabos.resources.resource_tracker import ResourceTreeSet
from unilabos.utils import logger

View File

@@ -278,7 +278,7 @@ def main():
from unilabos.app.web import start_server
from unilabos.app.register import register_devices_and_resources
from unilabos.resources.graphio import modify_to_backend_format
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet, ResourceDict
from unilabos.resources.resource_tracker import ResourceTreeSet, ResourceDict
# 显示启动横幅
print_unilab_banner(args_dict)

View File

@@ -6,12 +6,10 @@ HTTP客户端模块
import json
import os
import time
from threading import Thread
from typing import List, Dict, Any, Optional
import requests
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet
from unilabos.resources.resource_tracker import ResourceTreeSet
from unilabos.utils.log import info
from unilabos.config.config import HTTPConfig, BasicConfig
from unilabos.utils import logger

View File

@@ -6,7 +6,7 @@ Coin Cell Assembly Workstation
"""
from typing import Dict, Any, List, Optional, Union
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker
from unilabos.resources.resource_tracker import DeviceNodeResourceTracker
from unilabos.device_comms.workstation_base import WorkstationBase, WorkflowInfo
from unilabos.device_comms.workstation_communication import (
WorkstationCommunicationBase, CommunicationConfig, CommunicationProtocol, CoinCellCommunication
@@ -61,7 +61,7 @@ class CoinCellAssemblyWorkstation(WorkstationBase):
# 创建资源跟踪器(如果没有提供)
if resource_tracker is None:
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker
from unilabos.resources.resource_tracker import DeviceNodeResourceTracker
resource_tracker = DeviceNodeResourceTracker()
# 初始化基类

View File

@@ -13,7 +13,7 @@ from pylabrobot.resources import (
import copy
from unilabos_msgs.msg import Resource
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker # type: ignore
from unilabos.resources.resource_tracker import DeviceNodeResourceTracker # type: ignore
class LiquidHandlerBiomek:

View File

@@ -13,7 +13,7 @@ from unilabos.config.config import BasicConfig
from unilabos.resources.container import RegularContainer
from unilabos.resources.itemized_carrier import ItemizedCarrier, BottleCarrier
from unilabos.ros.msgs.message_converter import convert_to_ros_msg
from unilabos.ros.nodes.resource_tracker import (
from unilabos.resources.resource_tracker import (
ResourceDictInstance,
ResourceTreeSet,
)

View File

@@ -149,6 +149,7 @@ class ItemizedCarrier(ResourcePLR):
if not reassign and self.sites[idx] is not None:
raise ValueError(f"a site with index {idx} already exists")
location = list(self.child_locations.values())[idx]
super().assign_child_resource(resource, location=location, reassign=reassign)
self.sites[idx] = resource

View File

@@ -14,9 +14,9 @@ if TYPE_CHECKING:
class ResourceDictPositionSize(BaseModel):
depth: float = Field(description="Depth", default=0.0)
width: float = Field(description="Width", default=0.0)
height: float = Field(description="Height", default=0.0)
depth: float = Field(description="Depth", default=0.0) # z
width: float = Field(description="Width", default=0.0) # x
height: float = Field(description="Height", default=0.0) # y
class ResourceDictPositionScale(BaseModel):
@@ -469,9 +469,9 @@ class ResourceTreeSet(object):
**res.config,
"name": res.name,
"type": res.config.get("type", plr_type),
"size_x": res.config.get("size_x", 0),
"size_y": res.config.get("size_y", 0),
"size_z": res.config.get("size_z", 0),
"size_x": res.pose.size.width,
"size_y": res.pose.size.height,
"size_z": res.pose.size.depth,
"location": {
"x": res.pose.position.x,
"y": res.pose.position.y,

View File

@@ -5,7 +5,7 @@ from unilabos.ros.msgs.message_converter import (
get_action_type,
)
from unilabos.ros.nodes.base_device_node import init_wrapper, ROS2DeviceNode
from unilabos.ros.nodes.resource_tracker import ResourceDictInstance
from unilabos.resources.resource_tracker import ResourceDictInstance
# 定义泛型类型变量
T = TypeVar("T")

View File

@@ -1,10 +1,9 @@
import copy
from typing import Optional
from unilabos.registry.registry import lab_registry
from unilabos.ros.device_node_wrapper import ros2_device_node
from unilabos.ros.nodes.base_device_node import ROS2DeviceNode, DeviceInitError
from unilabos.ros.nodes.resource_tracker import ResourceDictInstance
from unilabos.resources.resource_tracker import ResourceDictInstance
from unilabos.utils import logger
from unilabos.utils.exception import DeviceClassInvalid
from unilabos.utils.import_manager import default_manager

View File

@@ -10,7 +10,7 @@ from unilabos_msgs.srv._serial_command import SerialCommand_Response
from unilabos.app.register import register_devices_and_resources
from unilabos.ros.nodes.presets.resource_mesh_manager import ResourceMeshManager
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker, ResourceTreeSet
from unilabos.resources.resource_tracker import DeviceNodeResourceTracker, ResourceTreeSet
from unilabos.devices.ros_dev.liquid_handler_joint_publisher import LiquidHandlerJointPublisher
from unilabos_msgs.srv import SerialCommand # type: ignore
from rclpy.executors import MultiThreadedExecutor

View File

@@ -1,4 +1,3 @@
import copy
import inspect
import io
import json
@@ -13,7 +12,6 @@ import asyncio
import rclpy
import yaml
from msgcenterpy import ROS2MessageInstance
from rclpy.node import Node
from rclpy.action import ActionServer, ActionClient
from rclpy.action.server import ServerGoalHandle
@@ -26,11 +24,7 @@ from unilabos.utils.decorator import get_topic_config, get_all_subscriptions
from unilabos.resources.container import RegularContainer
from unilabos.resources.graphio import (
resource_ulab_to_plr,
initialize_resources,
dict_to_tree,
resource_plr_to_ulab,
tree_to_list,
)
from unilabos.resources.plr_additional_res_reg import register
from unilabos.ros.msgs.message_converter import (
@@ -47,7 +41,7 @@ from unilabos_msgs.srv import (
) # type: ignore
from unilabos_msgs.msg import Resource # type: ignore
from unilabos.ros.nodes.resource_tracker import (
from unilabos.resources.resource_tracker import (
DeviceNodeResourceTracker,
ResourceTreeSet,
ResourceTreeInstance,
@@ -363,7 +357,6 @@ class BaseROS2DeviceNode(Node, Generic[T]):
return res
async def append_resource(req: SerialCommand_Request, res: SerialCommand_Response):
from pylabrobot.resources.resource import Resource as ResourcePLR
from pylabrobot.resources.deck import Deck
from pylabrobot.resources import Coordinate
from pylabrobot.resources import Plate
@@ -851,6 +844,16 @@ class BaseROS2DeviceNode(Node, Generic[T]):
and original_parent_resource is not None
):
self.transfer_to_new_resource(original_instance, tree, additional_add_params)
else:
# 判断是否变更了resource_site
target_site = original_instance.unilabos_extra.get("update_resource_site")
sites = original_instance.parent.sites if original_instance.parent is not None and hasattr(original_instance.parent, "sites") else None
site_names = list(original_instance.parent._ordering.keys()) if original_instance.parent is not None and hasattr(original_instance.parent, "sites") else []
if target_site is not None and sites is not None and site_names is not None:
site_index = sites.index(original_instance)
site_name = site_names[site_index]
if site_name != target_site:
self.transfer_to_new_resource(original_instance, tree, additional_add_params)
# 加载状态
original_instance.load_all_state(states)
@@ -888,6 +891,13 @@ class BaseROS2DeviceNode(Node, Generic[T]):
raise ValueError("tree_set不能为None")
plr_resources = tree_set.to_plr_resources()
result = _handle_add(plr_resources, tree_set, additional_add_params)
new_tree_set = ResourceTreeSet.from_plr_resources(plr_resources)
r = SerialCommand.Request()
r.command = json.dumps(
{"data": {"data": new_tree_set.dump()}, "action": "update"}) # 和Update Resource一致
response: SerialCommand_Response = await self._resource_clients[
"c2s_update_resource_tree"].call_async(r) # type: ignore
self.lab_logger().info(f"确认资源云端 Add 结果: {response.response}")
results.append(result)
elif action == "update":
if tree_set is None:
@@ -898,7 +908,14 @@ class BaseROS2DeviceNode(Node, Generic[T]):
plr_resources.append(tree.root_node)
else:
plr_resources.append(ResourceTreeSet([tree]).to_plr_resources()[0])
new_tree_set = ResourceTreeSet.from_plr_resources(plr_resources)
result = _handle_update(plr_resources, tree_set, additional_add_params)
r = SerialCommand.Request()
r.command = json.dumps(
{"data": {"data": new_tree_set.dump()}, "action": "update"}) # 和Update Resource一致
response: SerialCommand_Response = await self._resource_clients[
"c2s_update_resource_tree"].call_async(r) # type: ignore
self.lab_logger().info(f"确认资源云端 Update 结果: {response.response}")
results.append(result)
elif action == "remove":
result = _handle_remove(resources_uuid)
@@ -1765,6 +1782,7 @@ class ROS2DeviceNode:
or driver_class.__name__ == "LiquidHandlerBiomek"
or driver_class.__name__ == "PRCXI9300Handler"
or driver_class.__name__ == "TransformXYZHandler"
or driver_class.__name__ == "OpcUaClient"
)
# 创建设备类实例

View File

@@ -10,7 +10,6 @@ from typing import TYPE_CHECKING, Optional, Dict, Any, List, ClassVar, Set, Type
from action_msgs.msg import GoalStatus
from geometry_msgs.msg import Point
from rclpy.action import ActionClient, get_action_server_names_and_types_by_node
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.service import Service
from unilabos_msgs.msg import Resource # type: ignore
from unilabos_msgs.srv import (
@@ -19,7 +18,6 @@ from unilabos_msgs.srv import (
ResourceUpdate,
ResourceList,
SerialCommand,
ResourceGet,
) # type: ignore
from unilabos_msgs.srv._serial_command import SerialCommand_Request, SerialCommand_Response
from unique_identifier_msgs.msg import UUID
@@ -37,7 +35,7 @@ from unilabos.ros.msgs.message_converter import (
)
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode, ROS2DeviceNode, DeviceNodeResourceTracker
from unilabos.ros.nodes.presets.controller_node import ControllerNode
from unilabos.ros.nodes.resource_tracker import (
from unilabos.resources.resource_tracker import (
ResourceDict,
ResourceDictInstance,
ResourceTreeSet,

View File

@@ -12,11 +12,10 @@ from unilabos_msgs.srv import ResourceUpdate
from unilabos.messages import * # type: ignore # protocol names
from rclpy.action import ActionServer, ActionClient
from rclpy.action.server import ServerGoalHandle
from rclpy.callback_groups import ReentrantCallbackGroup
from unilabos_msgs.srv._serial_command import SerialCommand_Request, SerialCommand_Response
from unilabos.compile import action_protocol_generators
from unilabos.resources.graphio import list_to_nested_dict, nested_dict_to_list
from unilabos.resources.graphio import nested_dict_to_list
from unilabos.ros.initialize_device import initialize_device_from_dict
from unilabos.ros.msgs.message_converter import (
get_action_type,
@@ -24,7 +23,7 @@ from unilabos.ros.msgs.message_converter import (
convert_from_ros_msg_with_mapping,
)
from unilabos.ros.nodes.base_device_node import BaseROS2DeviceNode, DeviceNodeResourceTracker, ROS2DeviceNode
from unilabos.ros.nodes.resource_tracker import ResourceTreeSet, ResourceDictInstance
from unilabos.resources.resource_tracker import ResourceTreeSet, ResourceDictInstance
from unilabos.utils.type_check import get_result_info_str
if TYPE_CHECKING:

View File

@@ -11,10 +11,9 @@ import traceback
from abc import abstractmethod
from typing import Type, Any, Dict, Optional, TypeVar, Generic, List
from unilabos.resources.graphio import nested_dict_to_list, resource_ulab_to_plr
from unilabos.ros.nodes.resource_tracker import DeviceNodeResourceTracker, ResourceTreeSet, ResourceDictInstance, \
from unilabos.resources.resource_tracker import DeviceNodeResourceTracker, ResourceTreeSet, ResourceDictInstance, \
ResourceTreeInstance
from unilabos.utils import logger, import_manager
from unilabos.utils import logger
from unilabos.utils.cls_creator import create_instance_from_config
# 定义泛型类型变量
@@ -135,7 +134,7 @@ class PyLabRobotCreator(DeviceClassCreator[T]):
Returns:
处理后的数据
"""
from pylabrobot.resources import Deck, Resource
from pylabrobot.resources import Resource
if states is None:
states = {}