# yuanfengjeff/ipec architecture

> Architecture diagram of the GitHub repository yuanfengjeff/ipec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuanfengjeff/ipec
- Repository: https://github.com/yuanfengjeff/ipec

## Overview

1. **What this repository is**
   `ipec` is an integration layer for running OpenPI-style robot policy inference on ARX dual-arm systems. The repo is organized around two execution patterns: a **split-process GMP setup** and **single-process direct inference scripts**. The main architectural concern is moving data between robot observation sources, policy inference backends, and action execution endpoints.

2. **Two robot backends define the main hardware boundary**
   The code targets two different robot stacks:
   - **Acone / ROS2**: observation and control are handled locally through `utils.DualArmCollector` and ROS2 message/control APIs.
   - **Lift2 / Noetic**: control is built around Mobile Aloha / RosOperator style tooling from the `lijinarui/ARX_Play/mobile_aloha` workspace.
   
   This is the biggest boundary in the repo: the same policy interface is adapted to two robot runtime environments with different middleware and state sources.

3. **Robot service layer: the GMP HTTP services**
   `gmp_service_acone.py`, `gmp_service_lift2.py`, and `gmp_service_xdeploy.py` are the robot-facing servers. They expose HTTP endpoints for:
   - reading observations,
   - starting/resetting robot sessions,
   - stepping actions,
   - and legacy GenManip/GMP-compatible routes.
   
   Architecturally, these services isolate low-level robot access behind a simple request/response API so the policy pipeline can run elsewhere, even on another machine.

4. **Pipeline layer: observation → policy → action**
   `gmp_pipeline_acone.py` and `gmp_pipeline_lift2.py` are the main orchestration scripts. Their job is to:
   - fetch observations from the robot service,
   - transform them into the OpenPI input schema,
   - send them to a policy server,
   - receive an action horizon,
   - and execute a chosen prefix of that horizon back through the GMP service.
   
   This is the core runtime loop of the repo and the clearest place to draw the system’s end-to-end data flow.

5. **Direct inference scripts collapse the pipeline into one process**
   The `pi_infer_*.py` files run the same logical loop without the split service boundary. They combine local observation collection, policy inference, and action execution in a single Python process. These are useful for simpler deployments, timing experiments, or robot setups where the policy server is local and the control path does not need to be distributed.

6. **Policy backend: OpenPI WebSocket protocol**
   The policy side is accessed through the vendored `openpi-client` package and the `pi_infer_*` scripts. The policy server is treated as a WebSocket endpoint that returns action chunks, not as a robot-specific control service. This keeps policy inference independent from robot middleware and makes the robot-specific code mostly an adapter layer.

7. **Mock policy server for integration testing**
   `pi_infer_service_mockup.py` provides a local WebSocket-compatible policy server for wiring tests. It produces a fixed-horizon action output from current observations, which makes it useful for validating transport, schema conversion, and robot-service connectivity before connecting a real model.

8. **Zenoh/RIO is an alternate transport path**
   The `zenoh_*.py` scripts represent a parallel transport stack that talks to a Zenoh/RIO-based runtime instead of the OpenPI WebSocket client. These are not the primary path in the README, but they form a second integration boundary for deployments that use Zenoh messaging infrastructure rather than direct WebSocket inference.

9. **Vendored `openpi-client` is the policy-runtime adapter**
   The `openpi-client/` subtree is a lightweight local dependency that contains:
   - WebSocket policy client logic,
   - runtime/agent/environment abstractions,
   - action chunk handling,
   - image preprocessing,
   - and msgpack-numpy serialization helpers.
   
   Its role is to normalize OpenPI communication and hide transport details from the repo’s pipeline scripts. It is effectively the policy I/O adapter layer.

