isaac-sim / IsaacLab

Unified framework for robot learning built on NVIDIA Isaac Sim
https://isaac-sim.github.io/IsaacLab
Other
1.91k stars 735 forks source link

[Proposal] Add windows support #111

Closed sambaPython24 closed 2 months ago

sambaPython24 commented 1 year ago

Proposal

I propose to add a windows script .bat that is doing the same as orbit.sh. Please let me know if there are additional problems, that I do not see here.

Motivation

Many people are using Windows instead of Linux.

Checklist

sambaPython24 commented 1 year ago

Proposal (as a starting point)

@echo off

:: This is a bat file that translates the orbit.sh file.

:: Configurations
setlocal enabledelayedexpansion
set "ORBIT_PATH=%~dp0"

:: Helper functions
:extract_python_exe
set "build_path=%ORBIT_PATH%\_isaac_sim"
if not "%ISAACSIM_PATH%" == "" (
    set "build_path=%ISAACSIM_PATH%"
)

:: Checking if Conda environment variable is set
if not "%CONDA_PREFIX%" == "" (
    set "python_exe=%CONDA_PREFIX%\Scripts\python.exe"
) else (
    set "python_exe=%build_path%\python.bat"
)

:: Checking if Python executable exists
if not exist "%python_exe%" (
    echo [ERROR] No python executable found at path: %build_path%
    exit /b 1
)

echo %python_exe%
exit /b

:extract_isaacsim_exe
set "build_path=%ORBIT_PATH%\_isaac_sim"
if not "%ISAACSIM_PATH%" == "" (
    set "build_path=%ISAACSIM_PATH%"
)

:: Checking if IsaacSim executable exists
set "isaacsim_exe=%build_path%\isaac-sim.bat"

if not exist "%isaacsim_exe%" (
    echo [ERROR] No isaac-sim executable found at path: %build_path%
    exit /b 1
)

echo %isaacsim_exe%
exit /b

:install_orbit_extension
call :extract_python_exe
if exist "%~1\setup.py" (
    echo Installing module: %~1
    "%python_exe%" -m pip install --editable "%~1"
)
exit /b

:setup_conda_env
set "env_name=%~1"

:: Checking if Conda is installed
where conda >nul 2>nul
if %errorlevel% neq 0 (
    echo [ERROR] Conda could not be found. Please install conda and try again.
    exit /b 1
)

set "build_path=%ORBIT_PATH%\_isaac_sim"

:: Checking if IsaacSim directory is manually specified
if not "%ISAACSIM_PATH%" == "" (
    set "build_path=%ISAACSIM_PATH%"
)

:: Checking if the environment exists
conda env list | findstr /c:"%env_name%" >nul
if %errorlevel% equ 0 (
    echo [INFO] Conda environment named '%env_name%' already exists.
) else (
    echo [INFO] Creating conda environment named '%env_name%'...
    conda env create --name %env_name% -f %build_path%\environment.yml
)

:: Saving current Python path and LD_LIBRARY_PATH
set "cache_pythonpath=!PYTHONPATH!"
set "cache_ld_library_path=!LD_LIBRARY_PATH!"

:: Deleting previous activation and deactivation scripts
del /q "%CONDA_PREFIX%\etc\conda\activate.d\setenv.bat" 2>nul
del /q "%CONDA_PREFIX%\etc\conda\deactivate.d\unsetenv.bat" 2>nul

:: Activating the environment
call "%CONDA_EXE%\Scripts\conda.bat" activate %env_name%

:: Creating directories for activation and deactivation scripts
mkdir "%CONDA_PREFIX%\etc\conda\activate.d"
mkdir "%CONDA_PREFIX%\etc\conda\deactivate.d"

set "isaacsim_setup_conda_env_script=%ORBIT_PATH%\_isaac_sim\setup_conda_env.bat"

:: Creating activation script
(
  echo @echo off
  echo rem for isaac-sim
  echo call "%isaacsim_setup_conda_env_script%"
  echo.
  echo rem for orbit
  echo set "PATH=%ORBIT_PATH%;%%PATH%%"
  echo.
  echo rem show icon if not runninng headless
  echo set "RESOURCE_NAME=IsaacSim"
) > "%CONDA_PREFIX%\etc\conda\activate.d\setenv.bat"

