From d8186d9d13412da1c618c79bc3fec107b119fa7b Mon Sep 17 00:00:00 2001 From: Jiao77 Date: Sat, 20 Sep 2025 00:22:37 +0800 Subject: [PATCH] finish this part --- README.md | 113 ++++++++++++++++++++++++++++++++++++--------------- README_zh.md | 113 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 160 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 971e6f7..b59e444 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - +

@@ -35,7 +35,7 @@ ## 🖥️ Supported Systems -- **Python**: 3.9+ +- **Python**: 3.12+ - **OS**: macOS 13+/Apple Silicon, Linux (Ubuntu 20.04/22.04). Windows via **WSL2** recommended - **Frameworks**: PyTorch, PyTorch Geometric (with CUDA optional) - **EDA I/O**: GDSII/OASIS (via `klayout` Python API) @@ -98,37 +98,75 @@ Geo-Layout-Transformer/ ### 3.1. Prerequisites 🧰 -* Python 3.9+ -* A Conda environment is highly recommended. +* Python 3.12+ +* Dependency management: using uv is recommended for fast, reproducible installs (uv.lock provided). Conda/Python is supported as an alternative. * Access to EDA tools for generating labeled data (e.g., a DRC engine for hotspot labels). ### 3.2. Installation 🚧 -1. **Clone the repository:** - ```bash - git clone https://github.com/your-username/Geo-Layout-Transformer.git - cd Geo-Layout-Transformer - ``` +#### A) Using uv (recommended) -2. **Create and activate the Conda environment:** - ```bash - conda create -n geo_trans python=3.9 - conda activate geo_trans - ``` +1) Install uv (one-time): -3. **Install dependencies:** - This project requires PyTorch and PyTorch Geometric (PyG). Please follow the official installation instructions for your specific CUDA version. +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh +``` - * **PyTorch:** [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/) - * **PyG:** [https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html) +2) Clone the repository: - After installing PyTorch and PyG, install the remaining dependencies: - ```bash - pip install -r requirements.txt - ``` - *(Note: You may need to install `klayout` separately via its own package manager or build from source to enable its Python API).* +```bash +git clone https://github.com/your-username/Geo-Layout-Transformer.git +cd Geo-Layout-Transformer +``` + +3) Ensure Python 3.12 is available (uv can manage it): + +```bash +uv python install 3.12 +``` + +4) Create the environment and install dependencies from uv.lock/pyproject: + +```bash +uv sync +``` + +Notes: +- For CUDA builds of PyTorch/PyG, follow the official installers first, then install the rest via uv: + - PyTorch: https://pytorch.org/get-started/locally/ + - PyG: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html + After installing the correct Torch/PyG wheels, you may run `uv sync --frozen` to install the remaining packages. +- You may need to install `klayout` separately (package manager or from source) to enable its Python API. + +#### B) Using Python/Conda (alternative) + +1) Clone the repository: + +```bash +git clone https://github.com/your-username/Geo-Layout-Transformer.git +cd Geo-Layout-Transformer +``` + +2) Create and activate an environment (Conda example): + +```bash +conda create -n geo_trans python=3.12 +conda activate geo_trans +``` + +3) Install PyTorch and PyTorch Geometric per your CUDA setup: + +- PyTorch: https://pytorch.org/get-started/locally/ +- PyG: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html + +4) Install the remaining dependencies: + +```bash +pip install -r requirements.txt +``` > Tip: GPU is optional. For CPU-only environments, install the CPU variants of PyTorch/PyG. +> Note: You may need to install `klayout` separately to enable its Python API. ## 4. Project Usage 🛠️ @@ -141,9 +179,14 @@ The first step is to convert your GDSII/OASIS files into a graph dataset that th 1. Place your layout files in the `data/gds/` directory. 2. Configure the preprocessing parameters in `configs/default.yaml`. You will need to define patch size, stride, layer mappings, and how to construct graph edges. 3. Run the preprocessing script: - ```bash - python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ - ``` + - Using uv (recommended): + ```bash + uv run python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ + ``` + - Using Python/Conda: + ```bash + python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ + ``` This script will parse the GDS file, divide it into patches, construct a graph for each patch, and save the processed data as `.pt` files for efficient loading. #### Polygon handling and per-patch graphs 🧩 @@ -171,6 +214,10 @@ Once the dataset is ready, you can train the Geo-Layout Transformer. To build a powerful foundation model, we first pre-train it on unlabeled data using a "Masked Layout Modeling" task. ```bash +# Using uv (recommended) +uv run python main.py --config-file configs/default.yaml --mode pretrain --data-dir data/processed/my_design/ + +# Using Python/Conda python main.py --config-file configs/default.yaml --mode pretrain --data-dir data/processed/my_design/ ``` This will train the model to understand the fundamental "grammar" of physical layouts without requiring any expensive labels. @@ -182,9 +229,13 @@ After pre-training, you can fine-tune the model on a smaller, labeled dataset fo 1. Ensure your processed data includes labels. 2. Use a task-specific config file (e.g., `hotspot_detection.yaml`) that defines the model head and loss function. 3. Run the main script in `train` mode: - ```bash - python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth - ``` + ```bash + # Using uv (recommended) + uv run python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth + + # Using Python/Conda + python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth + ``` ## 5. Roadmap & Contribution 🗺️ @@ -207,7 +258,3 @@ We stand on the shoulders of open-source communities. This project draws inspira - Research works such as LayoutGMN (graph matching for structural similarity) that informed our polygon/graph handling design If your work is used and not listed here, please open an issue or PR so we can properly credit you. - ---- - -Made with ❤️ for EDA research and open-source collaboration. diff --git a/README_zh.md b/README_zh.md index a961788..275a23e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -10,7 +10,7 @@ - +