10. **Data model and action conventions are shared across all paths**
   The repo standardizes observations into OpenPI-style fields such as:
   - RGB images for head and wrist cameras,
   - joint positions and gripper positions,
   - and a prompt/task string.
   
   Actions are expected as a 14-value dual-arm command: left arm joints + gripper, then right arm joints + gripper. Control mode selection is also explicit, with joint-position and end-effector styles mapped differently. This schema conversion is a key architectural responsibility of the pipeline code.

11. **The main control flow is chunked and latency-sensitive**
   The policy typically returns a horizon of actions, but the pipeline may only execute a prefix of that chunk before querying again. That design is important because it decouples policy inference frequency from robot execution frequency and allows the pipeline to handle latency, safety limits, and partial commitment to predicted actions.

12. **External dependencies define the deployment environment**
   The repo assumes a robotics workspace with ROS2 for Acone, ROS1/Noetic and Mobile Aloha dependencies for Lift2, plus networking/serialization libraries such as `requests`, `websockets`, `opencv-python`, `zenoh`, and `msgpack-numpy`. These dependencies matter architecturally because they determine which runtime can host which entrypoint and how the observation/action transport is implemented.

Main entry points: [`openpi-client/src/openpi_client/websocket_client_policy.py`](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/websocket_client_policy.py) (WebSocket client), [`zenoh_policy_client.py`](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_policy_client.py) (Zenoh client), [`gmp_service_acone.py`](https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_acone.py) (Acone service), [`gmp_service_lift2.py`](https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_lift2.py) (Lift2 service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_robot_services["Robot services"]
  node_gmp_service_acone["Acone service<br/>ROS2 GMP server"]
  node_gmp_service_lift2["Lift2 service<br/>Noetic GMP server"]
  node_gmp_service_xdeploy["Xdeploy service<br/>Legacy GMP server"]
end

subgraph group_pipelines["Pipelines"]
  node_gmp_pipeline_acone["Acone pipeline<br/>Split-process loop"]
  node_gmp_pipeline_lift2["Lift2 pipeline<br/>Split-process loop"]
end

subgraph group_direct_infer["Direct inference"]
  node_pi_infer_sync["Sync infer<br/>Single-process loop<br/>[pi_infer_sync.py]"]
  node_pi_infer_async_630["Async infer<br/>Single-process loop"]
  node_pi_infer_rtc_630["RTC infer<br/>Single-process RTC"]
  node_pi_infer_sync_acone["Acone direct"]
  node_pi_infer_sync_lift2["Lift2 direct"]
  node_pi_infer_service_mockup["Mock policy<br/>WebSocket mock"]
end

subgraph group_policy_runtime["Policy runtime"]
  node_openpi_client_websocket["WebSocket client<br/>Policy client"]
  node_openpi_runtime["Runtime core<br/>Agent/runtime<br/>[runtime.py]"]
  node_openpi_policy_agent["Policy agent<br/>Agent wrapper<br/>[policy_agent.py]"]
  node_openpi_action_chunk["Action chunks<br/>Chunk broker"]
  node_openpi_msgpack["Msgpack codec<br/>Serialization<br/>[msgpack_numpy.py]"]
  node_openpi_images["Image tools<br/>Preprocessing<br/>[image_tools.py]"]
end

subgraph group_zenoh["Zenoh path"]
  node_zenoh_pipeline_acone["Zenoh Acone<br/>Zenoh pipeline"]
  node_zenoh_pipeline_acone_async["Zenoh async<br/>Zenoh pipeline"]
  node_zenoh_pipeline_lift2_async["Zenoh Lift2<br/>Zenoh pipeline"]
  node_zenoh_pi_infer_rtc["Zenoh RTC<br/>Zenoh infer"]
  node_zenoh_policy_client["Zenoh client<br/>Transport client"]
  node_zenoh_policy_dist["Zenoh dist<br/>Transport runtime"]
end

node_gmp_pipeline_acone -->|"obs/actions"| node_gmp_service_acone
node_gmp_pipeline_lift2 -->|"obs/actions"| node_gmp_service_lift2
node_gmp_service_acone -->|"policy call"| node_openpi_client_websocket
node_gmp_service_lift2 -->|"policy call"| node_openpi_client_websocket
node_pi_infer_sync -->|"policy call"| node_openpi_client_websocket
node_pi_infer_async_630 -->|"policy call"| node_openpi_client_websocket
node_pi_infer_rtc_630 -->|"runtime"| node_openpi_runtime
node_pi_infer_sync_acone -->|"control"| node_gmp_service_acone
node_pi_infer_sync_lift2 -->|"control"| node_gmp_service_lift2
node_pi_infer_service_mockup -->|"mock policy"| node_openpi_client_websocket
node_openpi_client_websocket -->|"chunks"| node_openpi_action_chunk
node_openpi_runtime -->|"agent"| node_openpi_policy_agent
node_openpi_policy_agent -->|"infer"| node_openpi_client_websocket
node_openpi_client_websocket -->|"serialize"| node_openpi_msgpack
node_openpi_client_websocket -->|"preprocess"| node_openpi_images
node_gmp_pipeline_acone -->|"policy backend"| node_openpi_client_websocket
node_gmp_pipeline_lift2 -->|"policy backend"| node_openpi_client_websocket
node_zenoh_pipeline_acone -->|"transport"| node_zenoh_policy_client
node_zenoh_pipeline_acone_async -->|"transport"| node_zenoh_policy_client
node_zenoh_pipeline_lift2_async -->|"transport"| node_zenoh_policy_client
node_zenoh_pi_infer_rtc -->|"runtime"| node_zenoh_policy_dist
node_zenoh_policy_dist -->|"client"| node_zenoh_policy_client
node_gmp_service_xdeploy -.->|"compat"| node_openpi_client_websocket

click node_gmp_service_acone "https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_acone.py"
click node_gmp_service_lift2 "https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_lift2.py"
click node_gmp_service_xdeploy "https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_xdeploy.py"
click node_gmp_pipeline_acone "https://github.com/yuanfengjeff/ipec/blob/master/gmp_pipeline_acone.py"
click node_gmp_pipeline_lift2 "https://github.com/yuanfengjeff/ipec/blob/master/gmp_pipeline_lift2.py"
click node_pi_infer_sync "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync.py"
click node_pi_infer_async_630 "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_async_630.py"
click node_pi_infer_rtc_630 "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_rtc_630.py"
click node_pi_infer_sync_acone "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync_acone.py"
click node_pi_infer_sync_lift2 "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync_lift2.py"
click node_pi_infer_service_mockup "https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_service_mockup.py"
click node_openpi_client_websocket "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/websocket_client_policy.py"
click node_openpi_runtime "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/runtime/runtime.py"
click node_openpi_policy_agent "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/runtime/agents/policy_agent.py"
click node_openpi_action_chunk "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/action_chunk_broker.py"
click node_openpi_msgpack "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/msgpack_numpy.py"
click node_openpi_images "https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/image_tools.py"
click node_zenoh_pipeline_acone "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_acone.py"
click node_zenoh_pipeline_acone_async "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_acone_async.py"
click node_zenoh_pipeline_lift2_async "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_lift2_async.py"
click node_zenoh_pi_infer_rtc "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pi_infer_rtc.py"
click node_zenoh_policy_client "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_policy_client.py"
click node_zenoh_policy_dist "https://github.com/yuanfengjeff/ipec/blob/master/zenoh_policy_dist.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_gmp_service_acone,node_gmp_service_lift2,node_gmp_service_xdeploy toneBlue
class node_gmp_pipeline_acone,node_gmp_pipeline_lift2 toneAmber
class node_pi_infer_sync,node_pi_infer_async_630,node_pi_infer_rtc_630,node_pi_infer_sync_acone,node_pi_infer_sync_lift2,node_pi_infer_service_mockup toneMint
class node_openpi_client_websocket,node_openpi_runtime,node_openpi_policy_agent,node_openpi_action_chunk,node_openpi_msgpack,node_openpi_images toneRose
class node_zenoh_pipeline_acone,node_zenoh_pipeline_acone_async,node_zenoh_pipeline_lift2_async,node_zenoh_pi_infer_rtc,node_zenoh_policy_client,node_zenoh_policy_dist toneIndigo
```

## Components

### Robot services

HTTP-facing robot adapters for different hardware and middleware stacks.

- [Acone service](https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_acone.py): ROS2 GMP server · Robot-facing HTTP service for the Acone/ROS2 dual-arm stack. · `gmp_service_acone.py`
- [Lift2 service](https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_lift2.py): Noetic GMP server · Robot-facing HTTP service for the Lift2 / Mobile Aloha / ROS1 stack. · `gmp_service_lift2.py`
- [Xdeploy service](https://github.com/yuanfengjeff/ipec/blob/master/gmp_service_xdeploy.py): Legacy GMP server · Compatibility service exposing GenManip/GMP-style robot endpoints. · `gmp_service_xdeploy.py`

### Pipelines

Split-process orchestration that bridges robot state, policy inference, and action execution.

- [Acone pipeline](https://github.com/yuanfengjeff/ipec/blob/master/gmp_pipeline_acone.py): Split-process loop · Fetches observations from the Acone service, calls policy inference, and executes action prefixes. · `gmp_pipeline_acone.py`
- [Lift2 pipeline](https://github.com/yuanfengjeff/ipec/blob/master/gmp_pipeline_lift2.py): Split-process loop · Fetches observations from the Lift2 service, calls policy inference, and executes action prefixes. · `gmp_pipeline_lift2.py`

### Direct inference

Single-process loops that combine observation, policy, and control.

- [Sync infer](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync.py): Single-process loop · Direct policy inference and action execution in one process. · `pi_infer_sync.py`
- [Async infer](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_async_630.py): Single-process loop · Asynchronous direct inference path for robot control and timing-sensitive execution. · `pi_infer_async_630.py`
- [RTC infer](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_rtc_630.py): Single-process RTC · Direct inference entrypoint using runtime/RTC-style coordination. · `pi_infer_rtc_630.py`
- [Acone direct](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync_acone.py): Acone direct loop · Direct inference path specialized for the Acone/ROS2 stack. · `pi_infer_sync_acone.py`
- [Lift2 direct](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_sync_lift2.py): Lift2 direct loop · Direct inference path specialized for the Lift2/Noetic stack. · `pi_infer_sync_lift2.py`
- [Mock policy](https://github.com/yuanfengjeff/ipec/blob/master/pi_infer_service_mockup.py): WebSocket mock · Local mock policy server for integration and transport validation. · `pi_infer_service_mockup.py`

### Policy runtime

Vendored OpenPI client and shared policy/runtime abstractions.

- [WebSocket client](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/websocket_client_policy.py): Policy client · OpenPI WebSocket client that exchanges observations for action chunks. · `openpi-client/src/openpi_client/websocket_client_policy.py`
- [Runtime core](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/runtime/runtime.py): Agent/runtime · Core runtime, agent, and environment abstractions for policy execution. · `openpi-client/src/openpi_client/runtime/runtime.py`
- [Policy agent](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/runtime/agents/policy_agent.py): Agent wrapper · Agent wrapper coordinating policy calls inside the runtime. · `openpi-client/src/openpi_client/runtime/agents/policy_agent.py`
- [Action chunks](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/action_chunk_broker.py): Chunk broker · Handles horizon chunks and prefix selection for execution. · `openpi-client/src/openpi_client/action_chunk_broker.py`
- [Msgpack codec](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/msgpack_numpy.py): Serialization · Msgpack-numpy helpers used to serialize observations and actions. · `openpi-client/src/openpi_client/msgpack_numpy.py`
- [Image tools](https://github.com/yuanfengjeff/ipec/blob/master/openpi-client/src/openpi_client/image_tools.py): Preprocessing · Image preprocessing utilities used before policy submission. · `openpi-client/src/openpi_client/image_tools.py`

### Zenoh path

Alternate transport and inference path using Zenoh/RIO-style messaging.

- [Zenoh Acone](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_acone.py): Zenoh pipeline · Acone pipeline variant using Zenoh-based transport. · `zenoh_pipeline_acone.py`
- [Zenoh async](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_acone_async.py): Zenoh pipeline · Asynchronous Acone Zenoh pipeline variant. · `zenoh_pipeline_acone_async.py`
- [Zenoh Lift2](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pipeline_lift2_async.py): Zenoh pipeline · Lift2 Zenoh pipeline variant using asynchronous transport. · `zenoh_pipeline_lift2_async.py`
- [Zenoh RTC](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_pi_infer_rtc.py): Zenoh infer · Zenoh/RIO inference entrypoint for RTC-style runtime coordination. · `zenoh_pi_infer_rtc.py`
- [Zenoh client](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_policy_client.py): Transport client · Policy-side client for Zenoh/RIO communication. · `zenoh_policy_client.py`
- [Zenoh dist](https://github.com/yuanfengjeff/ipec/blob/master/zenoh_policy_dist.py): Transport runtime · Distributed Zenoh policy runtime and transport coordination. · `zenoh_policy_dist.py`

## Connections

- Acone pipeline → Acone service: obs/actions · Reads robot observations and sends action steps through the Acone service.
- Lift2 pipeline → Lift2 service: obs/actions · Reads robot observations and sends action steps through the Lift2 service.
- Acone service → WebSocket client: policy call · Forwards normalized observations to the OpenPI policy client path.
- Lift2 service → WebSocket client: policy call · Forwards normalized observations to the OpenPI policy client path.
- Sync infer → WebSocket client: policy call · Single-process direct inference uses the OpenPI WebSocket client.
- Async infer → WebSocket client: policy call · Asynchronous direct inference uses the OpenPI WebSocket client.
- RTC infer → Runtime core: runtime · RTC-style entrypoint builds on the OpenPI runtime abstractions.
- Acone direct → Acone service: control · Specialized direct loop for the Acone robot stack.
- Lift2 direct → Lift2 service: control · Specialized direct loop for the Lift2 robot stack.
- Mock policy → WebSocket client: mock policy · Implements a WebSocket-compatible mock policy endpoint for integration tests.
- WebSocket client → Action chunks: chunks · Receives action horizons and exposes chunk selection for execution.
- Runtime core → Policy agent: agent · Runtime delegates policy execution to an agent wrapper.
- Policy agent → WebSocket client: infer · Agent invokes the WebSocket policy backend.
- WebSocket client → Msgpack codec: serialize · Uses msgpack-numpy encoding for transport payloads.
- WebSocket client → Image tools: preprocess · Applies image preprocessing before policy submission.
- Acone pipeline → WebSocket client: policy backend · Split-process Acone pipeline depends on the OpenPI policy client.
- Lift2 pipeline → WebSocket client: policy backend · Split-process Lift2 pipeline depends on the OpenPI policy client.
- Zenoh Acone → Zenoh client: transport · Acone Zenoh pipeline uses the Zenoh policy client.
- Zenoh async → Zenoh client: transport · Async Acone Zenoh pipeline uses the Zenoh policy client.
- Zenoh Lift2 → Zenoh client: transport · Async Lift2 Zenoh pipeline uses the Zenoh policy client.
- Zenoh RTC → Zenoh dist: runtime · RTC-style Zenoh inference uses the distributed Zenoh runtime.
- Zenoh dist → Zenoh client: client · Distributed Zenoh runtime relies on the transport client.
- Xdeploy service → WebSocket client: compat · Legacy GMP-compatible service can forward policy requests through the OpenPI client path.
