From a63d97ef669120b9fbceb6087d764f60732e5ae0 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 18:17:28 +0200 Subject: [PATCH 01/25] adds initial fix --- .vscode/tasks.json | 2 +- .vscode/tools/launch.template.json | 14 +++------ .vscode/tools/setup_vscode.py | 46 ++++++++++++++++++++++++------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index ef0dbd6eab..59dcc3d859 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -8,7 +8,7 @@ "label": "setup_python_env", "type": "shell", "linux": { - "command": "export CARB_APP_PATH=${workspaceFolder}/_isaac_sim/kit && export ISAAC_PATH=${workspaceFolder}/_isaac_sim && export EXP_PATH=${workspaceFolder}/_isaac_sim/apps && source ${workspaceFolder}/_isaac_sim/setup_python_env.sh && printenv >${workspaceFolder}/.vscode/.python.env && ${workspaceFolder}/_isaac_sim/python.sh ${workspaceFolder}/.vscode/tools/setup_vscode.py" + "command": "${workspaceFolder}/isaaclab.sh -p ${workspaceFolder}/.vscode/tools/setup_vscode.py" } }, { diff --git a/.vscode/tools/launch.template.json b/.vscode/tools/launch.template.json index 123e4e9cf6..4276d42938 100644 --- a/.vscode/tools/launch.template.json +++ b/.vscode/tools/launch.template.json @@ -11,11 +11,9 @@ "program": "${file}", "console": "integratedTerminal", "env": { - "EXP_PATH": "${workspaceFolder}/_isaac_sim/apps", "RESOURCE_NAME": "IsaacSim" }, - "envFile": "${workspaceFolder}/.vscode/.python.env", - "preLaunchTask": "setup_python_env" + "envFile": "${workspaceFolder}/.vscode/.python.env" }, { "name": "Python: Attach (windows-x86_64/linux-x86_64)", @@ -32,11 +30,9 @@ "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/train.py", "console": "integratedTerminal", "env": { - "EXP_PATH": "${workspaceFolder}/_isaac_sim/apps", "RESOURCE_NAME": "IsaacSim" }, - "envFile": "${workspaceFolder}/.vscode/.python.env", - "preLaunchTask": "setup_python_env" + "envFile": "${workspaceFolder}/.vscode/.python.env" }, { "name": "Python: Play Environment", @@ -46,11 +42,9 @@ "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/play.py", "console": "integratedTerminal", "env": { - "EXP_PATH": "${workspaceFolder}/_isaac_sim/apps", "RESOURCE_NAME": "IsaacSim" }, - "envFile": "${workspaceFolder}/.vscode/.python.env", - "preLaunchTask": "setup_python_env" - }, + "envFile": "${workspaceFolder}/.vscode/.python.env" + } ] } diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index eee1f7450e..e7bea180cb 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -5,10 +5,10 @@ """This script sets up the vs-code settings for the Isaac Lab project. -This script merges the python.analysis.extraPaths from the "_isaac_sim/.vscode/settings.json" file into +This script merges the python.analysis.extraPaths from the "{ISAACSIM_DIR}/.vscode/settings.json" file into the ".vscode/settings.json" file. -This is necessary because Isaac Sim 2022.2.1 does not add the necessary python packages to the python path +This is necessary because Isaac Sim 2022.2.1 onwards does not add the necessary python packages to the python path when the "setup_python_env.sh" is run as part of the vs-code launch configuration. """ @@ -20,18 +20,33 @@ ISAACLAB_DIR = pathlib.Path(__file__).parents[2] """Path to the Isaac Lab directory.""" -ISAACSIM_DIR = os.path.join(ISAACLAB_DIR, "_isaac_sim") + +try: + import isaacsim # noqa: F401 + + isaacsim_dir = os.environ.get("ISAAC_PATH", "") +except ModuleNotFoundError or ImportError: + isaacsim_dir = os.path.join(ISAACLAB_DIR, "_isaac_sim") + +# check if the isaac-sim directory exists +if not os.path.exists(isaacsim_dir): + raise FileNotFoundError( + f"Could not find the isaac-sim directory: {isaacsim_dir}. There are two possible reasons for this:\n" + "\t1. The Isaac Sim directory does not exist as a symlink in the Isaac Lab directory.\n" + "\t2. The script could import the 'isaacsim' package. This could be due to the 'isaacsim' package not being " + "installed in the Python environment.\n" + "Please make sure that the Isaac Sim directory exists or that the 'isaacsim' package is installed." + ) + +ISAACSIM_DIR = isaacsim_dir """Path to the isaac-sim directory.""" -# check if ISAACSIM_DIR is valid: -if not os.path.isdir(ISAACSIM_DIR): - ISAACSIM_DIR = os.environ.get("ISAACSIM_PATH", "") def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: """Overwrite the python.analysis.extraPaths in the Isaac Lab settings file. The extraPaths are replaced with the path names from the isaac-sim settings file that exists in the - "_isaac_sim/.vscode/settings.json" file. + "{ISAACSIM_DIR}/.vscode/settings.json" file. Args: isaaclab_settings: The settings string to use as template. @@ -57,10 +72,15 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: settings = settings.group(0) settings = settings.split('"python.analysis.extraPaths": [')[-1] settings = settings.split("]")[0] - # change the path names to be relative to the Isaac Lab directory + + # read the path names from the isaac-sim settings file path_names = settings.split(",") path_names = [path_name.strip().strip('"') for path_name in path_names] - path_names = ['"${workspaceFolder}/_isaac_sim/' + path_name + '"' for path_name in path_names if len(path_name) > 0] + path_names = [path_name for path_name in path_names if len(path_name) > 0] + + # change the path names to be relative to the Isaac Lab directory + rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR) + path_names = ['"${workspaceFolder}/' + rel_path + '/' + path_name + '"' for path_name in path_names] # add the path names that are in the Isaac Lab extensions directory isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions")) @@ -68,6 +88,8 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: # combine them into a single string path_names = ",\n\t\t".expandtabs(4).join(path_names) + # deal with the path separator being different on Windows and Unix + path_names = path_names.replace("/", os.sep) # replace the path names in the Isaac Lab settings file with the path names from the isaac-sim settings file isaaclab_settings = re.sub( @@ -158,6 +180,12 @@ def main(): with open(isaaclab_vscode_launch_filename, "w") as f: f.write(isaaclab_launch_settings) + # save the current set of environment variables into the .env file + isaaclab_env_filename = os.path.join(ISAACLAB_DIR, ".vscode", ".python.env") + with open(isaaclab_env_filename, "w") as f: + for key, value in os.environ.items(): + f.write(f"{key}={value}\n") + if __name__ == "__main__": main() From c739249cb566f8cb40cbb730e7d1bf47daaea142 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 18:22:24 +0200 Subject: [PATCH 02/25] working setup without env file --- .vscode/tools/launch.template.json | 9 +++------ .vscode/tools/settings.template.json | 5 +++-- .vscode/tools/setup_vscode.py | 6 ------ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.vscode/tools/launch.template.json b/.vscode/tools/launch.template.json index 4276d42938..371acaeacf 100644 --- a/.vscode/tools/launch.template.json +++ b/.vscode/tools/launch.template.json @@ -12,8 +12,7 @@ "console": "integratedTerminal", "env": { "RESOURCE_NAME": "IsaacSim" - }, - "envFile": "${workspaceFolder}/.vscode/.python.env" + } }, { "name": "Python: Attach (windows-x86_64/linux-x86_64)", @@ -31,8 +30,7 @@ "console": "integratedTerminal", "env": { "RESOURCE_NAME": "IsaacSim" - }, - "envFile": "${workspaceFolder}/.vscode/.python.env" + } }, { "name": "Python: Play Environment", @@ -43,8 +41,7 @@ "console": "integratedTerminal", "env": { "RESOURCE_NAME": "IsaacSim" - }, - "envFile": "${workspaceFolder}/.vscode/.python.env" + } } ] } diff --git a/.vscode/tools/settings.template.json b/.vscode/tools/settings.template.json index 1502916a4e..93ed96e7e5 100644 --- a/.vscode/tools/settings.template.json +++ b/.vscode/tools/settings.template.json @@ -68,8 +68,9 @@ "autoDocstring.docstringFormat": "google", "autoDocstring.guessTypes": true, // Python environment path - "python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/kit/python/bin/python3", - "python.envFile": "${workspaceFolder}/.vscode/.python.env", + // note: the default interpreter is overriden when user selects a workspace interpreter + // in the status bar. For example, the virtual environment python interpreter + "python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh", // ROS distribution "ros.distro": "noetic", // Language specific settings diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index e7bea180cb..fad4ccb84f 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -180,12 +180,6 @@ def main(): with open(isaaclab_vscode_launch_filename, "w") as f: f.write(isaaclab_launch_settings) - # save the current set of environment variables into the .env file - isaaclab_env_filename = os.path.join(ISAACLAB_DIR, ".vscode", ".python.env") - with open(isaaclab_env_filename, "w") as f: - for key, value in os.environ.items(): - f.write(f"{key}={value}\n") - if __name__ == "__main__": main() From d09fff060b94b27236e1452d2056528c1ea5f5ba Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 18:23:51 +0200 Subject: [PATCH 03/25] works without any other code --- .vscode/tools/launch.template.json | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/.vscode/tools/launch.template.json b/.vscode/tools/launch.template.json index 371acaeacf..def68d2429 100644 --- a/.vscode/tools/launch.template.json +++ b/.vscode/tools/launch.template.json @@ -9,10 +9,7 @@ "type": "python", "request": "launch", "program": "${file}", - "console": "integratedTerminal", - "env": { - "RESOURCE_NAME": "IsaacSim" - } + "console": "integratedTerminal" }, { "name": "Python: Attach (windows-x86_64/linux-x86_64)", @@ -27,10 +24,7 @@ "request": "launch", "args" : ["--task", "Isaac-Reach-Franka-v0", "--headless"], "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/train.py", - "console": "integratedTerminal", - "env": { - "RESOURCE_NAME": "IsaacSim" - } + "console": "integratedTerminal" }, { "name": "Python: Play Environment", @@ -38,10 +32,7 @@ "request": "launch", "args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"], "program": "${workspaceFolder}/source/standalone/workflows/rsl_rl/play.py", - "console": "integratedTerminal", - "env": { - "RESOURCE_NAME": "IsaacSim" - } + "console": "integratedTerminal" } ] } From 9d92b49075e52b69be656822c2065d1f6a8ffbe4 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 18:44:27 +0200 Subject: [PATCH 04/25] runs formatter --- .vscode/tools/setup_vscode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index fad4ccb84f..8156a1a943 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -80,7 +80,7 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: # change the path names to be relative to the Isaac Lab directory rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR) - path_names = ['"${workspaceFolder}/' + rel_path + '/' + path_name + '"' for path_name in path_names] + path_names = ['"${workspaceFolder}/' + rel_path + "/" + path_name + '"' for path_name in path_names] # add the path names that are in the Isaac Lab extensions directory isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions")) From f568db5f0aa4372fefdc89ac06fa52697d3d1456 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 18:44:50 +0200 Subject: [PATCH 05/25] runs formatter --- .vscode/tools/settings.template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/tools/settings.template.json b/.vscode/tools/settings.template.json index 93ed96e7e5..7d696c44b8 100644 --- a/.vscode/tools/settings.template.json +++ b/.vscode/tools/settings.template.json @@ -68,7 +68,7 @@ "autoDocstring.docstringFormat": "google", "autoDocstring.guessTypes": true, // Python environment path - // note: the default interpreter is overriden when user selects a workspace interpreter + // note: the default interpreter is overridden when user selects a workspace interpreter // in the status bar. For example, the virtual environment python interpreter "python.defaultInterpreterPath": "${workspaceFolder}/_isaac_sim/python.sh", // ROS distribution From 0327c3ae34d4ffb93858041d575cb0fbfccf3ff5 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 20:22:51 +0200 Subject: [PATCH 06/25] fix scripts to use isaacsim pip paths --- isaaclab.bat | 79 ++++++++++++++++++++++++-------------------------- isaaclab.sh | 81 ++++++++++++++++++++++++++-------------------------- 2 files changed, 78 insertions(+), 82 deletions(-) diff --git a/isaaclab.bat b/isaaclab.bat index f48c331b0f..de8ca2f142 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -12,17 +12,40 @@ goto main rem Helper functions -rem extract the python from isaacsim -:extract_python_exe +rem extract Isaac Sim directory +:extract_isaacsim_path rem Check if IsaacSim directory manually specified -rem Note: for manually build isaacsim, this: _build/linux-x86_64/release if not "%ISAACSIM_PATH%"=="" ( rem Use local build - set build_path=%ISAACSIM_PATH% + set isaac_path=%ISAACSIM_PATH% ) else ( - rem Use TeamCity build - set build_path=%ISAACLAB_PATH%\_isaac_sim + rem check if isaacsim is installed + pip show isaacsim-rl > nul 2>&1 + if errorlevel 1 ( + rem Use TeamCity build or pip install + set isaac_path=%ISAACLAB_PATH%\_isaac_sim + ) else ( + rem obtain the path from isaacsim-rl package + set "isaac_path=" + for /f "delims=" %%i in ('pip show isaacsim-rl ^| findstr /c:"Location"') do ( + if not defined isaac_path ( + set "isaac_path=%%i" + ) + ) + ) ) +rem Check if the directory exists +if not exist "%isaac_path%" ( + echo [ERROR] Isaac Sim directory not found at path: %isaac_path% + echo [ERROR] Please specify the path to Isaac Sim directory using 'ISAACSIM_PATH' environment variable. + exit /b 1 +) +goto :eof + +rem extract the python from isaacsim +:extract_python_exe +rem obtain isaacsim path +call :extract_isaacsim_path rem check if using conda if not "%CONDA_PREFIX%"=="" ( rem use conda python @@ -32,7 +55,7 @@ if not "%CONDA_PREFIX%"=="" ( pip show isaacsim-rl > nul 2>&1 if errorlevel 1 ( rem use python from kit if Isaac Sim not installed from pip - set python_exe=%build_path%\python.bat + set python_exe=%isaac_path%\python.bat ) else ( rem use current python if Isaac Sim is installed from pip set "python_exe=" @@ -45,7 +68,7 @@ if not "%CONDA_PREFIX%"=="" ( ) rem check if there is a python path available if "%python_exe%"=="" ( - echo [ERROR] No python executable found at path: %build_path% + echo [ERROR] No python executable found at path: %isaac_path% exit /b 1 ) goto :eof @@ -53,20 +76,13 @@ goto :eof rem extract the simulator exe from isaacsim :extract_isaacsim_exe -rem Check if IsaacSim directory manually specified -rem Note: for manually build isaacsim, this: _build\linux-x86_64\release -if not "%ISAACSIM_PATH%"=="" ( - rem Use local build - set build_path=%ISAACSIM_PATH% -) else ( - rem Use TeamCity build - set build_path=%ISAACLAB_PATH%\_isaac_sim -) +rem obtain isaacsim path +call :extract_isaacsim_path rem python executable to use -set isaacsim_exe=%build_path%\isaac-sim.bat +set isaacsim_exe=%isaac_path%\isaac-sim.bat rem check if there is a python path available if not exist "%isaacsim_exe%" ( - echo [ERROR] No isaac-sim executable found at path: %build_path% + echo [ERROR] No isaac-sim executable found at path: %isaac_path% exit /b 1 ) goto :eof @@ -95,15 +111,6 @@ if errorlevel 1 ( echo [ERROR] Conda could not be found. Please install conda and try again. exit /b 1 ) -rem check if Isaac Sim directory manually specified -rem Note: for manually build Isaac Sim, this: _build\windows-x86_64\release -if not "%ISAACSIM_PATH%"=="" ( - rem Use local build - set "build_path=%ISAACSIM_PATH%" -) else ( - rem Use TeamCity build - set "build_path=%ISAACLAB_PATH%\_isaac_sim" -) rem check if the environment exists call conda env list | findstr /c:"%env_name%" >nul if %errorlevel% equ 0 ( @@ -128,18 +135,11 @@ rem add variables to environment during activation ( echo @echo off rem for isaac-sim - echo set CARB_APP_PATH=%build_path%\kit - echo set EXP_PATH=%build_path%\apps - echo set ISAAC_PATH=%build_path% - echo set PYTHONPATH=%PYTHONPATH%;%build_path%\site echo set "RESOURCE_NAME=IsaacSim" + rem for isaac-lab echo doskey isaaclab=isaaclab.bat $* ) > "%CONDA_PREFIX%\etc\conda\activate.d\env_vars.bat" ( - echo $env:CARB_APP_PATH="%build_path%\kit" - echo $env:EXP_PATH="%build_path%\apps" - echo $env:ISAAC_PATH="%build_path%" - echo $env:PYTHONPATH="%PYTHONPATH%;%build_path%\site" echo $env:RESOURCE_NAME="IsaacSim" ) > "%CONDA_PREFIX%\etc\conda\activate.d\env_vars.ps1" @@ -149,10 +149,8 @@ rem remove variables from environment during deactivation ( echo @echo off echo rem for isaac-sim - echo set "CARB_APP_PATH=" - echo set "EXP_PATH=" - echo set "ISAAC_PATH=" echo set "RESOURCE_NAME=" + echo rem for isaac-lab echo doskey isaaclab = echo. echo rem restore paths @@ -160,9 +158,6 @@ rem remove variables from environment during deactivation echo set "LD_LIBRARY_PATH=%cache_ld_library_path%" ) > "%CONDA_PREFIX%\etc\conda\deactivate.d\unsetenv_vars.bat" ( - echo $env:CARB_APP_PATH="" - echo $env:EXP_PATH="" - echo $env:ISAAC_PATH="" echo $env:RESOURCE_NAME="" echo $env:PYTHONPATH="%cache_pythonpath%" echo $env:LD_LIBRARY_PATH="%cache_pythonpath%" diff --git a/isaaclab.sh b/isaaclab.sh index 1ef84f013b..c3b13013e9 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -22,34 +22,54 @@ export ISAACLAB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && p # Helper functions #== -# extract the python from isaacsim -extract_python_exe() { +# extract isaac sim path +extract_isaacsim_path() { # Check if IsaacSim directory manually specified # Note: for manually build isaacsim, this: _build/linux-x86_64/release if [ ! -z ${ISAACSIM_PATH} ]; then - # Use local build - build_path=${ISAACSIM_PATH} + # Use local build (for internal development) or user specified path + local isaac_path=${ISAACSIM_PATH} else - # Use TeamCity build - build_path=${ISAACLAB_PATH}/_isaac_sim + # Check if we have isaacsim-rl package installed + if [ pip show isaacsim-rl > /dev/null 2>&1 ]; then + # Retrieve the path from location of isaacsim-rl package + local isaac_path=$(pip show isaacsim-rl | grep Location | cut -d ' ' -f 2) + else + # Use the sym-link path to Isaac Sim directory + local isaac_path=${ISAACLAB_PATH}/_isaac_sim + fi fi + # check if there is a path available + if [ ! -d "${isaac_path}" ]; then + echo "[ERROR] No Isaac Sim directory found at path: ${isaac_path}" >&2 + echo "[ERROR] Please specify the path to the Isaac Sim directory using 'ISAACSIM_PATH' environment variable." >&2 + exit 1 + fi + # return the result + echo ${isaac_path} +} + +# extract the python from isaacsim +extract_python_exe() { # check if using conda if ! [[ -z "${CONDA_PREFIX}" ]]; then # use conda python local python_exe=${CONDA_PREFIX}/bin/python else - if pip show isaacsim-rl > /dev/null 2>&1; then + if [ pip show isaacsim-rl > /dev/null 2>&1 ]; then # use current python executable - python_exe=$(which python) + local python_exe=$(which python) else + # obtain the isaac sim path + local isaac_path=$(extract_isaacsim_path) # use python from kit - local python_exe=${build_path}/python.sh + local python_exe=${isaac_path}/python.sh fi fi # check if there is a python path available if [ ! -f "${python_exe}" ]; then - echo "[ERROR] No python executable found at path: ${build_path}" >&2 + echo "[ERROR] No python executable found at path: ${isaac_path}" >&2 exit 1 fi # return the result @@ -58,21 +78,13 @@ extract_python_exe() { # extract the simulator exe from isaacsim extract_isaacsim_exe() { - # Check if IsaacSim directory manually specified - # Note: for manually build isaacsim, this: _build/linux-x86_64/release - if [ ! -z ${ISAACSIM_PATH} ]; - then - # Use local build - build_path=${ISAACSIM_PATH} - else - # Use TeamCity build - build_path=${ISAACLAB_PATH}/_isaac_sim - fi + # obtain the isaac sim path + local isaac_path=$(extract_isaacsim_path) # python executable to use - local isaacsim_exe=${build_path}/isaac-sim.sh + local isaacsim_exe=${isaac_path}/isaac-sim.sh # check if there is a python path available if [ ! -f "${isaacsim_exe}" ]; then - echo "[ERROR] No isaac-sim executable found at path: ${build_path}" >&2 + echo "[ERROR] No Isaac Sim executable found at path: ${isaacsim_exe}" >&2 exit 1 fi # return the result @@ -100,16 +112,7 @@ setup_conda_env() { echo "[ERROR] Conda could not be found. Please install conda and try again." exit 1 fi - # Check if IsaacSim directory manually specified - # Note: for manually build isaacsim, this: _build/linux-x86_64/release - if [ ! -z ${ISAACSIM_PATH} ]; - then - # Use local build - build_path=${ISAACSIM_PATH} - else - # Use TeamCity build - build_path=${ISAACLAB_PATH}/_isaac_sim - fi + # check if the environment exists if { conda env list | grep -w ${env_name}; } >/dev/null 2>&1; then echo -e "[INFO] Conda environment named '${env_name}' already exists." @@ -117,6 +120,7 @@ setup_conda_env() { echo -e "[INFO] Creating conda environment named '${env_name}'..." conda create -y --name ${env_name} python=3.10 fi + # cache current paths for later cache_pythonpath=$PYTHONPATH cache_ld_library_path=$LD_LIBRARY_PATH @@ -129,12 +133,9 @@ setup_conda_env() { # setup directories to load Isaac Sim variables mkdir -p ${CONDA_PREFIX}/etc/conda/activate.d mkdir -p ${CONDA_PREFIX}/etc/conda/deactivate.d + # add variables to environment during activation - local isaacsim_setup_conda_env_script=${ISAACLAB_PATH}/_isaac_sim/setup_conda_env.sh printf '%s\n' '#!/usr/bin/env bash' '' \ - '# for Isaac Sim' \ - 'source '${isaacsim_setup_conda_env_script}'' \ - '' \ '# for Isaac Lab' \ 'export ISAACLAB_PATH='${ISAACLAB_PATH}'' \ 'alias isaaclab='${ISAACLAB_PATH}'/isaaclab.sh' \ @@ -142,9 +143,11 @@ setup_conda_env() { '# show icon if not runninng headless' \ 'export RESOURCE_NAME="IsaacSim"' \ '' > ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh + # reactivate the environment to load the variables # needed because deactivate complains about Isaac Lab alias since it otherwise doesn't exist conda activate ${env_name} + # remove variables from environment during deactivation printf '%s\n' '#!/usr/bin/env bash' '' \ '# for Isaac Lab' \ @@ -152,9 +155,6 @@ setup_conda_env() { 'unset ISAACLAB_PATH' \ '' \ '# for Isaac Sim' \ - 'unset CARB_APP_PATH' \ - 'unset EXP_PATH' \ - 'unset ISAAC_PATH' \ 'unset RESOURCE_NAME' \ '' \ '# restore paths' \ @@ -164,6 +164,7 @@ setup_conda_env() { # install some extra dependencies echo -e "[INFO] Installing extra dependencies (this might take a few minutes)..." conda install -c conda-forge -y importlib_metadata &> /dev/null + # deactivate the environment conda deactivate # add information to the user about alias @@ -187,7 +188,7 @@ update_vscode_settings() { if [ -f "${setup_vscode_script}" ]; then ${python_exe} "${setup_vscode_script}" else - echo "[WARNING] setup_vscode.py not found. Aborting vscode settings setup." + echo "[WARNING] Unable to find the script 'setup_vscode.py'. Aborting vscode settings setup." fi } From acbda9a2cad83b8d165a069e46e9e2abdf1d54ae Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Wed, 3 Jul 2024 23:02:51 +0200 Subject: [PATCH 07/25] gets path correclty --- isaaclab.bat | 6 ++++-- isaaclab.sh | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/isaaclab.bat b/isaaclab.bat index de8ca2f142..eff635827b 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -25,9 +25,11 @@ if not "%ISAACSIM_PATH%"=="" ( rem Use TeamCity build or pip install set isaac_path=%ISAACLAB_PATH%\_isaac_sim ) else ( - rem obtain the path from isaacsim-rl package + rem use the python executable to get the path + call :extract_python_exe + rem retrieve the isaacsim path set "isaac_path=" - for /f "delims=" %%i in ('pip show isaacsim-rl ^| findstr /c:"Location"') do ( + for /f "delims=" %%i in ('!python_exe! -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])"') do ( if not defined isaac_path ( set "isaac_path=%%i" ) diff --git a/isaaclab.sh b/isaaclab.sh index c3b13013e9..28214c8fba 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -33,8 +33,10 @@ extract_isaacsim_path() { else # Check if we have isaacsim-rl package installed if [ pip show isaacsim-rl > /dev/null 2>&1 ]; then - # Retrieve the path from location of isaacsim-rl package - local isaac_path=$(pip show isaacsim-rl | grep Location | cut -d ' ' -f 2) + # Use the python executable to get the path + local python_exe=$(extract_python_exe) + # Retrieve the path importing isaac sim and getting the environment path + local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") else # Use the sym-link path to Isaac Sim directory local isaac_path=${ISAACLAB_PATH}/_isaac_sim From 1234de4a40ece9554f9b4752ff76a0dbccd61890 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 00:18:21 +0200 Subject: [PATCH 08/25] checks steps for bash --- isaaclab.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/isaaclab.sh b/isaaclab.sh index 28214c8fba..6d60ebb7b4 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -31,8 +31,8 @@ extract_isaacsim_path() { # Use local build (for internal development) or user specified path local isaac_path=${ISAACSIM_PATH} else - # Check if we have isaacsim-rl package installed - if [ pip show isaacsim-rl > /dev/null 2>&1 ]; then + # Check if we have pip package installed + if [ $(pip list | grep -c 'isaacsim-rl') ]; then # Use the python executable to get the path local python_exe=$(extract_python_exe) # Retrieve the path importing isaac sim and getting the environment path @@ -59,9 +59,10 @@ extract_python_exe() { # use conda python local python_exe=${CONDA_PREFIX}/bin/python else - if [ pip show isaacsim-rl > /dev/null 2>&1 ]; then + # check if pip package is installed + if [ $(pip list | grep -c 'isaacsim-rl') ]; then # use current python executable - local python_exe=$(which python) + local python_exe=$(which python3) else # obtain the isaac sim path local isaac_path=$(extract_isaacsim_path) @@ -71,7 +72,7 @@ extract_python_exe() { fi # check if there is a python path available if [ ! -f "${python_exe}" ]; then - echo "[ERROR] No python executable found at path: ${isaac_path}" >&2 + echo "[ERROR] No python executable found at path: ${python_exe}" >&2 exit 1 fi # return the result From 08a57cfeab5f3e84523005019a8fce4dd1319a95 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 00:18:45 +0200 Subject: [PATCH 09/25] adds dockerfile for pip installation --- docker/Dockerfile.pip | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 docker/Dockerfile.pip diff --git a/docker/Dockerfile.pip b/docker/Dockerfile.pip new file mode 100644 index 0000000000..0b818b5804 --- /dev/null +++ b/docker/Dockerfile.pip @@ -0,0 +1,87 @@ +# Copyright (c) 2022-2024, The Isaac Lab Project Developers. +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause + +# This Dockerfile is used to build a Docker image for the Isaac Lab framework. +# +# It uses the pip package manager to install Isaac Sim and the Isaac Lab framework. +# +# To build the Docker image and run the Docker container, follow the steps below: +# +# 1. Build the Docker image: +# docker build -t isaac-lab:latest -f docker/Dockerfile.pip . +# 2. Run the Docker container: +# docker run -it --gpus all --rm --network=host --name isaac-lab isaac-lab:latest -v $(pwd):/root/isaaclab + +# Base image: Ubuntu 22.04 +FROM ubuntu:22.04 AS base + +# Set default RUN shell to bash +SHELL ["/bin/bash", "-c"] + +# Adds labels to the Dockerfile +LABEL version="1.0" +LABEL description="Dockerfile for building and running the Isaac Lab framework in Ubuntu 22.04 container image." + +# Arguments +# Path to the Isaac Lab directory +ENV ISAACLAB_PATH=/root/isaaclab +# Home dir of docker user, typically '/root' +ENV DOCKER_USER_HOME=/root + +# Set environment variables +ENV LANG=C.UTF-8 +ENV DEBIAN_FRONTEND=noninteractive + +USER root + +# Install dependencies and remove cache +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + cmake \ + git \ + libglib2.0-0 \ + ncurses-term && \ + apt -y autoremove && apt clean autoclean && \ + rm -rf /var/lib/apt/lists/* + +# for singularity usage, have to create the directories that will binded +RUN mkdir -p ${DOCKER_USER_HOME}/.cache/ov && \ + mkdir -p ${DOCKER_USER_HOME}/.cache/pip && \ + mkdir -p ${DOCKER_USER_HOME}/.cache/nvidia/GLCache && \ + mkdir -p ${DOCKER_USER_HOME}/.nv/ComputeCache && \ + mkdir -p ${DOCKER_USER_HOME}/.nvidia-omniverse/logs && \ + mkdir -p ${DOCKER_USER_HOME}/.local/share/ov/data && \ + mkdir -p ${DOCKER_USER_HOME}/Documents + +# for singularity usage, create NVIDIA binary placeholders +RUN touch /bin/nvidia-smi && \ + touch /bin/nvidia-debugdump && \ + touch /bin/nvidia-persistenced && \ + touch /bin/nvidia-cuda-mps-control && \ + touch /bin/nvidia-cuda-mps-server && \ + touch /etc/localtime && \ + mkdir -p /var/run/nvidia-persistenced && \ + touch /var/run/nvidia-persistenced/socket + +# Install python3 and pip +RUN apt-get update && apt-get install -y --no-install-recommends \ + python3 \ + python3-pip && \ + apt -y autoremove && apt clean autoclean && \ + rm -rf /var/lib/apt/lists/* + +# Install python packages +RUN pip3 install --no-cache-dir --upgrade pip && \ + pip install torch==2.2.2 --index-url https://download.pytorch.org/whl/cu118 + +RUN pip install isaacsim-rl isaacsim-replicator isaacsim-extscache-physics isaacsim-extscache-kit-sdk isaacsim-extscache-kit isaacsim-app --extra-index-url https://pypi.nvidia.com + +# Mount the Isaac Lab directory (files to exclude are defined in .dockerignore) +COPY ../ ${ISAACLAB_PATH} + +# make working directory as the Isaac Lab directory +# this is the default directory when the container is run +WORKDIR ${ISAACLAB_PATH} From 43682be786b4ef3a09afafafe49986a24b38daf2 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 00:23:42 +0200 Subject: [PATCH 10/25] adds python in pip dockerfile --- docker/Dockerfile.pip | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docker/Dockerfile.pip b/docker/Dockerfile.pip index 0b818b5804..91fa13c75f 100644 --- a/docker/Dockerfile.pip +++ b/docker/Dockerfile.pip @@ -72,6 +72,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ python3-pip && \ apt -y autoremove && apt clean autoclean && \ rm -rf /var/lib/apt/lists/* +# Maintain python3 as the default python version +RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1 +RUN update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 # Install python packages RUN pip3 install --no-cache-dir --upgrade pip && \ @@ -82,6 +85,16 @@ RUN pip install isaacsim-rl isaacsim-replicator isaacsim-extscache-physics isaac # Mount the Isaac Lab directory (files to exclude are defined in .dockerignore) COPY ../ ${ISAACLAB_PATH} +# installing Isaac Lab dependencies +# use pip caching to avoid reinstalling large packages +RUN --mount=type=cache,target=${DOCKER_USER_HOME}/.cache/pip \ + ${ISAACLAB_PATH}/isaaclab.sh --install + +# aliasing isaaclab.sh and python for convenience +RUN echo "export ISAACLAB_PATH=${ISAACLAB_PATH}" >> ${HOME}/.bashrc && \ + echo "alias isaaclab=${ISAACLAB_PATH}/isaaclab.sh" >> ${HOME}/.bashrc && \ + echo "export TZ=$(date +%Z)" >> ${HOME}/.bashrc + # make working directory as the Isaac Lab directory # this is the default directory when the container is run WORKDIR ${ISAACLAB_PATH} From ce363cc8dadb09c74ae076e84f8c3217f5c0b5d8 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 00:33:02 +0200 Subject: [PATCH 11/25] fixes docs --- docker/Dockerfile.pip | 2 +- .../setup/installation/binaries_installation.rst | 3 +++ .../setup/installation/pip_installation.rst | 16 +++++++++------- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile.pip b/docker/Dockerfile.pip index 91fa13c75f..69d36c4879 100644 --- a/docker/Dockerfile.pip +++ b/docker/Dockerfile.pip @@ -12,7 +12,7 @@ # 1. Build the Docker image: # docker build -t isaac-lab:latest -f docker/Dockerfile.pip . # 2. Run the Docker container: -# docker run -it --gpus all --rm --network=host --name isaac-lab isaac-lab:latest -v $(pwd):/root/isaaclab +# docker run -it --gpus all --rm --network=host --name isaac-lab -v $(pwd):/root/isaaclab isaac-lab:latest # Base image: Ubuntu 22.04 FROM ubuntu:22.04 AS base diff --git a/docs/source/setup/installation/binaries_installation.rst b/docs/source/setup/installation/binaries_installation.rst index 7607758bd2..f8738c0547 100644 --- a/docs/source/setup/installation/binaries_installation.rst +++ b/docs/source/setup/installation/binaries_installation.rst @@ -1,3 +1,6 @@ +.. _isaacsim-binaries-installation: + + Installation using Isaac Sim Binaries ===================================== diff --git a/docs/source/setup/installation/pip_installation.rst b/docs/source/setup/installation/pip_installation.rst index 0c58047253..7b42abe7a9 100644 --- a/docs/source/setup/installation/pip_installation.rst +++ b/docs/source/setup/installation/pip_installation.rst @@ -1,3 +1,5 @@ +.. _isaacsim-pip-installation: + Installation using Isaac Sim pip ================================ @@ -5,18 +7,18 @@ Installation using Isaac Sim pip Installing Isaac Sim -------------------- -.. note:: - - Installing Isaac Sim from pip is currently an experimental feature. - If errors occur, please report them to the - `Isaac Sim Forums `_ - and install Isaac Sim from pre-built binaries. +From Isaac Sim 4.0 release, it is possible to install Isaac Sim using pip. This approach is experimental and may have +compatibility issues with some Linux distributions. If you encounter any issues, please report them to the +`Isaac Sim Forums `_. -.. note:: +.. attention:: Installing Isaac Sim with pip requires GLIBC 2.34+ version compatibility. To check the GLIBC version on your system, use command ``ldd --version``. + This may pose compatibility issues with some Linux distributions. For instance, Ubuntu 20.04 LTS has GLIBC 2.31 + by default. If you encounter compatibility issues, we recommend following the + :ref:`Isaac Sim Binaries Installation ` approach. - To use the pip installation approach for Isaac Sim, we recommend first creating a virtual environment. Ensure that the python version of the virtual environment is **Python 3.10**. From c51cce31a61eb21bfeabebc1ba79780f1e2e0063 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 01:19:59 +0200 Subject: [PATCH 12/25] fixes vscode setup on launch --- .vscode/tools/setup_vscode.py | 76 ++++++++++++++++++----------------- isaaclab.bat | 8 +--- isaaclab.sh | 13 +++--- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 8156a1a943..42c15990a6 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -31,11 +31,11 @@ # check if the isaac-sim directory exists if not os.path.exists(isaacsim_dir): raise FileNotFoundError( - f"Could not find the isaac-sim directory: {isaacsim_dir}. There are two possible reasons for this:\n" - "\t1. The Isaac Sim directory does not exist as a symlink in the Isaac Lab directory.\n" - "\t2. The script could import the 'isaacsim' package. This could be due to the 'isaacsim' package not being " + f"Could not find the isaac-sim directory: {isaacsim_dir}. There are two possible reasons for this:" + f"\n\t1. The Isaac Sim directory does not exist as a symlink at: {os.path.join(ISAACLAB_DIR, '_isaac_sim')}" + "\n\t2. The script could import the 'isaacsim' package. This could be due to the 'isaacsim' package not being " "installed in the Python environment.\n" - "Please make sure that the Isaac Sim directory exists or that the 'isaacsim' package is installed." + "\nPlease make sure that the Isaac Sim directory exists or that the 'isaacsim' package is installed." ) ISAACSIM_DIR = isaacsim_dir @@ -48,39 +48,46 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: The extraPaths are replaced with the path names from the isaac-sim settings file that exists in the "{ISAACSIM_DIR}/.vscode/settings.json" file. + If the isaac-sim settings file does not exist, the extraPaths are not overwritten. + Args: isaaclab_settings: The settings string to use as template. Returns: The settings string with overwritten python analysis extra paths. - - Raises: - FileNotFoundError: If the isaac-sim settings file does not exist. """ # isaac-sim settings isaacsim_vscode_filename = os.path.join(ISAACSIM_DIR, ".vscode", "settings.json") - # make sure the isaac-sim settings file exists - if not os.path.exists(isaacsim_vscode_filename): - raise FileNotFoundError(f"Could not find the isaac-sim settings file: {isaacsim_vscode_filename}") - - # read the path names from the isaac-sim settings file - with open(isaacsim_vscode_filename) as f: - vscode_settings = f.read() - # extract the path names - # search for the python.analysis.extraPaths section and extract the contents - settings = re.search(r"\"python.analysis.extraPaths\": \[.*?\]", vscode_settings, flags=re.MULTILINE | re.DOTALL) - settings = settings.group(0) - settings = settings.split('"python.analysis.extraPaths": [')[-1] - settings = settings.split("]")[0] - - # read the path names from the isaac-sim settings file - path_names = settings.split(",") - path_names = [path_name.strip().strip('"') for path_name in path_names] - path_names = [path_name for path_name in path_names if len(path_name) > 0] - - # change the path names to be relative to the Isaac Lab directory - rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR) - path_names = ['"${workspaceFolder}/' + rel_path + "/" + path_name + '"' for path_name in path_names] + + # we use the isaac-sim settings file to get the python.analysis.extraPaths for kit extensions + # if this file does not exist, we will not add any extra paths + if os.path.exists(isaacsim_vscode_filename): + # read the path names from the isaac-sim settings file + with open(isaacsim_vscode_filename) as f: + vscode_settings = f.read() + # extract the path names + # search for the python.analysis.extraPaths section and extract the contents + settings = re.search(r"\"python.analysis.extraPaths\": \[.*?\]", vscode_settings, flags=re.MULTILINE | re.DOTALL) + settings = settings.group(0) + settings = settings.split('"python.analysis.extraPaths": [')[-1] + settings = settings.split("]")[0] + + # read the path names from the isaac-sim settings file + path_names = settings.split(",") + path_names = [path_name.strip().strip('"') for path_name in path_names] + path_names = [path_name for path_name in path_names if len(path_name) > 0] + + # change the path names to be relative to the Isaac Lab directory + rel_path = os.path.relpath(ISAACSIM_DIR, ISAACLAB_DIR) + path_names = ['"${workspaceFolder}/' + rel_path + "/" + path_name + '"' for path_name in path_names] + else: + path_names = [] + print( + f"[WARN] Could not find Isaac Sim VSCode settings file: {isaacsim_vscode_filename}." + "\n\tThis will result in missing python.analysis.extraPaths in Isaac Lab VSCode settings from Isaac Sim." + " It limits the functionality of Python language server in VSCode." + "\n\tHowever, it does not affect the functionality of the Isaac Lab project." + ) # add the path names that are in the Isaac Lab extensions directory isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions")) @@ -91,7 +98,7 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: # deal with the path separator being different on Windows and Unix path_names = path_names.replace("/", os.sep) - # replace the path names in the Isaac Lab settings file with the path names from the isaac-sim settings file + # replace the path names in the Isaac Lab settings file with the path names parsed isaaclab_settings = re.sub( r"\"python.analysis.extraPaths\": \[.*?\]", '"python.analysis.extraPaths": [\n\t\t'.expandtabs(4) + path_names + "\n\t]".expandtabs(4), @@ -117,9 +124,6 @@ def overwrite_default_python_interpreter(isaaclab_settings: str) -> str: """ # read executable name python_exe = sys.executable - # if python interpreter is from conda, use that. Otherwise, use the template. - if "conda" not in python_exe: - return isaaclab_settings # replace the default python interpreter in the Isaac Lab settings file with the path to the # python interpreter in the Isaac Lab directory isaaclab_settings = re.sub( @@ -146,9 +150,9 @@ def main(): # overwrite the python.analysis.extraPaths in the Isaac Lab settings file with the path names isaaclab_settings = overwrite_python_analysis_extra_paths(isaaclab_template_settings) - # overwrite the default python interpreter in the Isaac Lab settings file - # NOTE: thisis disabled since we don't need it. The default interpreter should always be the one from isaac-sim - # isaaclab_settings = overwrite_default_python_interpreter(isaaclab_settings) + # overwrite the default python interpreter in the Isaac Lab settings file with the path to the + # python interpreter used to call this script + isaaclab_settings = overwrite_default_python_interpreter(isaaclab_settings) # add template notice to the top of the file header_message = ( diff --git a/isaaclab.bat b/isaaclab.bat index eff635827b..d525969771 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -241,12 +241,6 @@ if "%arg%"=="-i" ( set ext_folder="%%d" call :install_isaaclab_extension ) - call !python_exe! -m pip show isaacsim-rl > nul 2>&1 - rem if not installing from pip, set up VScode - if errorlevel 1 ( - rem setup vscode settings - call :update_vscode_settings - ) rem install the python packages for supported reinforcement learning frameworks echo [INFO] Installing extra requirements such as learning frameworks... if "%~2"=="" ( @@ -263,6 +257,8 @@ if "%arg%"=="-i" ( ) rem install the rl-frameworks specified !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] + rem setup vscode settings + call :update_vscode_settings shift ) else if "%arg%"=="--install" ( rem install the python packages in omni.isaac.rl/source directory diff --git a/isaaclab.sh b/isaaclab.sh index 6d60ebb7b4..0ed0ac806c 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -238,12 +238,6 @@ while [[ $# -gt 0 ]]; do export -f install_isaaclab_extension # source directory find -L "${ISAACLAB_PATH}/source/extensions" -mindepth 1 -maxdepth 1 -type d -exec bash -c 'install_isaaclab_extension "{}"' \; - # unset local variables - unset install_isaaclab_extension - # setup vscode settings - if ! ${python_exe} -m pip show isaacsim-rl &>/dev/null; then - update_vscode_settings - fi # install the python packages for supported reinforcement learning frameworks echo "[INFO] Installing extra requirements such as learning frameworks..." # check if specified which rl-framework to install @@ -261,6 +255,11 @@ while [[ $# -gt 0 ]]; do fi # install the rl-frameworks specified ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/extensions/omni.isaac.lab_tasks["${framework_name}"] + # setup vscode settings + update_vscode_settings + # unset local variables + unset extract_python_exe + unset install_isaaclab_extension shift # past argument ;; -c|--conda) @@ -287,7 +286,7 @@ while [[ $# -gt 0 ]]; do fi # run the formatter over the repository # check if pre-commit is installed - if ! command -v pre-commit &>/dev/null; then + if [ ! command -v pre-commit &>/dev/null ]; then echo "[INFO] Installing pre-commit..." pip install pre-commit fi From c85f1196cdb3433673c1f97de476055c81e69805 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 01:26:17 +0200 Subject: [PATCH 13/25] runs formatter --- .vscode/tools/setup_vscode.py | 4 +++- docker/Dockerfile.pip | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 42c15990a6..1db12d4043 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -67,7 +67,9 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: vscode_settings = f.read() # extract the path names # search for the python.analysis.extraPaths section and extract the contents - settings = re.search(r"\"python.analysis.extraPaths\": \[.*?\]", vscode_settings, flags=re.MULTILINE | re.DOTALL) + settings = re.search( + r"\"python.analysis.extraPaths\": \[.*?\]", vscode_settings, flags=re.MULTILINE | re.DOTALL + ) settings = settings.group(0) settings = settings.split('"python.analysis.extraPaths": [')[-1] settings = settings.split("]")[0] diff --git a/docker/Dockerfile.pip b/docker/Dockerfile.pip index 69d36c4879..5053638c11 100644 --- a/docker/Dockerfile.pip +++ b/docker/Dockerfile.pip @@ -12,7 +12,7 @@ # 1. Build the Docker image: # docker build -t isaac-lab:latest -f docker/Dockerfile.pip . # 2. Run the Docker container: -# docker run -it --gpus all --rm --network=host --name isaac-lab -v $(pwd):/root/isaaclab isaac-lab:latest +# docker run -it --gpus all --rm --network=host --name isaac-lab -v $(pwd):/root/isaaclab isaac-lab:latest # Base image: Ubuntu 22.04 FROM ubuntu:22.04 AS base From 682882bf75e8005258403a7ab97baabebe3c3072 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 07:27:48 +0200 Subject: [PATCH 14/25] fixes based on kelly --- .vscode/tools/setup_vscode.py | 2 -- isaaclab.bat | 19 ++++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 1db12d4043..77c5451004 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -97,8 +97,6 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: # combine them into a single string path_names = ",\n\t\t".expandtabs(4).join(path_names) - # deal with the path separator being different on Windows and Unix - path_names = path_names.replace("/", os.sep) # replace the path names in the Isaac Lab settings file with the path names parsed isaaclab_settings = re.sub( diff --git a/isaaclab.bat b/isaaclab.bat index d525969771..c432b8598f 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -46,8 +46,6 @@ goto :eof rem extract the python from isaacsim :extract_python_exe -rem obtain isaacsim path -call :extract_isaacsim_path rem check if using conda if not "%CONDA_PREFIX%"=="" ( rem use conda python @@ -56,6 +54,8 @@ if not "%CONDA_PREFIX%"=="" ( rem check if isaacsim is installed pip show isaacsim-rl > nul 2>&1 if errorlevel 1 ( + rem obtain isaacsim path + call :extract_isaacsim_path rem use python from kit if Isaac Sim not installed from pip set python_exe=%isaac_path%\python.bat ) else ( @@ -176,8 +176,8 @@ echo [INFO] Created conda environment named '%env_name%'. echo. echo 1. To activate the environment, run: conda activate %env_name% echo 2. To install Isaac Lab extensions, run: isaaclab -i -echo 4. To perform formatting, run: isaaclab -f -echo 5. To deactivate the environment, run: conda deactivate +echo 3. To perform formatting, run: isaaclab -f +echo 4. To deactivate the environment, run: conda deactivate echo. goto :eof @@ -268,12 +268,6 @@ if "%arg%"=="-i" ( set ext_folder="%%d" call :install_isaaclab_extension ) - call !python_exe! -m pip show isaacsim-rl > nul 2>&1 - rem if not installing from pip, set up VScode - if errorlevel 1 ( - rem setup vscode settings - call :update_vscode_settings - ) rem install the python packages for supported reinforcement learning frameworks echo [INFO] Installing extra requirements such as learning frameworks... if "%~2"=="" ( @@ -289,7 +283,10 @@ if "%arg%"=="-i" ( shift ) rem install the rl-frameworks specified - !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] + call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] + rem if not installing from pip, set up VScode + rem setup vscode settings + call :update_vscode_settings shift ) else if "%arg%"=="-c" ( rem use default name if not provided From df24b93c83f3777bd4665d6c583a03d4c34f9180 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Thu, 4 Jul 2024 07:49:13 +0200 Subject: [PATCH 15/25] adds throwing error for wrong python version --- isaaclab.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/isaaclab.sh b/isaaclab.sh index 0ed0ac806c..ed114a1ab6 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -62,7 +62,7 @@ extract_python_exe() { # check if pip package is installed if [ $(pip list | grep -c 'isaacsim-rl') ]; then # use current python executable - local python_exe=$(which python3) + local python_exe=$(which python) else # obtain the isaac sim path local isaac_path=$(extract_isaacsim_path) @@ -75,6 +75,12 @@ extract_python_exe() { echo "[ERROR] No python executable found at path: ${python_exe}" >&2 exit 1 fi + # kit dependencies are built with python 3.10 so any other version will not work + # this is needed in case users have multiple python versions installed and the wrong one is being used + if [ "$(${python_exe} --version | grep -c '3.10')" -eq 0 ]; then + echo "[ERROR] Found version: $(${python_exe} --version) while expecting 3.10. Please use the correct python version." >&2 + exit 1 + fi # return the result echo ${python_exe} } From cc26f0aa56f2e3dbde4104a9e8c3d4a4445bac76 Mon Sep 17 00:00:00 2001 From: Kelly Guo Date: Thu, 4 Jul 2024 10:28:03 -0400 Subject: [PATCH 16/25] fix backslash in paths --- .vscode/tools/setup_vscode.py | 6 +++--- isaaclab.bat | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 77c5451004..d4ebcc8a0e 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -95,8 +95,8 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: isaaclab_extensions = os.listdir(os.path.join(ISAACLAB_DIR, "source", "extensions")) path_names.extend(['"${workspaceFolder}/source/extensions/' + ext + '"' for ext in isaaclab_extensions]) - # combine them into a single string - path_names = ",\n\t\t".expandtabs(4).join(path_names) + # combine them into a single string and standardize to forward slashes + path_names = ",\n\t\t".expandtabs(4).join(path_names).replace("\\", "/") # replace the path names in the Isaac Lab settings file with the path names parsed isaaclab_settings = re.sub( @@ -123,7 +123,7 @@ def overwrite_default_python_interpreter(isaaclab_settings: str) -> str: The settings string with overwritten default python interpreter. """ # read executable name - python_exe = sys.executable + python_exe = sys.executable.replace("\\", "/") # replace the default python interpreter in the Isaac Lab settings file with the path to the # python interpreter in the Isaac Lab directory isaaclab_settings = re.sub( diff --git a/isaaclab.bat b/isaaclab.bat index c432b8598f..d7765a004b 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -256,7 +256,7 @@ if "%arg%"=="-i" ( shift ) rem install the rl-frameworks specified - !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] + call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] rem setup vscode settings call :update_vscode_settings shift @@ -284,7 +284,6 @@ if "%arg%"=="-i" ( ) rem install the rl-frameworks specified call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] - rem if not installing from pip, set up VScode rem setup vscode settings call :update_vscode_settings shift From bdd772eefea78d516036468b1bd7e920448d4eb8 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 01:36:28 +0200 Subject: [PATCH 17/25] makes yq installation not mandatory --- docker/container.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/docker/container.sh b/docker/container.sh index cde4fd69ca..c8789bb36f 100755 --- a/docker/container.sh +++ b/docker/container.sh @@ -25,7 +25,7 @@ fi # print the usage description print_help () { - echo -e "\nusage: $(basename "$0") [-h] [run] [start] [stop] -- Utility for handling docker in Isaac Lab." + echo -e "\nusage: $(basename "$0") [-h] [...] -- Utility for handling Docker in Isaac Lab." echo -e "\noptional arguments:" echo -e "\t-h, --help Display the help content." echo -e "\tstart [profile] Build the docker image and create the container in detached mode." @@ -36,8 +36,9 @@ print_help () { echo -e "\tjob [profile] [job_args] Submit a job to the cluster." echo -e "\tconfig [profile] Parse, resolve and render compose file in canonical format." echo -e "\n" - echo -e "[profile] is the optional container profile specification and [job_args] optional arguments specific" - echo -e "to the executed script" + echo -e "where: " + echo -e "\t[profile] is the optional container profile specification. Example: 'isaaclab', 'base', 'ros2'." + echo -e "\t[job_args] are optional arguments specific to the executed script." echo -e "\n" >&2 } @@ -56,8 +57,8 @@ install_apptainer() { install_yq() { # Installing yq to handle file parsing - # Installation procedure from here: https://github.com/mikefarah/yq - read -p "[INFO] Required 'yq' package could not be found. Would you like to install it via wget? (y/N)" yq_answer + # Installation procedure from here: https://github.com/mikefarah/yq?tab=readme-ov-file#linux-via-snap + read -p "[INFO] Required 'yq' package could not be found. Would you like to install it via snap? (y/N)" yq_answer if [ "$yq_answer" != "${yq_answer#[Yy]}" ]; then sudo snap install yq else @@ -67,17 +68,29 @@ install_yq() { } set_statefile_variable() { + # Check if yq is installed + if ! command -v yq &> /dev/null; then + install_yq + fi # Stores key $1 with value $2 in yaml $STATEFILE yq -i '.["'"$1"'"] = "'"$2"'"' $STATEFILE } load_statefile_variable() { + # Check if yq is installed + if ! command -v yq &> /dev/null; then + install_yq + fi # Loads key $1 from yaml $STATEFILE as an envvar # If key does not exist, the loaded var will equal "null" eval $1="$(yq ".$1" $STATEFILE)" } delete_statefile_variable() { + # Check if yq is installed + if ! command -v yq &> /dev/null; then + install_yq + fi # Deletes key $1 from yaml $STATEFILE yq -i "del(.$1)" $STATEFILE } @@ -270,10 +283,6 @@ if ! command -v docker &> /dev/null; then exit 1 fi -if ! command -v yq &> /dev/null; then - install_yq -fi - # parse arguments mode="$1" profile_arg="$2" # Capture the second argument as the potential profile argument From 1cc8e21b616e944003d8aa6df7b8c21be8de363d Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 01:38:17 +0200 Subject: [PATCH 18/25] simplify logic in windows --- isaaclab.bat | 56 +++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/isaaclab.bat b/isaaclab.bat index d7765a004b..c58ab0ccd3 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -14,20 +14,16 @@ rem Helper functions rem extract Isaac Sim directory :extract_isaacsim_path -rem Check if IsaacSim directory manually specified -if not "%ISAACSIM_PATH%"=="" ( - rem Use local build - set isaac_path=%ISAACSIM_PATH% -) else ( - rem check if isaacsim is installed - pip show isaacsim-rl > nul 2>&1 +rem check if conda environment is activated and isaacsim package is installed +if not "%CONDA_PREFIX%"=="" ( + rem use conda python + set python_exe=%CONDA_PREFIX%\python + call %python_exe% -m pip show isaacsim-rl > nul 2>&1 if errorlevel 1 ( - rem Use TeamCity build or pip install - set isaac_path=%ISAACLAB_PATH%\_isaac_sim + rem set isaac path to empty + set isaac_path= ) else ( - rem use the python executable to get the path - call :extract_python_exe - rem retrieve the isaacsim path + rem retrieve the isaacsim path from the installed package set "isaac_path=" for /f "delims=" %%i in ('!python_exe! -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])"') do ( if not defined isaac_path ( @@ -35,11 +31,16 @@ if not "%ISAACSIM_PATH%"=="" ( ) ) ) +) else ( + rem Use the sym-link path to Isaac Sim directory + set isaac_path=%ISAACLAB_PATH%\_isaac_sim ) rem Check if the directory exists if not exist "%isaac_path%" ( - echo [ERROR] Isaac Sim directory not found at path: %isaac_path% - echo [ERROR] Please specify the path to Isaac Sim directory using 'ISAACSIM_PATH' environment variable. + echo [ERROR] Unable to find the Isaac Sim directory: %isaac_path% + echo /tThis could be due to the following reasons: + echo /t1. Conda environment with Isaac Sim pip package is not activated. + echo /t2. Isaac Sim directory is not available at the default path: %ISAACLAB_PATH%\_isaac_sim exit /b 1 ) goto :eof @@ -51,26 +52,17 @@ if not "%CONDA_PREFIX%"=="" ( rem use conda python set python_exe=%CONDA_PREFIX%\python ) else ( - rem check if isaacsim is installed - pip show isaacsim-rl > nul 2>&1 - if errorlevel 1 ( - rem obtain isaacsim path - call :extract_isaacsim_path - rem use python from kit if Isaac Sim not installed from pip - set python_exe=%isaac_path%\python.bat - ) else ( - rem use current python if Isaac Sim is installed from pip - set "python_exe=" - for /f "delims=" %%i in ('where python') do ( - if not defined python_exe ( - set "python_exe=%%i" - ) - ) - ) + rem obtain isaacsim path + call :extract_isaacsim_path + rem use python from kit if Isaac Sim not installed from pip + set python_exe=%isaac_path%\python.bat ) rem check if there is a python path available if "%python_exe%"=="" ( - echo [ERROR] No python executable found at path: %isaac_path% + echo [ERROR] Unable to find any Python executable at path: %isaac_path% + echo /tThis could be due to the following reasons: + echo /t1. Conda environment is not activated. + echo /t2. Python executable is not available at the default path: %ISAACLAB_PATH%\_isaac_sim\python.bat exit /b 1 ) goto :eof @@ -257,8 +249,6 @@ if "%arg%"=="-i" ( ) rem install the rl-frameworks specified call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] - rem setup vscode settings - call :update_vscode_settings shift ) else if "%arg%"=="--install" ( rem install the python packages in omni.isaac.rl/source directory From 64d928b10d2f7f4ef65d493f3f6a559b44f94e48 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 01:47:29 +0200 Subject: [PATCH 19/25] deals with docker container cases --- isaaclab.sh | 72 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/isaaclab.sh b/isaaclab.sh index ed114a1ab6..2e391d1276 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -24,28 +24,40 @@ export ISAACLAB_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && p # extract isaac sim path extract_isaacsim_path() { - # Check if IsaacSim directory manually specified - # Note: for manually build isaacsim, this: _build/linux-x86_64/release - if [ ! -z ${ISAACSIM_PATH} ]; - then - # Use local build (for internal development) or user specified path - local isaac_path=${ISAACSIM_PATH} - else - # Check if we have pip package installed - if [ $(pip list | grep -c 'isaacsim-rl') ]; then - # Use the python executable to get the path - local python_exe=$(extract_python_exe) - # Retrieve the path importing isaac sim and getting the environment path + # Check if we have pip package installed inside conda environment + if ! [[ -z "${CONDA_PREFIX}" ]]; then + # Use the python executable to get the path + local python_exe=${CONDA_PREFIX}/bin/python + # Retrieve the path importing isaac sim and getting the environment path + if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") else - # Use the sym-link path to Isaac Sim directory - local isaac_path=${ISAACLAB_PATH}/_isaac_sim + # If package not installed, use an empty path for failure + local isaac_path='' fi + elif command -v python &> /dev/null; then + # Use the python executable to get the path + local python_exe=$(which python) + # Retrieve the path importing isaac sim and getting the environment path + if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then + local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") + else + # If package not installed, use an empty path for failure + local isaac_path='' + fi + else + # Use the sym-link path to Isaac Sim directory + local isaac_path=${ISAACLAB_PATH}/_isaac_sim fi # check if there is a path available if [ ! -d "${isaac_path}" ]; then - echo "[ERROR] No Isaac Sim directory found at path: ${isaac_path}" >&2 - echo "[ERROR] Please specify the path to the Isaac Sim directory using 'ISAACSIM_PATH' environment variable." >&2 + # throw an error if no path is found + echo -e "[ERROR] Unable to find the Isaac Sim directory: '${isaac_path}'" >&2 + echo -e "\tThis could be due to the following reasons:" >&2 + echo -e "\t1. Conda environment is not activated." >&2 + echo -e "\t2. Isaac Sim pip package 'isaacsim-rl' is not installed." >&2 + echo -e "\t3. Isaac Sim directory is not available at the default path: ${ISAACLAB_PATH}/_isaac_sim" >&2 + # exit the script exit 1 fi # return the result @@ -58,27 +70,33 @@ extract_python_exe() { if ! [[ -z "${CONDA_PREFIX}" ]]; then # use conda python local python_exe=${CONDA_PREFIX}/bin/python - else - # check if pip package is installed - if [ $(pip list | grep -c 'isaacsim-rl') ]; then - # use current python executable + elif command -v python &> /dev/null; then + # use the python executable to get the path + if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then local python_exe=$(which python) else - # obtain the isaac sim path - local isaac_path=$(extract_isaacsim_path) - # use python from kit - local python_exe=${isaac_path}/python.sh + # leave a blank path for failure + local python_exe='' fi + else + # obtain the isaac sim path + local isaac_path=$(extract_isaacsim_path) + # use python from kit + local python_exe=${isaac_path}/python.sh fi # check if there is a python path available if [ ! -f "${python_exe}" ]; then - echo "[ERROR] No python executable found at path: ${python_exe}" >&2 + echo -e "[ERROR] Unable to find any Python executable at path: '${python_exe}'" >&2 + echo -e "\tThis could be due to the following reasons:" >&2 + echo -e "\t1. Conda environment is not activated." >&2 + echo -e "\t2. Isaac Sim pip package 'isaacsim-rl' is not installed." >&2 + echo -e "\t3. Python executable is not available at the default path: ${ISAACLAB_PATH}/_isaac_sim/python.sh" >&2 exit 1 fi # kit dependencies are built with python 3.10 so any other version will not work # this is needed in case users have multiple python versions installed and the wrong one is being used if [ "$(${python_exe} --version | grep -c '3.10')" -eq 0 ]; then - echo "[ERROR] Found version: $(${python_exe} --version) while expecting 3.10. Please use the correct python version." >&2 + echo "[ERROR] Found Python version: $(${python_exe} --version) while expecting 3.10. Please use the correct python version." >&2 exit 1 fi # return the result @@ -261,8 +279,6 @@ while [[ $# -gt 0 ]]; do fi # install the rl-frameworks specified ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/extensions/omni.isaac.lab_tasks["${framework_name}"] - # setup vscode settings - update_vscode_settings # unset local variables unset extract_python_exe unset install_isaaclab_extension From 0be5e7e73f4dacf4552970d20ea07cc8bb45097b Mon Sep 17 00:00:00 2001 From: Kelly Guo Date: Thu, 4 Jul 2024 21:12:50 -0400 Subject: [PATCH 20/25] fixes for windows script --- isaaclab.bat | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/isaaclab.bat b/isaaclab.bat index c58ab0ccd3..0ef973d6ca 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -18,7 +18,7 @@ rem check if conda environment is activated and isaacsim package is installed if not "%CONDA_PREFIX%"=="" ( rem use conda python set python_exe=%CONDA_PREFIX%\python - call %python_exe% -m pip show isaacsim-rl > nul 2>&1 + call !python_exe! -m pip show isaacsim-rl > nul 2>&1 if errorlevel 1 ( rem set isaac path to empty set isaac_path= @@ -38,9 +38,9 @@ if not "%CONDA_PREFIX%"=="" ( rem Check if the directory exists if not exist "%isaac_path%" ( echo [ERROR] Unable to find the Isaac Sim directory: %isaac_path% - echo /tThis could be due to the following reasons: - echo /t1. Conda environment with Isaac Sim pip package is not activated. - echo /t2. Isaac Sim directory is not available at the default path: %ISAACLAB_PATH%\_isaac_sim + echo %tab%This could be due to the following reasons: + echo %tab%1. Conda environment with Isaac Sim pip package is not activated. + echo %tab%2. Isaac Sim directory is not available at the default path: %ISAACLAB_PATH%\_isaac_sim exit /b 1 ) goto :eof @@ -55,14 +55,14 @@ if not "%CONDA_PREFIX%"=="" ( rem obtain isaacsim path call :extract_isaacsim_path rem use python from kit if Isaac Sim not installed from pip - set python_exe=%isaac_path%\python.bat + set python_exe=!isaac_path!\python.bat ) rem check if there is a python path available if "%python_exe%"=="" ( echo [ERROR] Unable to find any Python executable at path: %isaac_path% - echo /tThis could be due to the following reasons: - echo /t1. Conda environment is not activated. - echo /t2. Python executable is not available at the default path: %ISAACLAB_PATH%\_isaac_sim\python.bat + echo %tab%This could be due to the following reasons: + echo %tab%1. Conda environment is not activated. + echo %tab%2. Python executable is not available at the default path: %ISAACLAB_PATH%\_isaac_sim\python.bat exit /b 1 ) goto :eof @@ -70,13 +70,20 @@ goto :eof rem extract the simulator exe from isaacsim :extract_isaacsim_exe -rem obtain isaacsim path -call :extract_isaacsim_path -rem python executable to use -set isaacsim_exe=%isaac_path%\isaac-sim.bat +call :extract_python_exe +call !python_exe! -m pip show isaacsim-rl > nul 2>&1 +if errorlevel 1 ( + rem obtain isaacsim path + call :extract_isaacsim_path + rem python executable to use + set isaacsim_exe=!isaac_path!\isaac-sim.bat +) else ( + rem if isaac sim installed from pip + set isaacsim_exe=isaacsim +) rem check if there is a python path available if not exist "%isaacsim_exe%" ( - echo [ERROR] No isaac-sim executable found at path: %isaac_path% + echo [ERROR] No isaac-sim executable found at path: !isaac_path! exit /b 1 ) goto :eof @@ -178,7 +185,7 @@ rem Update the vscode settings from template and Isaac Sim settings :update_vscode_settings echo [INFO] Setting up vscode settings... rem Retrieve the python executable -call :extract_python_exe python_exe +call :extract_python_exe rem Path to setup_vscode.py set "setup_vscode_script=%ISAACLAB_PATH%\.vscode\tools\setup_vscode.py" rem Check if the file exists before attempting to run it @@ -274,8 +281,6 @@ if "%arg%"=="-i" ( ) rem install the rl-frameworks specified call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] - rem setup vscode settings - call :update_vscode_settings shift ) else if "%arg%"=="-c" ( rem use default name if not provided @@ -392,7 +397,7 @@ if "%arg%"=="-i" ( ) else if "%arg%"=="-s" ( rem run the simulator exe provided by isaacsim call :extract_isaacsim_exe - echo [INFO] Running isaac-sim from: %isaacsim_exe% + echo [INFO] Running isaac-sim from: !isaacsim_exe! set "allArgs=" for %%a in (%*) do ( REM Append each argument to the variable, skip the first one @@ -407,7 +412,7 @@ if "%arg%"=="-i" ( ) else if "%arg%"=="--sim" ( rem run the simulator exe provided by Isaac Sim call :extract_isaacsim_exe - echo [INFO] Running isaac-sim from: %isaacsim_exe% + echo [INFO] Running isaac-sim from: !isaacsim_exe! set "allArgs=" for %%a in (%*) do ( REM Append each argument to the variable, skip the first one From 5d050c602d5ce0d25c7b2a08201f89953b67cf65 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 10:09:18 +0200 Subject: [PATCH 21/25] deals with corner cases --- isaaclab.bat | 27 +++++++++++++++++++++++---- isaaclab.sh | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/isaaclab.bat b/isaaclab.bat index 0ef973d6ca..b04ce061dc 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -20,8 +20,8 @@ if not "%CONDA_PREFIX%"=="" ( set python_exe=%CONDA_PREFIX%\python call !python_exe! -m pip show isaacsim-rl > nul 2>&1 if errorlevel 1 ( - rem set isaac path to empty - set isaac_path= + rem Use the sym-link path to Isaac Sim directory + set isaac_path=%ISAACLAB_PATH%\_isaac_sim ) else ( rem retrieve the isaacsim path from the installed package set "isaac_path=" @@ -132,25 +132,43 @@ call conda activate %env_name% rem setup directories to load isaac-sim variables mkdir "%CONDA_PREFIX%\etc\conda\activate.d" 2>nul mkdir "%CONDA_PREFIX%\etc\conda\deactivate.d" 2>nul + +rem obtain isaacsim path +call :extract_isaacsim_path + rem add variables to environment during activation ( echo @echo off - rem for isaac-sim + echo rem for isaac-sim echo set "RESOURCE_NAME=IsaacSim" - rem for isaac-lab + echo set CARB_APP_PATH=!isaac_path!\kit + echo set EXP_PATH=!isaac_path!\apps + echo set ISAAC_PATH=!isaac_path! + echo set PYTHONPATH=%PYTHONPATH%;!isaac_path!\site + echo. + echo rem for isaac-lab echo doskey isaaclab=isaaclab.bat $* ) > "%CONDA_PREFIX%\etc\conda\activate.d\env_vars.bat" ( + echo $env:CARB_APP_PATH="!isaac_path!\kit" + echo $env:EXP_PATH="!isaac_path!\apps" + echo $env:ISAAC_PATH="!isaac_path!" + echo $env:PYTHONPATH="%PYTHONPATH%;!isaac_path!\site" echo $env:RESOURCE_NAME="IsaacSim" ) > "%CONDA_PREFIX%\etc\conda\activate.d\env_vars.ps1" rem reactivate the environment to load the variables call conda activate %env_name% + rem remove variables from environment during deactivation ( echo @echo off echo rem for isaac-sim + echo set "CARB_APP_PATH=" + echo set "EXP_PATH=" + echo set "ISAAC_PATH=" echo set "RESOURCE_NAME=" + echo. echo rem for isaac-lab echo doskey isaaclab = echo. @@ -167,6 +185,7 @@ rem remove variables from environment during deactivation rem install some extra dependencies echo [INFO] Installing extra dependencies (this might take a few minutes)... call conda install -c conda-forge -y importlib_metadata >nul 2>&1 + rem deactivate the environment call conda deactivate rem add information to the user about alias diff --git a/isaaclab.sh b/isaaclab.sh index 2e391d1276..648a5bab44 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -32,10 +32,11 @@ extract_isaacsim_path() { if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") else - # If package not installed, use an empty path for failure - local isaac_path='' + # If package not installed, try with the default path + local isaac_path=${ISAACLAB_PATH}/_isaac_sim fi elif command -v python &> /dev/null; then + # note: we need to deal with this case because of docker containers # Use the python executable to get the path local python_exe=$(which python) # Retrieve the path importing isaac sim and getting the environment path @@ -71,6 +72,7 @@ extract_python_exe() { # use conda python local python_exe=${CONDA_PREFIX}/bin/python elif command -v python &> /dev/null; then + # note: we need to deal with this case because of docker containers # use the python executable to get the path if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then local python_exe=$(which python) @@ -170,6 +172,17 @@ setup_conda_env() { '# show icon if not runninng headless' \ 'export RESOURCE_NAME="IsaacSim"' \ '' > ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh + + # check if we have _isaac_sim directory -> if so that means binaries were installed. + # we need to setup conda variables to load the binaries + local isaacsim_setup_conda_env_script=${ISAACLAB_PATH}/_isaac_sim/setup_conda_env.sh + if [ -f "${isaacsim_setup_conda_env_script}" ]; then + # add variables to environment during activation + printf '' \ + '# for Isaac Sim' \ + 'source '${isaacsim_setup_conda_env_script}'' \ + '' >> ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh + fi # reactivate the environment to load the variables # needed because deactivate complains about Isaac Lab alias since it otherwise doesn't exist @@ -181,13 +194,25 @@ setup_conda_env() { 'unalias isaaclab &>/dev/null' \ 'unset ISAACLAB_PATH' \ '' \ - '# for Isaac Sim' \ - 'unset RESOURCE_NAME' \ - '' \ '# restore paths' \ 'export PYTHONPATH='${cache_pythonpath}'' \ 'export LD_LIBRARY_PATH='${cache_ld_library_path}'' \ + '' \ + '# for Isaac Sim' \ + 'unset RESOURCE_NAME' \ '' > ${CONDA_PREFIX}/etc/conda/deactivate.d/unsetenv.sh + + # check if we have _isaac_sim directory -> if so that means binaries were installed. + if [ -f "${isaacsim_setup_conda_env_script}" ]; then + # add variables to environment during activation + printf '' \ + '# for Isaac Sim' \ + 'unset CARB_APP_PATH' \ + 'unset EXP_PATH' \ + 'unset ISAAC_PATH' \ + '' >> ${CONDA_PREFIX}/etc/conda/deactivate.d/unsetenv.sh + fi + # install some extra dependencies echo -e "[INFO] Installing extra dependencies (this might take a few minutes)..." conda install -c conda-forge -y importlib_metadata &> /dev/null From 467c27220f2dfd09c562c75b9a9ea6bdca8827a1 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 10:09:33 +0200 Subject: [PATCH 22/25] runs formatter --- isaaclab.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/isaaclab.sh b/isaaclab.sh index 648a5bab44..c3630bbf65 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -172,7 +172,7 @@ setup_conda_env() { '# show icon if not runninng headless' \ 'export RESOURCE_NAME="IsaacSim"' \ '' > ${CONDA_PREFIX}/etc/conda/activate.d/setenv.sh - + # check if we have _isaac_sim directory -> if so that means binaries were installed. # we need to setup conda variables to load the binaries local isaacsim_setup_conda_env_script=${ISAACLAB_PATH}/_isaac_sim/setup_conda_env.sh @@ -201,7 +201,7 @@ setup_conda_env() { '# for Isaac Sim' \ 'unset RESOURCE_NAME' \ '' > ${CONDA_PREFIX}/etc/conda/deactivate.d/unsetenv.sh - + # check if we have _isaac_sim directory -> if so that means binaries were installed. if [ -f "${isaacsim_setup_conda_env_script}" ]; then # add variables to environment during activation @@ -212,7 +212,7 @@ setup_conda_env() { 'unset ISAAC_PATH' \ '' >> ${CONDA_PREFIX}/etc/conda/deactivate.d/unsetenv.sh fi - + # install some extra dependencies echo -e "[INFO] Installing extra dependencies (this might take a few minutes)..." conda install -c conda-forge -y importlib_metadata &> /dev/null From bff56ae67c7c8756058d1027f6eb850d3084e3a2 Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 10:16:36 +0200 Subject: [PATCH 23/25] adds back vscode setting --- isaaclab.bat | 3 +++ isaaclab.sh | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/isaaclab.bat b/isaaclab.bat index b04ce061dc..514f023f23 100644 --- a/isaaclab.bat +++ b/isaaclab.bat @@ -300,6 +300,9 @@ if "%arg%"=="-i" ( ) rem install the rl-frameworks specified call !python_exe! -m pip install -e %ISAACLAB_PATH%\source\extensions\omni.isaac.lab_tasks[!framework_name!] + rem update the vscode settings + rem once we have a docker container, we need to disable vscode settings + call :update_vscode_settings shift ) else if "%arg%"=="-c" ( rem use default name if not provided diff --git a/isaaclab.sh b/isaaclab.sh index c3630bbf65..05c831124a 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -304,6 +304,15 @@ while [[ $# -gt 0 ]]; do fi # install the rl-frameworks specified ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/extensions/omni.isaac.lab_tasks["${framework_name}"] + + # check if we are inside a docker container (in that case don't setup VSCode) + if [ -f "/.dockerenv" ]; then + echo "[INFO] Running inside a docker container. Skipping VSCode settings setup." + else + # update the vscode settings + update_vscode_settings + fi + # unset local variables unset extract_python_exe unset install_isaaclab_extension From 07a6ea487cd9ced8ba792869c4e68dd1071dd02a Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 10:17:04 +0200 Subject: [PATCH 24/25] runs formatter --- isaaclab.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isaaclab.sh b/isaaclab.sh index 05c831124a..1d90a91dca 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -304,7 +304,7 @@ while [[ $# -gt 0 ]]; do fi # install the rl-frameworks specified ${python_exe} -m pip install -e ${ISAACLAB_PATH}/source/extensions/omni.isaac.lab_tasks["${framework_name}"] - + # check if we are inside a docker container (in that case don't setup VSCode) if [ -f "/.dockerenv" ]; then echo "[INFO] Running inside a docker container. Skipping VSCode settings setup." From a496c29da25f0d505ac3aa5a20ffca3e697f95df Mon Sep 17 00:00:00 2001 From: Mayank Mittal Date: Fri, 5 Jul 2024 10:24:42 +0200 Subject: [PATCH 25/25] better warning --- .vscode/tools/setup_vscode.py | 7 ++++--- isaaclab.sh | 14 +++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.vscode/tools/setup_vscode.py b/.vscode/tools/setup_vscode.py index 3ddd775039..7750be6f9f 100644 --- a/.vscode/tools/setup_vscode.py +++ b/.vscode/tools/setup_vscode.py @@ -85,10 +85,11 @@ def overwrite_python_analysis_extra_paths(isaaclab_settings: str) -> str: else: path_names = [] print( - f"[WARN] Could not find Isaac Sim VSCode settings file: {isaacsim_vscode_filename}." - "\n\tThis will result in missing python.analysis.extraPaths in Isaac Lab VSCode settings from Isaac Sim." - " It limits the functionality of Python language server in VSCode." + f"[WARN] Could not find Isaac Sim VSCode settings: {isaacsim_vscode_filename}." + "\n\tThis will result in missing 'python.analysis.extraPaths' in the VSCode" + "\n\tsettings, which limits the functionality of the Python language server." "\n\tHowever, it does not affect the functionality of the Isaac Lab project." + "\n\tWe are working on a fix for this issue with the Isaac Sim team." ) # add the path names that are in the Isaac Lab extensions directory diff --git a/isaaclab.sh b/isaaclab.sh index 1d90a91dca..f3f27c90ee 100755 --- a/isaaclab.sh +++ b/isaaclab.sh @@ -37,11 +37,9 @@ extract_isaacsim_path() { fi elif command -v python &> /dev/null; then # note: we need to deal with this case because of docker containers - # Use the python executable to get the path - local python_exe=$(which python) # Retrieve the path importing isaac sim and getting the environment path - if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then - local isaac_path=$(${python_exe} -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") + if [ $(python -m pip list | grep -c 'isaacsim-rl') ]; then + local isaac_path=$(python -c "import isaacsim; import os; print(os.environ['ISAAC_PATH'])") else # If package not installed, use an empty path for failure local isaac_path='' @@ -73,18 +71,15 @@ extract_python_exe() { local python_exe=${CONDA_PREFIX}/bin/python elif command -v python &> /dev/null; then # note: we need to deal with this case because of docker containers - # use the python executable to get the path - if [ $(${python_exe} -m pip list | grep -c 'isaacsim-rl') ]; then + if [ $(python -m pip list | grep -c 'isaacsim-rl') ]; then local python_exe=$(which python) else # leave a blank path for failure local python_exe='' fi else - # obtain the isaac sim path - local isaac_path=$(extract_isaacsim_path) # use python from kit - local python_exe=${isaac_path}/python.sh + local python_exe=${ISAACLAB_PATH}/_isaac_sim/python.sh fi # check if there is a python path available if [ ! -f "${python_exe}" ]; then @@ -308,6 +303,7 @@ while [[ $# -gt 0 ]]; do # check if we are inside a docker container (in that case don't setup VSCode) if [ -f "/.dockerenv" ]; then echo "[INFO] Running inside a docker container. Skipping VSCode settings setup." + echo "[INFO] To setup VSCode settings, run 'isaaclab -v'." else # update the vscode settings update_vscode_settings