@@ -35,7 +35,7 @@ ## 🖥️ 支持系统 💻 -- **Python**:3.9+ +- **Python**:3.12+ - **操作系统**:macOS 13+/Apple Silicon、Linux(Ubuntu 20.04/22.04)。Windows 建议使用 **WSL2** - **深度学习框架**:PyTorch、PyTorch Geometric(CUDA 可选) - **EDA I/O**:GDSII/OASIS(通过 `klayout` Python API) @@ -98,37 +98,75 @@ Geo-Layout-Transformer/ ### 3.1. 环境要求 🧰 -* Python 3.9+ -* 强烈建议使用 Conda 进行环境管理。 +* Python 3.12+ +* 依赖管理:推荐使用 uv(已提供 uv.lock)来进行快速、可复现的安装;也支持使用 Conda/Python 作为替代方案。 * 能够访问 EDA 工具以生成带标签的数据(例如,使用 DRC 工具生成热点标签)。 ### 3.2. 安装步骤 🚧 -1. **克隆代码仓库:** - ```bash - git clone https://github.com/your-username/Geo-Layout-Transformer.git - cd Geo-Layout-Transformer - ``` +#### A) 使用 uv(推荐) -2. **创建并激活 Conda 环境:** - ```bash - conda create -n geo_trans python=3.9 - conda activate geo_trans - ``` +1)安装 uv(一次性): -3. **安装依赖:** - 本项目需要 PyTorch 和 PyTorch Geometric (PyG)。请根据您的 CUDA 版本遵循官方指南进行安装。 +```bash +curl -LsSf https://astral.sh/uv/install.sh | sh +``` - * **PyTorch:** [https://pytorch.org/get-started/locally/](https://pytorch.org/get-started/locally/) - * **PyG:** [https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html](https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html) +2)克隆代码仓库: - 安装完 PyTorch 和 PyG 后,安装其余的依赖项: - ```bash - pip install -r requirements.txt - ``` - *(注意:您可能需要通过 `klayout` 自身的包管理器或从源码编译来单独安装它,以启用其 Python API)。* +```bash +git clone https://github.com/your-username/Geo-Layout-Transformer.git +cd Geo-Layout-Transformer +``` + +3)确保系统可用 Python 3.12(uv 可管理): + +```bash +uv python install 3.12 +``` + +4)基于 uv.lock/pyproject 创建环境并安装依赖: + +```bash +uv sync +``` + +说明: +- 如需安装带 CUDA 的 PyTorch/PyG,请先根据官方说明安装对应版本,然后再用 uv 安装其余依赖: + - PyTorch: https://pytorch.org/get-started/locally/ + - PyG: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html + 正确安装 Torch/PyG 轮子后,可执行 `uv sync --frozen` 安装剩余依赖。 +- 若需要 `klayout` 的 Python API,可能需要通过其包管理器或源码单独安装。 + +#### B) 使用 Python/Conda(备选) + +1)克隆代码仓库: + +```bash +git clone https://github.com/your-username/Geo-Layout-Transformer.git +cd Geo-Layout-Transformer +``` + +2)创建并激活环境(以 Conda 为例): + +```bash +conda create -n geo_trans python=3.12 +conda activate geo_trans +``` + +3)根据 CUDA 环境安装 PyTorch 和 PyTorch Geometric: + +- PyTorch: https://pytorch.org/get-started/locally/ +- PyG: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html + +4)安装其余依赖: + +```bash +pip install -r requirements.txt +``` > 提示:GPU 不是必须的。仅 CPU 环境可安装 PyTorch/PyG 的 CPU 版本。 +> 说明:如需 `klayout` 的 Python API,可能需要单独安装。 ## 4. 项目使用 🛠️ @@ -141,9 +179,14 @@ Geo-Layout-Transformer/ 1. 将您的版图文件放入 `data/gds/` 目录。 2. 在 `configs/default.yaml` 中配置预处理参数。您需要定义区块大小、步长、层映射以及图边的构建方式。 3. 运行预处理脚本: - ```bash - python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ - ``` + - 使用 uv(推荐): + ```bash + uv run python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ + ``` + - 使用 Python/Conda: + ```bash + python scripts/preprocess_gds.py --config-file configs/default.yaml --gds-file data/gds/my_design.gds --output-dir data/processed/my_design/ + ``` 该脚本将解析 GDS 文件,将其划分为多个区块,为每个区块构建一个图,并将处理后的数据保存为 `.pt` 文件以便高效加载。 #### 多边形处理与按区块建图 🧩 @@ -171,6 +214,10 @@ Geo-Layout-Transformer/ 为了构建一个强大的基础模型,我们首先在无标签数据上使用“掩码版图建模”任务对其进行预训练。 ```bash +# 使用 uv(推荐) +uv run python main.py --config-file configs/default.yaml --mode pretrain --data-dir data/processed/my_design/ + +# 使用 Python/Conda python main.py --config-file configs/default.yaml --mode pretrain --data-dir data/processed/my_design/ ``` 这将训练模型理解物理版图的基本“语法”,而无需任何昂贵的标签。 @@ -182,9 +229,13 @@ python main.py --config-file configs/default.yaml --mode pretrain --data-dir dat 1. 确保您处理好的数据包含标签。 2. 使用一个特定于任务的配置文件(例如 `hotspot_detection.yaml`),其中定义了模型的任务头和损失函数。 3. 在 `train` 模式下运行主脚本: - ```bash - python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth - ``` + ```bash + # 使用 uv(推荐) + uv run python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth + + # 使用 Python/Conda + python main.py --config-file configs/hotspot_detection.yaml --mode train --data-dir data/processed/labeled_hotspots/ --checkpoint-path /path/to/pretrained_model.pth + ``` ## 5. 发展路线与贡献 🗺️ @@ -207,7 +258,3 @@ python main.py --config-file configs/default.yaml --mode pretrain --data-dir dat - 研究工作 LayoutGMN(面向结构相似性的图匹配),启发了我们对多边形/图构建的设计 若您的工作被本项目使用但尚未列出,欢迎提交 Issue 或 PR 以便完善致谢。 - ---- - -Made with ❤️ 面向 EDA 研究与开源协作。