:: Activating the environment again
call "%CONDA_EXE%\Scripts\conda.bat" activate %env_name%

:: Creating deactivation script
(
  echo @echo off
  echo rem for orbit
  echo set "PATH=!cache_pythonpath!"
  echo set "RESOURCE_NAME="
) > "%CONDA_PREFIX%\etc\conda\deactivate.d\unsetenv.bat"

:: Installing extra dependencies
echo [INFO] Installing extra dependencies (this might take a few minutes)...
call conda install -c conda-forge -y importlib_metadata >nul

:: Deactivating the environment
call conda deactivate

:: Adding alias and environment information
echo [INFO] Added 'orbit' alias to conda environment for 'orbit.bat' script.
echo [INFO] Created conda environment named '%env_name%'.
echo.
echo       1. To activate the environment, run:                conda activate %env_name%
echo       2. To install orbit extensions, run:                orbit -i
echo       3. To install learning-related dependencies, run:   orbit -e
echo       4. To perform formatting, run:                      orbit -f
echo       5. To deactivate the environment, run:              conda deactivate
echo.

exit /b

:update_vscode_settings
echo [INFO] Setting up vscode settings...

call :extract_python_exe
"%python_exe%" "%ORBIT_PATH%\.vscode\tools\setup_vscode.py"

exit /b

:print_help
echo.
echo usage: %~nx0 [-h] [-i] [-e] [-f] [-p] [-s] [-v] [-d] [-c] -- Utility to manage extensions in Orbit.
echo.
echo optional arguments:
echo    -h, --help           Display the help content.
echo    -i, --install        Install the extensions inside Isaac Orbit.
echo    -e, --extra          Install extra dependencies such as the learning frameworks.
echo    -f, --format         Run pre-commit to format the code and check lints.
echo    -p, --python         Run the python executable (python.bat) provided by Isaac Sim.
echo    -s, --sim            Run the simulator executable (isaac-sim.bat) provided by Isaac Sim.
echo    -v, --vscode         Generate the VSCode settings file from the template.
echo    -d, --docs           Build the documentation from source using sphinx.
echo    -c, --conda [NAME]   Create the conda environment for Orbit. Default name is 'orbit'.
echo.

:: Main
if "%~#"=="" (
    echo [Error] No arguments provided.
    call :print_help
    exit /b 1
)

:loop
if "%~1"=="" goto :end

if "%~1"=="-i" (
    echo [INFO] Installing extensions inside orbit repository...

    for /d %%D in ("%ORBIT_PATH%\source\extensions\*") do (
        call :install_orbit_extension "%%~fD"
    )

    call :update_vscode_settings
    shift
    goto :loop
)

if "%~1"=="-e" (
    echo [INFO] Installing extra requirements such as learning frameworks...

    call :extract_python_exe
    "%python_exe%" -m pip install -e "%ORBIT_PATH%\source\extensions\omni.isaac.orbit_envs[all]"

    shift
    goto :loop
)

if "%~1"=="-c" (
    if "%~2"=="" (
        echo [INFO] Using default conda environment name: orbit
        set "conda_env_name=orbit"
    ) else (
        echo [INFO] Using conda environment name: %~2
        set "conda_env_name=%~2"
        shift
    )

    call :setup_conda_env "%conda_env_name%"
    shift
    goto :loop
)

if "%~1"=="-f" (
    if defined CONDA_DEFAULT_ENV (
        set "cache_pythonpath=!PYTHONPATH!"
        set "PYTHONPATH="
    )

    if not exist "%CONDA_EXE%\Scripts\conda.exe" (
        echo [INFO] Installing conda...
        start /wait "" "%ORBIT_PATH%\install_conda.bat"
    )

    if not exist "%CONDA_EXE%\Scripts\pre-commit.exe" (
        echo [INFO] Installing pre-commit...
        call conda install -c conda-forge -y pre-commit >nul
    )

    echo [INFO] Formatting the repository...
    cd /d "%ORBIT_PATH%"
    call pre-commit run --all-files
    cd /d "%~dp0"
    set "PYTHONPATH=!cache_pythonpath!"
    shift
    goto :end
)

