├── .gitignore ├── 10_nvidia.json ├── nvidia_icd.json ├── exec.sh ├── setup_template.sh ├── requirement_template.txt ├── run.sh ├── Dockerfile ├── README_CN.md ├── README.md └── LICENCE /.gitignore: -------------------------------------------------------------------------------- 1 | setup.sh 2 | requirement.txt -------------------------------------------------------------------------------- /10_nvidia.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "ICD" : { 4 | "library_path" : "libEGL_nvidia.so.0" 5 | } 6 | } 7 | 8 | -------------------------------------------------------------------------------- /nvidia_icd.json: -------------------------------------------------------------------------------- 1 | { 2 | "file_format_version" : "1.0.0", 3 | "ICD": { 4 | "library_path": "libGLX_nvidia.so.0", 5 | "api_version" : "1.1.95" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /exec.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -u 4 | 5 | PROJECTNAME=$(basename "$(cd "$(dirname "\$0")"; cd ..; pwd -P)" | tr '[:upper:]' '[:lower:]') 6 | 7 | docker exec -it ${PROJECTNAME}_container /bin/bash -------------------------------------------------------------------------------- /setup_template.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -u 4 | 5 | ############################ 6 | # ADD YOUR OWN REQUIREMENT # 7 | ############################ 8 | pip install -e ./isaacgym/python 9 | pip install -e ./rsl_rl 10 | pip install -e ./legged_gym 11 | 12 | /bin/bash -------------------------------------------------------------------------------- /requirement_template.txt: -------------------------------------------------------------------------------- 1 | torch>=1.4.0 2 | torchvision>=0.5.0 3 | numpy==1.23.5 4 | scipy>=1.5.0 5 | pyyaml>=5.3.1 6 | pillow 7 | imageio 8 | ninja 9 | 10 | matplotlib 11 | tensorboard 12 | 13 | pybullet 14 | pygame 15 | lxml 16 | transformations 17 | 18 | opencv-python<4.3 19 | opencv-contrib-python<4.3 20 | opencv-python-headless<4.3 21 | 22 | nvitop 23 | 24 | pyquaternion 25 | 26 | ################################## 27 | # ADD YOUR OWN REQUIREMENT AFTER # 28 | ################################## 29 | 30 | # your-requirement-xxx 31 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | set -u 4 | 5 | SCRIPTROOT="$( cd "$(dirname "\$0")" ; pwd -P )" 6 | PROJECTNAME=$(basename "$(cd "$(dirname "\$0")"; cd ..; pwd -P)" | tr '[:upper:]' '[:lower:]') 7 | HOMENAME=$(basename $HOME) 8 | 9 | display_flag="" 10 | gpus="" 11 | 12 | usage() { 13 | echo "Usage: bash $0 -g -d " 1>&2 14 | exit 1 15 | } 16 | 17 | while getopts "g:d:" opt; do 18 | case $opt in 19 | g) 20 | gpus=$OPTARG 21 | ;; 22 | d) 23 | display_flag=$OPTARG 24 | ;; 25 | ?) 26 | usage 27 | exit 1 28 | ;; 29 | esac 30 | done 31 | 32 | shift $(( $OPTIND - 1 )) 33 | 34 | errors="" 35 | 36 | if [ -z "$gpus" ]; then 37 | errors+="GPUs parameter is required.\n" 38 | elif ! [[ "$gpus" =~ ^[1-9]+$ ]] && [ "$gpus" != "all" ]; then 39 | errors+="Invalid GPUs parameter. Must be a numeric value or 'all'.\n" 40 | fi 41 | 42 | if [ -z "${display_flag}" ]; then 43 | errors+="Display parameter is required.\n" 44 | fi 45 | 46 | if [ -n "$errors" ]; then 47 | echo -e "$errors" >&2 48 | usage 49 | else 50 | echo -e "Use Docker Image: $PROJECTNAME" 51 | echo -e "Start Docker Container: ${PROJECTNAME}_container" 52 | echo -e "Use GPU: $gpus" 53 | echo -e "Use Display: $display_flag\n" 54 | fi 55 | 56 | if [ "$display_flag" = true ]; then 57 | export DISPLAY=$DISPLAY 58 | echo "Setting display to $DISPLAY" 59 | xhost + 60 | docker run -it --rm \ 61 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 62 | -v /home/${HOMENAME}/.Xauthority:/root/.Xauthority \ 63 | -e DISPLAY=$DISPLAY \ 64 | -v ${SCRIPTROOT}/..:/home/root/rl_ws \ 65 | --network=host \ 66 | --gpus="${gpus}" \ 67 | --name="${PROJECTNAME}_container" \ 68 | ${PROJECTNAME} /home/root/rl_ws/rl_docker/setup.sh 69 | else 70 | echo "Running Docker without display" 71 | docker run -it --rm \ 72 | -v ${SCRIPTROOT}/..:/home/root/rl_ws \ 73 | --network=host \ 74 | --gpus="${gpus}" \ 75 | --name="${PROJECTNAME}_container" \ 76 | ${PROJECTNAME} /home/root/rl_ws/rl_docker/setup.sh 77 | fi 78 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvcr.io/nvidia/pytorch:21.09-py3 2 | 3 | # set WORKDIR 4 | WORKDIR /home/root/rl_ws 5 | 6 | # setup environment 7 | ENV LANG C.UTF-8 8 | ENV LC_ALL C.UTF-8 9 | ENV DEBIAN_FRONTEND noninteractive 10 | 11 | # replace mirror 12 | RUN apt-get install -q -y --no-install-recommends wget \ 13 | && wget http://archive.ubuntu.com/ubuntu/pool/main/c/ca-certificates/ca-certificates_20240203~20.04.1_all.deb \ 14 | && dpkg -i ./ca-certificates_20240203~20.04.1_all.deb 15 | RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \ 16 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse\n" > /etc/apt/sources.list && \ 17 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse\n" >> /etc/apt/sources.list && \ 18 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse\n" >> /etc/apt/sources.list && \ 19 | echo "deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse\n" >> /etc/apt/sources.list 20 | 21 | # dependencies for gym 22 | RUN apt-get update \ 23 | && apt-get install -y --no-install-recommends \ 24 | libxcursor-dev \ 25 | libxrandr-dev \ 26 | libxinerama-dev \ 27 | libxi-dev \ 28 | mesa-common-dev \ 29 | zip \ 30 | unzip \ 31 | make \ 32 | gcc-8 \ 33 | g++-8 \ 34 | vulkan-utils \ 35 | mesa-vulkan-drivers \ 36 | pigz \ 37 | git \ 38 | libegl1 \ 39 | git-lfs \ 40 | libsm6 \ 41 | xauth \ 42 | x11-apps 43 | 44 | # change pip mirror 45 | RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 46 | 47 | # update pip 48 | RUN python -m pip install --upgrade pip 49 | 50 | # pip install requirements 51 | COPY requirement.txt . 52 | RUN pip install -r requirement.txt 53 | 54 | # Force gcc 8 to avoid CUDA 10 build issues on newer base OS 55 | RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 56 | RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8 57 | 58 | # WAR for eglReleaseThread shutdown crash in libEGL_mesa.so.0 (ensure it's never detected/loaded) 59 | # Can't remove package libegl-mesa0 directly (because of libegl1 which we need) 60 | RUN rm /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0 /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0.0.0 /usr/share/glvnd/egl_vendor.d/50_mesa.json 61 | 62 | COPY nvidia_icd.json /usr/share/vulkan/icd.d/nvidia_icd.json 63 | COPY 10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json 64 | 65 | ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all 66 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # rl_docker 2 | 3 | [English document](README.md) 4 | 5 | 此项目用于配置基于[isaac_gym](https://developer.nvidia.com/isaac-gym)的强化学习docker环境。 6 | 7 | 使用docker可以快速部署隔离的、虚拟的、完全相同的开发环境,不会出现“我的电脑能跑,你的电脑跑不了”的情况。 8 | 9 | [点击在Discord上讨论](https://discord.gg/MC9KguQHtt) 10 | 11 | ## 如何使用 12 | 13 | ### 拉取本仓库到你的项目根目录下 14 | 15 | ```bash 16 | git clone https://github.com/fan-ziqi/rl_docker.git 17 | cd rl_docker 18 | ``` 19 | 20 | ### 复制并修改配置文件 21 | 22 | 将`requirement_template.txt`复制一份并命名为`requirement.txt`,在此文件中添加所需要的python依赖项。(在此文件中添加的依赖项在docker构建时下载,生成容器后不会重复下载) 23 | 24 | ```bash 25 | cp -p requirement_template.txt requirement.txt 26 | ``` 27 | 28 | 将`setup_template.sh`复制一份并命名为`setup.sh`,在此文件中配置所有python包。(在此文件中添加的依赖项在docker容器每次运行时都会重新下载,仅为了解决某些依赖冲突的问题。没有特殊情况请将依赖项都写入`requirement.txt`中) 29 | 30 | ```bash 31 | cp -p setup_template.sh setup.sh 32 | ``` 33 | 34 | 对于`setup_template.sh`,其对应的工作目录文件层级如下: 35 | 36 | ``` 37 | rl_ws/ 38 | │ 39 | ├── rl_docker/ 40 | │ └── ... 41 | │ 42 | ├── isaacgym/ 43 | │ ├── python/ 44 | │ │ ├── setup.py 45 | │ │ └── ... 46 | │ │ 47 | │ └── ... 48 | │ 49 | ├── rsl_rl/ 50 | │ ├── setup.py 51 | │ └── ... 52 | │ 53 | ├── legged_gym/ 54 | │ ├── setup.py 55 | │ └── ... 56 | │ 57 | └── ... 58 | ``` 59 | 60 | ### 构建镜像 61 | 62 | ```bash 63 | bash build.sh 64 | ``` 65 | 66 | ### 运行镜像 67 | 68 | ```bash 69 | bash run.sh -g -d 70 | # example: bash run.sh -g all -d true 71 | ``` 72 | 73 | Git不会track这两个新建的文件,如有需要请自行修改`.gitignore`。 74 | 75 | 使用`Ctrl+P+Q`可退出当前终端,使用`exit`结束容器; 76 | 77 | ## 查看资源使用情况 78 | 79 | 镜像中内置了`nvitop`,新建一个窗口,运行`bash exec.sh`进入容器,运行`nvitop`查看系统资源使用情况。使用`exit`或者`Ctrl+P+Q`均可退出当前终端而不结束容器; 80 | 81 | ## 问题解决 82 | 83 | ### 显卡问题 84 | 85 | * 如果使用的是RTX4090显卡,请修改`docker/Dockerfile`文件中的第一句为: 86 | 87 | ```dockerfile 88 | nvcr.io/nvidia/pytorch:22.12-py3 89 | ``` 90 | 91 | * 如果使用的是RTX3070显卡,则无需修改 92 | 93 | 其他显卡的pytorch支持版本请在下方链接中查找 94 | 95 | [Frameworks Support Matrix](https://docs.nvidia.com/deeplearning/frameworks/support-matrix/index.html) 96 | 97 | ### 权限问题 98 | 99 | 执行`run.sh`脚本的时候若出现如下报错: 100 | 101 | ``` 102 | Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy' 103 | nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown 104 | ``` 105 | 106 | 出现此问题大多是因为没有使用root权限运行容器,以下几种方案均可: 107 | 108 | * 在bash前加root 109 | * 切换至root用户 110 | * 将当前用户加入root组 111 | 112 | 若无法找到构建好的isaacgym镜像,则需重新以root权限构建镜像。 113 | 114 | ### runtime问题 115 | 116 | 执行`run.sh`脚本的时候若出现如下报错: 117 | 118 | ``` 119 | docker: Error response from daemon: could not select device driver "" with capabilities:[[gpu]]. 120 | ``` 121 | 122 | 则需要安装`nvidia-container-runtime`和`nvidia-container-toolkit`两个包,并修改Docker daemon 的启动参数,将默认的 Runtime修改为 nvidia-container-runtime: 123 | 124 | ```bash 125 | curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg 126 | curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ 127 | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ 128 | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list 129 | sudo apt update 130 | sudo apt install nvidia-container-toolkit nvidia-container-runtime 131 | ``` 132 | 133 | ```bash 134 | sudo vi /etc/docker/daemon.json 135 | ``` 136 | 137 | 修改内容为 138 | 139 | ```json 140 | { 141 | "default-runtime": "nvidia", 142 | "runtimes": { 143 | "nvidia": { 144 | "path": "/usr/bin/nvidia-container-runtime", 145 | "runtimeArgs": [] 146 | } 147 | } 148 | } 149 | ``` 150 | 151 | 重启docker服务: 152 | 153 | ```bash 154 | systemctl restart docker 155 | ``` 156 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rl_docker 2 | 3 | [中文文档](README_CN.md) 4 | 5 | This project is used to configure a Reinforcement Learning Docker environment based on [isaac_gym](https://developer.nvidia.com/isaac-gym). 6 | 7 | Using Docker allows for the rapid deployment of isolated, virtual, and identical development environments, eliminating the situation of "it runs on my computer, but not on yours." 8 | 9 | [Click to discuss on Discord](https://discord.gg/vmVjkhVugU) 10 | 11 | ## How to Use 12 | 13 | ### Clone this repository into the root directory of your project. 14 | 15 | ```bash 16 | git clone https://github.com/fan-ziqi/rl_docker.git 17 | cd rl_docker 18 | ``` 19 | 20 | ### Copy and modify the configuration file. 21 | 22 | Copy `requirement_template.txt` and rename it to `requirement.txt`. In this file, add the necessary Python dependencies. (Dependencies added in this file will be downloaded during Docker build and will not be re-downloaded after the container is generated.) 23 | 24 | ```bash 25 | cp -p requirement_template.txt requirement.txt 26 | ``` 27 | 28 | Copy `setup_template.sh` and rename it to `setup.sh`. In this file, configure all Python packages. (Dependencies added in this file will be re-downloaded every time the Docker container is run, only to address specific dependency conflicts. Unless there are special circumstances, include all dependencies in `requirement.txt`.) 29 | 30 | ```bash 31 | cp -p setup_template.sh setup.sh 32 | ``` 33 | 34 | For `setup_template.sh`, the corresponding working directory file hierarchy is as follows: 35 | 36 | ``` 37 | rl_ws/ 38 | │ 39 | ├── rl_docker/ 40 | │ └── ... 41 | │ 42 | ├── isaacgym/ 43 | │ ├── python/ 44 | │ │ ├── setup.py 45 | │ │ └── ... 46 | │ │ 47 | │ └── ... 48 | │ 49 | ├── rsl_rl/ 50 | │ ├── setup.py 51 | │ └── ... 52 | │ 53 | ├── legged_gym/ 54 | │ ├── setup.py 55 | │ └── ... 56 | │ 57 | └── ... 58 | ``` 59 | 60 | ### Build the Image 61 | 62 | ```bash 63 | bash build.sh 64 | ``` 65 | 66 | ### Run the Image 67 | 68 | ```bash 69 | bash run.sh -g -d 70 | # example: bash run.sh -g all -d true 71 | ``` 72 | 73 | These two newly created files will not be tracked by Git. If needed, please modify`.gitignore`. 74 | 75 | Use `Ctrl+P+Q` to exit the current terminal and use `exit` to stop the container. 76 | 77 | ## Check Resource Usage 78 | 79 | The image comes with `nvitop` installed. Open a new window, run `bash exec.sh` to enter the container, and use `nvitop` to view the system resource usage. Use `exit` or `Ctrl+P+Q` to exit the current terminal without stopping the container. 80 | 81 | ## Troubleshooting 82 | 83 | ### GPU Issues 84 | 85 | * If you are using an RTX 4090 GPU, modify the first line of the `docker/Dockerfile` file to: 86 | 87 | ```dockerfile 88 | nvcr.io/nvidia/pytorch:22.12-py3 89 | ``` 90 | 91 | * If you are using an RTX 3070 GPU, no modifications are needed. 92 | 93 | Please find the supported versions of pytorch for other GPUs in the link below 94 | 95 | [Frameworks Support Matrix](https://docs.nvidia.com/deeplearning/frameworks/support-matrix/index.html) 96 | 97 | ### Permission Issues 98 | 99 | If you encounter the following error when running the `run.sh` script: 100 | 101 | ``` 102 | Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running hook #0: error running hook: exit status 1, stdout: , stderr: Auto-detected mode as 'legacy' 103 | nvidia-container-cli: initialization error: load library failed: libnvidia-ml.so.1: cannot open shared object file: no such file or directory: unknown 104 | ``` 105 | 106 | This error is mostly due to not running the container with root privileges. Here are a few solutions: 107 | 108 | * Prefix the bash command with `root`. 109 | * Switch to the root user. 110 | * Add the current user to the root group. 111 | 112 | If you cannot find the pre-built isaacgym image, you need to rebuild the image with root permissions. 113 | 114 | ### Runtime Issue 115 | 116 | If you encounter the following error when running the `run.sh` script: 117 | 118 | ``` 119 | docker: Error response from daemon: could not select device driver "" with capabilities:[[gpu]]. 120 | ``` 121 | 122 | You need to install the `nvidia-container-runtime` and `nvidia-container-toolkit` packages, and modify the Docker daemon startup parameter to change the default runtime to `nvidia-container-runtime`: 123 | 124 | ```bash 125 | curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg 126 | curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ 127 | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ 128 | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list 129 | sudo apt update 130 | sudo apt install nvidia-container-toolkit nvidia-container-runtime 131 | ``` 132 | 133 | ```bash 134 | sudo vi /etc/docker/daemon.json 135 | ``` 136 | 137 | Update the content to: 138 | 139 | ```json 140 | { 141 | "default-runtime": "nvidia", 142 | "runtimes": { 143 | "nvidia": { 144 | "path": "/usr/bin/nvidia-container-runtime", 145 | "runtimeArgs": [] 146 | } 147 | } 148 | } 149 | ``` 150 | 151 | Reload docker service: 152 | 153 | ```bash 154 | systemctl restart docker 155 | ``` 156 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2023 Fan Ziqi 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------