### Newton Installation with Examples Extra Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Install Newton with the 'examples' extra to include dependencies for running built-in simulation and visualization examples. ```console pip install "newton[examples]" ``` -------------------------------- ### Get Help for a Specific Example Source: https://github.com/newton-physics/newton/blob/main/README.md Run this command to see all available command-line options for a particular example, including any example-specific arguments. ```bash python -m newton.examples --help ``` -------------------------------- ### Run Default Basic Pendulum Example Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Launch the default 'basic_pendulum' example after installing Newton with the 'examples' extra. ```console python -m newton.examples ``` -------------------------------- ### Run Example by Name (uv) Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Executes a specific example by its short name using the 'uv' environment manager. Replace 'basic_pendulum' with your desired example name. ```console uv run -m newton.examples basic_pendulum ``` -------------------------------- ### Run Recording Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the recording example. This likely demonstrates how to record simulation data. ```bash python -m newton.examples recording ``` -------------------------------- ### List Examples with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst List available examples in the project using uv run command. ```console uv run -m newton.examples --list ``` -------------------------------- ### Run Basic Viewer Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic viewer example. This likely demonstrates visualization capabilities. ```bash python -m newton.examples basic_viewer ``` -------------------------------- ### List Available Examples Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Display a list of all available examples that can be run with the Newton library. ```console python -m newton.examples --list ``` -------------------------------- ### List Available Newton Examples Source: https://github.com/newton-physics/newton/blob/main/README.md Use this command to get a list of all runnable examples within the Newton physics library. ```bash # List available examples python -m newton.examples --list ``` -------------------------------- ### Run Basic Pendulum Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic pendulum simulation example. This demonstrates a simple physics setup. ```bash python -m newton.examples basic_pendulum ``` -------------------------------- ### Run Replay Viewer Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the replay viewer example. This demonstrates how to replay previously recorded simulation data. ```bash python -m newton.examples replay_viewer ``` -------------------------------- ### Run Example with Combined Options Source: https://github.com/newton-physics/newton/blob/main/README.md Shows how to combine multiple command-line options to configure an example's viewer, frame count, and compute device. ```bash # Combine options python -m newton.examples basic_viewer --viewer gl --num-frames 500 --device cpu ``` -------------------------------- ### Install PyTorch for CUDA 12.x and Run RL Example Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Install Newton with the 'torch-cu12' extra and PyTorch for CUDA 12.8, then run the 'robot_anymal_c_walk' RL inference example. ```console pip install newton[torch-cu12] --extra-index-url https://download.pytorch.org/whl/cu128 python -m newton.examples robot_anymal_c_walk ``` -------------------------------- ### Basic Newton Installation Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Install the core Newton library using pip. ```console pip install newton ``` -------------------------------- ### Run Example with USD Viewer and Custom Output Source: https://github.com/newton-physics/newton/blob/main/README.md Execute an example using the USD viewer and specify a custom output file path for the generated USD data. ```bash # Run with the USD viewer and save to my_output.usd python -m newton.examples basic_viewer --viewer usd --output-path my_output.usd ``` -------------------------------- ### Run Newton Examples Source: https://github.com/newton-physics/newton/blob/main/AGENTS.md Synchronizes dependencies and runs a basic pendulum example using the 'uv' package manager. ```bash uv sync --extra examples uv run -m newton.examples basic_pendulum ``` -------------------------------- ### Run Selection Materials Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the selection materials example. This showcases the selection of different materials within a simulation. ```bash python -m newton.examples selection_materials ``` -------------------------------- ### Run Basic Plotting Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic plotting example. This demonstrates how to visualize simulation data. ```bash python -m newton.examples basic_plotting ``` -------------------------------- ### Run Selection Articulations Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the selection articulations example. This demonstrates the selection of articulated components in a simulation. ```bash python -m newton.examples selection_articulations ``` -------------------------------- ### Quick Start: Basic Shapes Simulation Source: https://github.com/newton-physics/newton/blob/main/docs/concepts/collisions.rst A minimal end-to-end example demonstrating shape creation, collision detection, and solver stepping for a dynamic sphere falling on a ground plane. ```python import warp as wp import newton builder = newton.ModelBuilder() builder.add_ground_plane() # Dynamic sphere body = builder.add_body(xform=wp.transform((0.0, 0.0, 2.0), wp.quat_identity())) builder.add_shape_sphere(body, radius=0.5) model = builder.finalize() solver = newton.solvers.SolverXPBD(model, iterations=5) state_0 = model.state() state_1 = model.state() control = model.control() contacts = model.contacts() dt = 1.0 / 60.0 / 10.0 for frame in range(120): for substep in range(10): state_0.clear_forces() model.collide(state_0, contacts) solver.step(state_0, state_1, control, contacts, dt) state_0, state_1 = state_1, state_0 ``` -------------------------------- ### Colab Setup for Newton Installation Source: https://github.com/newton-physics/newton/blob/main/docs/tutorials/00_introduction.ipynb Installs the Newton library with notebook support if running in a Google Colab environment. This ensures all necessary dependencies are available for the tutorial. ```python # Colab setup: install Newton before importing it. import importlib.util import subprocess import sys try: IN_COLAB = importlib.util.find_spec("google.colab") is not None except ModuleNotFoundError: IN_COLAB = False if IN_COLAB: subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "newton[notebook]"]) ``` -------------------------------- ### Run Cube Stacking Inverse Kinematics Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the cube stacking inverse kinematics example. This command demonstrates IK for stacking cubes. ```bash python -m newton.examples ik_cube_stacking ``` -------------------------------- ### Install Warp from Source Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Clone the Warp repository, build the library, and install it in editable mode with development dependencies. ```bash git clone git@github.com:NVIDIA/warp.git cd warp python build_lib.py pip install -e .[dev,benchmark] ``` -------------------------------- ### Run Cloth Simulation Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the cloth simulation example. This command initiates a simulation demonstrating cloth dynamics. ```bash python -m newton.examples cloth_rollers ``` -------------------------------- ### Run Sensor Tiled Camera Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the sensor tiled camera example. This showcases the use of tiled camera sensors for simulation. ```bash python -m newton.examples sensor_tiled_camera ``` -------------------------------- ### Run Basic Heightfield Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic heightfield example. This demonstrates simulation on complex terrain. ```bash python -m newton.examples basic_heightfield ``` -------------------------------- ### Run Basic URDF Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic URDF (Unified Robot Description Format) loading example. This shows how to import robot models. ```bash python -m newton.examples basic_urdf ``` -------------------------------- ### Run Anymal Material Point Method Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the Anymal Material Point Method (MPM) example. This command demonstrates MPM for the Anymal robot. ```bash python -m newton.examples mpm_anymal ``` -------------------------------- ### Install Viser Package Source: https://github.com/newton-physics/newton/blob/main/docs/guide/visualization.rst Install the viser package to enable integration with the Viser Viewer. ```bash pip install viser ``` -------------------------------- ### Run Sensor Contact Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the sensor contact example. This demonstrates how to use contact sensors within the simulation. ```bash python -m newton.examples sensor_contact ``` -------------------------------- ### Test Specific Newton Examples with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Run a specific example test, 'test_basic.example_basic_shapes', using uv. ```console uv run --extra dev -m newton.tests.test_examples -k test_basic.example_basic_shapes ``` -------------------------------- ### Install Local Warp with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Steps to set up a local Warp installation using uv for development. Includes virtual environment creation and dependency synchronization. ```console uv venv source .venv/bin/activate uv sync --extra dev uv pip install -e "warp-lang @ ../warp" ``` -------------------------------- ### Run Selection Cartpole Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the selection cartpole example. This demonstrates the selection mechanism applied to a cartpole system. ```bash python -m newton.examples selection_cartpole ``` -------------------------------- ### Install uv on Windows Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Install the uv package manager using a PowerShell command on Windows systems. ```console powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Run Examples with uv Source: https://github.com/newton-physics/newton/blob/main/README.md Execute Newton examples using the uv package manager. This is an alternative to the standard python -m command when using a source checkout. ```bash uv run --extra examples -m newton.examples ``` -------------------------------- ### Install Newton Solver Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Clone the Newton solver repository and install it with development, documentation, and notebook dependencies. ```bash git clone git@github.com:newton-physics/newton.git cd newton pip install -e .[dev,docs,notebook] ``` -------------------------------- ### Run Franka Inverse Kinematics Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the Franka robot inverse kinematics example. This command demonstrates IK for a Franka robot. ```bash python -m newton.examples ik_franka ``` -------------------------------- ### Run Basic Shapes Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic shapes example. This demonstrates the creation and simulation of various geometric shapes. ```bash python -m newton.examples basic_shapes ``` -------------------------------- ### Run Basic Joints Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic joints example. This shows how to simulate articulated bodies using joints. ```bash python -m newton.examples basic_joints ``` -------------------------------- ### Run Basic Conveyor Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the basic conveyor belt simulation example. This demonstrates interaction with moving platforms. ```bash python -m newton.examples basic_conveyor ``` -------------------------------- ### Run Custom Inverse Kinematics Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute a custom inverse kinematics example. This command demonstrates IK for a custom robot configuration. ```bash python -m newton.examples ik_custom ``` -------------------------------- ### Run Viscous Material Point Method Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the viscous Material Point Method (MPM) example. This command demonstrates MPM for viscous fluids. ```bash python -m newton.examples mpm_viscous ``` -------------------------------- ### Run Granular Material Point Method Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the granular Material Point Method (MPM) example. This command demonstrates MPM for granular materials. ```bash python -m newton.examples mpm_granular ``` -------------------------------- ### Run Example on a Specific Compute Device Source: https://github.com/newton-physics/newton/blob/main/README.md This command demonstrates how to run a Newton example on a designated compute device, such as a CUDA-enabled GPU. ```bash # Run on a selected device python -m newton.examples basic_urdf --device cuda:0 ``` -------------------------------- ### Run MPM Snow Ball Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the MPM snow ball example. This demonstrates the simulation of granular materials like snow. ```bash python -m newton.examples mpm_snow_ball ``` -------------------------------- ### Run Sensor IMU Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the sensor IMU example. This demonstrates the integration and use of an Inertial Measurement Unit (IMU) sensor. ```bash python -m newton.examples sensor_imu ``` -------------------------------- ### Run Kamino Example Simulation Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Navigate to the Kamino examples directory and run a specific simulation script using Python. ```bash cd newton/_src/solvers/kamino/examples python sim/example_sim_dr_legs.py ``` -------------------------------- ### Install Newton USD Schemas Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Clone the Newton USD Schemas repository and install it with development, documentation, and notebook dependencies. ```bash git clone git@github.com:newton-physics/newton-usd-schemas.git cd newton-usd-schemas pip install -e .[dev,docs,notebook] ``` -------------------------------- ### Install Development Extras and Run Tests with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Use this command to install development dependencies and run all tests using the uv package manager. ```console uv run --extra dev --extra torch-cu12 -m newton.tests ``` -------------------------------- ### Run H1 Inverse Kinematics Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the H1 robot inverse kinematics example. This command demonstrates IK for an H1 robot. ```bash python -m newton.examples ik_h1 ``` -------------------------------- ### Run Cloth Poker Cards Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the cloth poker cards simulation example. This command demonstrates cloth simulation with poker cards. ```bash python -m newton.examples cloth_poker_cards ``` -------------------------------- ### Install Linux aarch64 Development Libraries Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst On ARM64 Linux systems, install X11 development libraries required for building 'imgui_bundle' when installing 'examples' extras. ```console sudo apt-get update sudo apt-get install -y libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libgl1-mesa-dev ``` -------------------------------- ### Run Sphinx Doctest Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst This command runs Sphinx doctests to verify documentation examples. Ensure you are in the correct directory and have Sphinx installed. ```console python -m sphinx -j auto -W -b doctest docs docs/_build/doctest ``` -------------------------------- ### Newton Quick Start: Build Model and Create Solver Source: https://github.com/newton-physics/newton/blob/main/docs/guide/installation.rst Demonstrates building a physics model with a body and ground plane, and creating an XPBD solver using only the base Newton package. ```python import warp as wp import newton # Build a model builder = newton.ModelBuilder() body = builder.add_body( xform=wp.transform((0.0, 1.0, 0.0), wp.quat_identity()), mass=1.0, ) builder.add_shape_sphere(body, radius=0.25) builder.add_ground_plane() model = builder.finalize() # Create a solver and allocate state solver = newton.solvers.SolverXPBD(model) state_0 = model.state() state_1 = model.state() ``` -------------------------------- ### Setup IK Objectives for Manipulation Source: https://github.com/newton-physics/newton/blob/main/docs/tutorials/01_robotics.ipynb Defines the Inverse Kinematics objectives for controlling the Franka robot's end-effector. This includes position, rotation, and joint limit objectives to guide the robot's movement. ```python ee_index = 11 fixed_rot = wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), wp.pi) home_pos_np = state_0.body_q.numpy()[ee_index][:3].astype(np.float32) home_pos = wp.vec3(home_pos_np[0], home_pos_np[1], home_pos_np[2]) pos_obj = ik.IKObjectivePosition( link_index=ee_index, link_offset=wp.vec3(0.0, 0.0, 0.0), target_positions=wp.array([home_pos], dtype=wp.vec3), ) rot_obj = ik.IKObjectiveRotation( link_index=ee_index, link_offset_rotation=wp.quat_identity(), target_rotations=wp.array([fixed_rot[:4]], dtype=wp.vec4), ) joint_limit_obj = ik.IKObjectiveJointLimit( joint_limit_lower=model.joint_limit_lower, joint_limit_upper=model.joint_limit_upper, ) joint_q_ik = wp.clone(model.joint_q.reshape((1, -1))) ik_solver = ik.IKSolver( model=model, n_problems=1, objectives=[pos_obj, rot_obj, joint_limit_obj], lambda_initial=0.1, jacobian_mode=ik.IKJacobianType.ANALYTIC, ) ik_iters = 24 ``` -------------------------------- ### Run Multi-Material Material Point Method Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the multi-material Material Point Method (MPM) example. This command demonstrates MPM with multiple material types. ```bash python -m newton.examples mpm_multi_material ``` -------------------------------- ### Example Class Interface Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Defines the interface for example classes in Newton. Implement these methods to create new simulation examples. ```python class Example: def __init__(self, viewer, args): """Build the model, create solver/state/control, and set up the viewer.""" ... def step(self): """Advance the simulation by one frame (typically with substeps).""" ... def render(self): """Update the viewer with the current state.""" ... def test_final(self): """Validate the final simulation state. Required for CI.""" ... def test_post_step(self): """Optional per-step validation, called after every step() in test mode.""" ... ``` -------------------------------- ### Install Newton in Editable Mode Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/tests/README.md Install the Newton project in editable mode with development, data, and documentation dependencies. This step can be skipped if Newton is already installed this way. ```bash cd /newton pip install -e .[dev,data,docs] ``` -------------------------------- ### Initialize Viser Viewer Source: https://github.com/newton-physics/newton/blob/main/docs/tutorials/00_introduction.ipynb Create and configure the Viser viewer for recording and displaying simulation data. Ensure the recording path is correctly set up. ```python # Create the Viser viewer with a path to save the recording recording_path = Path("../_static/recordings/00_introduction.viser").resolve() recording_path.parent.mkdir(parents=True, exist_ok=True) viewer = newton.viewer.ViewerViser(verbose=False, record_to_viser=str(recording_path)) ``` ```python # Set the model (this logs the static geometry) viewer.set_model(model) ``` -------------------------------- ### Install Rerun SDK Source: https://github.com/newton-physics/newton/blob/main/docs/guide/visualization.rst Install the rerun-sdk package to enable integration with the Rerun Viewer. ```bash pip install rerun-sdk ``` -------------------------------- ### Test Specific Newton Examples with venv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Run a specific example test, 'test_basic.example_basic_shapes', using venv. ```console python -m newton.tests.test_examples -k test_basic.example_basic_shapes ``` -------------------------------- ### Setup Simulation Viewer and Stepping Function Source: https://github.com/newton-physics/newton/blob/main/docs/tutorials/01_robotics.ipynb Initializes a viewer for visualizing the simulation and defines a function to run simulation substeps. This prepares for the main simulation loop. ```python viewer = make_viewer("05_franka_ik_single_position") viewer.set_model(model) viewer.set_camera(wp.vec3(0.5, 0.0, 0.5), -15, -140) sim_time = 0.0 ee_trace = [] graph = None def run_sim_substeps(): global state_0, state_1 for _ in range(sim_substeps): state_0.clear_forces() solver.step(state_in=state_0, state_out=state_1, control=control, contacts=contacts, dt=sim_sim_dt) state_0, state_1 = state_1, state_0 ``` -------------------------------- ### Run Example in Headless Test Mode (uv) Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Runs an example in headless test mode using 'uv', suitable for CI verification. This mode disables the viewer and runs tests. ```console uv run -m newton.examples basic_pendulum --viewer null --test ``` -------------------------------- ### Serve Documentation with Custom Port using uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Command to serve the built documentation locally using uv, specifying a custom port. Useful for testing interactive features. ```console uv run docs/serve.py --port 8080 ``` -------------------------------- ### Install MuJoCo Warp from Source Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Install the MuJoCo Warp (MJWarp) package directly from its GitHub repository. ```bash pip install git+https://github.com/google-deepmind/mujoco_warp.git@main ``` -------------------------------- ### Install Warp Nightly Builds Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Install the latest nightly builds of the Warp language from its pre-release channel. ```bash pip install warp-lang --pre -U -f https://pypi.nvidia.com/warp-lang/ ``` -------------------------------- ### Initialize Viewer and Simulation Loop Source: https://github.com/newton-physics/newton/blob/main/docs/tutorials/01_robotics.ipynb Sets up the simulation viewer and defines the substep function for running the physics solver. ```python viewer = make_viewer("08_franka_ik_rectangle_full") viewer.set_model(model) viewer.set_camera(wp.vec3(0.5, 0.0, 0.5), -15, -140) sim_time = 0.0 ee_trace = [] graph = None def run_sim_substeps(): global state_0, state_1 for _ in range(sim_substeps): state_0.clear_forces() solver.step(state_in=state_0, state_out=state_1, control=control, contacts=contacts, dt=sim_dt) state_0, state_1 = state_1, state_0 ``` -------------------------------- ### Install uv on macOS/Linux Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Install the uv package manager using a curl command on macOS or Linux systems. ```console curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Serve Documentation Locally with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Command to serve the built documentation locally using uv. Useful for testing interactive features. ```console uv run docs/serve.py ``` -------------------------------- ### Install MuJoCo Python Package Source: https://github.com/newton-physics/newton/blob/main/newton/_src/solvers/kamino/README.md Install the MuJoCo Python package, including pre-release versions, from its official repository. ```bash pip install mujoco --pre -f https://py.mujoco.org/ ``` -------------------------------- ### PhysX SDF Mesh Collision Schema Example Source: https://github.com/newton-physics/newton/blob/main/docs/concepts/usd_parsing.rst Example of defining a mesh with PhysX SDF collision properties in USD. ```usda #usda 1.0 def Xform "Body" ( prepend apiSchemas = [ "PhysicsCollisionAPI", "PhysxCollisionAPI", "PhysxSDFMeshCollisionAPI", ] ) { float physxCollision:restOffset = 0.002 float physxCollision:contactOffset = 0.005 uint physxSDFMeshCollision:sdfResolution = 256 float physxSDFMeshCollision:sdfNarrowBandThickness = 0.01 float physxSDFMeshCollision:sdfMargin = 0.01 token physxSDFMeshCollision:sdfBitsPerSubgridPixel = "BitsPerPixel16" } ``` -------------------------------- ### Run Tests with uv Source: https://github.com/newton-physics/newton/blob/main/docs/guide/development.rst Install development extras and run the project's test suite using uv. ```console uv run --extra dev -m newton.tests ``` -------------------------------- ### Run Two-Way Coupling Material Point Method Example Source: https://github.com/newton-physics/newton/blob/main/README.md Execute the two-way coupling Material Point Method (MPM) example. This command demonstrates MPM with fluid-structure interaction. ```bash python -m newton.examples mpm_twoway_coupling ```