if "%~1"=="-p" (
    call :extract_python_exe
    echo [INFO] Using python from: !python_exe!
    shift
    "%python_exe%" %*
    goto :end
)

if "%~1"=="-s" (
    call :extract_isaacsim_exe
    echo [INFO] Running isaac-sim from: !isaacsim_exe!
    shift
    "%isaacsim_exe%" --ext-folder "%ORBIT_PATH%\source\extensions" %*
    goto :end
)

if "%~1"=="-v" (
    call :update_vscode_settings
    shift
    goto :end
)

if "%~1"=="-d" (
    echo [INFO] Building documentation...

    call :extract_python_exe
    call "%python_exe%" -m pip install -r "%ORBIT_PATH%\docs\requirements.txt" >nul

    cd /d "%ORBIT_PATH%\docs"
    call "%python_exe%" -m sphinx -b html -d _build\doctrees . _build\html
    cd /d "%~dp0"

    echo [INFO] To open documentation on the default browser, run:
    echo.
    echo      start "" "%ORBIT_PATH%\docs\_build\html\index.html"
    echo.

    shift
    goto :end
)

if "%~1"=="-h" (
    call :print_help
    exit /b 1
)

echo [Error] Invalid argument provided: %~1
call :print_help
exit /b 1

:end
endlocal
Mayankm96 commented 1 year ago

That's really cool! Thanks a lot for sharing the .bat file. Let me try to get hold of a Windows machine and see if this works. Would be great to have this merged in!

emondssp commented 1 year ago

Add Windows installation details to documentation

Hey @Mayankm96 , I would participate in making this extension run in Windows

Could you add this to the documentation?


Configuring the environment variables

The Windwos version was tested with Windows 11 Pro.

! Note On Windows systems, you can find the path (in this case isaac_sim-2022.2.1) by either

We will call the path "{ISAAC_SIM_PATH}\isaac_sim-", with corresponding to the Isaac Sim version. {ISAAC_SIM_PATH} could be replaced for by e.g. C:\Users\myuser\Documents\Nvidia

For windows users, open the command line (cmd) and set the path variable as

:: Set Isaac Sim root directory
set "ISAACSIM_PATH={ISAAC_SIM_PATH}\isaac_sim-2022.2.1"
set "ISAACSIM_PATH=D:\NVIDIA\LIBRARY\isaac_sim-2022.2.1"
:: Set Isaac Sim python executable
set "ISAACSIM_PYTHON_EXE=%ISAACSIM_PATH%\python.bat"

This path is only kept in the memory for one terminal session.

Remark: You can also set the path variable with the GUI environment as via SetEnvironmentVariable

In order to set the path permanently (for any new terminal session), use

setx ISAACSIM_PATH "{ISAAC_SIM_PATH}\isaac_sim-2022.2.0"

and

setx ISAACSIM_PYTHON_EXE "%ISAACSIM_PATH%\python.bat"

Restart the terminal when using setx for the changes to take effect.

Running the simulator

Check that the simulator runs as expected:

"%ISAACSIM_PATH%\isaac-sim.bat"

Check that the simulator runs from a standalone python script:

:: Check that python path is set correctly
"%ISAACSIM_PYTHON_EXE%" -c "print('Isaac Sim configuration is now complete.')"
:: Check that Isaac Sim can be launched from python
"%ISAACSIM_PYTHON_EXE%" "%ISAACSIM_PATH%\standalone_examples\api\omni.isaac.core\add_cubes.py"
emondssp commented 1 year ago
:: Enter the cloned repository
cd orbit

:: Create a symbolic link
mklink /D _isaac_sim "%ISAACSIM_PATH%"

This might requires administrative privileges

Mayankm96 commented 2 months ago

Closing this issue as we have recently added Windows support to IsaacLab.