From 19f428670ee1ddb9846485e23649fb29d873beca Mon Sep 17 00:00:00 2001 From: kwangneuraco Date: Fri, 20 Feb 2026 15:13:34 +0000 Subject: [PATCH] feat: add docs on examples and delete the no_robot --- examples/example_data_collection_bigym.py | 3 + examples/example_data_collection_vx300s.py | 3 + examples/example_launch_training.py | 3 + examples/example_local_endpoint_bigym.py | 3 + examples/example_local_endpoint_no_robot.py | 150 ------------------ ...nt.py => example_local_endpoint_vx300s.py} | 3 + examples/example_retrieve_dataset.py | 3 + examples/example_server_endpoint.py | 3 + 8 files changed, 21 insertions(+), 150 deletions(-) delete mode 100644 examples/example_local_endpoint_no_robot.py rename examples/{example_local_endpoint.py => example_local_endpoint_vx300s.py} (97%) diff --git a/examples/example_data_collection_bigym.py b/examples/example_data_collection_bigym.py index 0c8aa085..57439548 100644 --- a/examples/example_data_collection_bigym.py +++ b/examples/example_data_collection_bigym.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can collect data from a Bigym environment +and record it to Neuracore.""" + import argparse import time diff --git a/examples/example_data_collection_vx300s.py b/examples/example_data_collection_vx300s.py index 646308e7..51da710f 100644 --- a/examples/example_data_collection_vx300s.py +++ b/examples/example_data_collection_vx300s.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can collect data from a VX300s environment +and record it to Neuracore.""" + import argparse import time diff --git a/examples/example_launch_training.py b/examples/example_launch_training.py index 1e7f3a55..615f15c4 100644 --- a/examples/example_launch_training.py +++ b/examples/example_launch_training.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can launch a training job +from the Neuracore platform.""" + import argparse from common.base_env import BimanualViperXTask diff --git a/examples/example_local_endpoint_bigym.py b/examples/example_local_endpoint_bigym.py index 5d16a47b..ab9b3b1f 100644 --- a/examples/example_local_endpoint_bigym.py +++ b/examples/example_local_endpoint_bigym.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can run a local policy rollout +in a Bigym environment using Neuracore.""" + import argparse import time from typing import Any, cast diff --git a/examples/example_local_endpoint_no_robot.py b/examples/example_local_endpoint_no_robot.py deleted file mode 100644 index 996571b7..00000000 --- a/examples/example_local_endpoint_no_robot.py +++ /dev/null @@ -1,150 +0,0 @@ -from typing import cast - -import matplotlib.pyplot as plt -import torch -from common.base_env import BimanualViperXTask -from common.transfer_cube import BOX_POSE, make_sim_env -from neuracore_types import ( - BatchedJointData, - BatchedNCData, - DataSpec, - DataType, - JointData, - RGBCameraData, - SynchronizedPoint, -) - -import neuracore as nc - -TRAINING_JOB_NAME = "MyTrainingJob" -ROBOT_NAME = "Mujoco VX300s" -CAMERA_NAMES = ["angle"] - -# Specification of the order that will be fed into the model -MODEL_INPUT_ORDER: DataSpec = { - DataType.JOINT_POSITIONS: ( - BimanualViperXTask.LEFT_ARM_JOINT_NAMES - + BimanualViperXTask.LEFT_GRIPPER_JOINT_NAMES - + BimanualViperXTask.RIGHT_ARM_JOINT_NAMES - + BimanualViperXTask.RIGHT_GRIPPER_JOINT_NAMES - ), - DataType.RGB_IMAGES: CAMERA_NAMES, -} - -MODEL_OUTPUT_ORDER: DataSpec = { - DataType.JOINT_TARGET_POSITIONS: BimanualViperXTask.ACTION_KEYS, -} - - -def main(): - # If you know the path to the local model.nc.zip file - # you can use it directly without connecting to a robot - policy = nc.policy( - model_file="PATH/TO/MODEL.nc.zip", - model_input_order=MODEL_INPUT_ORDER, - model_output_order=MODEL_OUTPUT_ORDER, - ) - - # Optional. Set the checkpoint to the last epoch. - # Note by default, model is loaded from the last epoch. - # policy.set_checkpoint(epoch=-1) - - onscreen_render = True - render_cam_name = CAMERA_NAMES[0] - num_rollouts = 10 - - for episode_idx in range(num_rollouts): - print(f"{episode_idx=}") - - # Setup the environment - env = make_sim_env() - # resample the initial cube pose - BOX_POSE[0] = env.sample_box_pose() - obs = env.reset() - - # Setup plotting - if onscreen_render: - ax = plt.subplot() - plt_img = ax.imshow(obs.cameras[render_cam_name].rgb) - plt.ion() - - horizon = 1 - # Run episode - for i in range(400): - # Create a sync point manually without logging data to the robot - SynchronizedPoint( - data={ - DataType.JOINT_POSITIONS: { - k: JointData(value=v) for k, v in obs.qpos.items() - }, - DataType.RGB_IMAGES: { - render_cam_name: RGBCameraData( - frame=obs.cameras[render_cam_name].rgb - ), - }, - } - ) - - idx_in_horizon = i % horizon - if idx_in_horizon == 0: - predictions: dict[DataType, dict[str, BatchedNCData]] = policy.predict( - timeout=5 - ) - joint_target_positions = cast( - dict[str, BatchedJointData], - predictions[DataType.JOINT_TARGET_POSITIONS], - ) - left_arm = torch.cat( - [ - joint_target_positions[name].value - for name in BimanualViperXTask.LEFT_ARM_JOINT_NAMES - ], - dim=2, - ) - right_arm = torch.cat( - [ - joint_target_positions[name].value - for name in BimanualViperXTask.RIGHT_ARM_JOINT_NAMES - ], - dim=2, - ) - left_open_amount = joint_target_positions[ - BimanualViperXTask.LEFT_GRIPPER_OPEN - ].value - right_open_amount = joint_target_positions[ - BimanualViperXTask.RIGHT_GRIPPER_OPEN - ].value - batched_action = ( - torch.cat( - [left_arm, left_open_amount, right_arm, right_open_amount], - dim=2, - ) - .cpu() - .numpy() - ) - # Get first batch: (horizon, num_joints) - mj_action = batched_action[0] - horizon = len(mj_action) - - a = mj_action[idx_in_horizon] - obs, reward, done = env.step(a) - - if onscreen_render: - plt_img.set_data(obs.cameras[render_cam_name].rgb) - plt.pause(0.002) - - if done: - print(f"Episode {episode_idx} done") - break - if reward == 4: - print(f"Episode {episode_idx} successful.") - else: - print(f"Episode {episode_idx} failed.") - - plt.close() - - policy.disconnect() - - -if __name__ == "__main__": - main() diff --git a/examples/example_local_endpoint.py b/examples/example_local_endpoint_vx300s.py similarity index 97% rename from examples/example_local_endpoint.py rename to examples/example_local_endpoint_vx300s.py index 9b539933..9b798c51 100644 --- a/examples/example_local_endpoint.py +++ b/examples/example_local_endpoint_vx300s.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can run a local policy rollout +in a VX300s environment using Neuracore.""" + from typing import cast import matplotlib.pyplot as plt diff --git a/examples/example_retrieve_dataset.py b/examples/example_retrieve_dataset.py index 6696f0be..85f06883 100644 --- a/examples/example_retrieve_dataset.py +++ b/examples/example_retrieve_dataset.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can retrieve a dataset +from the Neuracore platform and visualize it.""" + from typing import cast import matplotlib.animation as animation diff --git a/examples/example_server_endpoint.py b/examples/example_server_endpoint.py index 21d27423..bc0445d0 100644 --- a/examples/example_server_endpoint.py +++ b/examples/example_server_endpoint.py @@ -1,3 +1,6 @@ +"""This example demonstrates how you can start an endpoint on the cloud +and locally run the robot using the endpoint.""" + import sys from typing import cast