# openopc/openilt architecture

> Architecture diagram of the GitHub repository openopc/openilt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openopc/openilt
- Repository: https://github.com/openopc/openilt

## Overview

##### Project Type and Purpose
- OpenILT is an open-source research platform for inverse lithography technology (ILT).
- It decouples the ILT workflow into four orthogonal stages—simulation, initialization, optimization, evaluation—so researchers can swap in/out new methods easily.

##### High-Level File/Directory Structure
- benchmark/ : Input designs (ICCAD2013 .glp, .gds)
- config/ : Text configuration files for different simulators & ILT methods
- kernel/ : Precomputed optical kernels & scale factors for litho simulators
- opc/ : Classical OPC implementations (ICCAD13, simple OPC)
- pycommon/ : Shared utilities (GLP/GDS reader, settings, logging)
- pylitho/ : Lithography simulators (exact, simple) as PyTorch Modules
- pyilt/ : ILT solvers & support code (initializers, level-set, multilevel, SimpleILT, evaluation)
- utils/ : GDS‐specific helpers (layout conversion, polygon ops)
- tmp/ : Output directory for masks, figures, intermediate results
- requirements_*.txt, LICENSE, README.md

##### Main Components and Their Interactions
A. Input/Preprocessing
- Design files (.glp or .gds) loaded via pycommon (readGDS, glp)
- Configuration loader (pycommon/settings) parses config/*.txt
B. Initialization
- Initializer classes in pyilt/initializer.py produce:
– target image (binary)
– initial mask parameters
C. Lithography Simulation
- pylitho/LithoSim (exact.py, simple.py)
– Loads optical kernels (kernel/) and config
– Simulates aerial & printed images at nominal/max/min process corners
D. ILT Optimization
- pyilt/SimpleILT (and other pyilt solvers)
– Accepts target & params
– Feeds params (mask) into LithoSim → printed images
– Computes losses (L2, PVBand, optional EPE)
– Backpropagates gradients via PyTorch optimizers
– Updates mask parameters
– Iterates until convergence → best mask
E. Classical OPC
- opc/*.py provide alternative mask correction flows (iccad13.py, simpleopc.py)
F. Evaluation
- pyilt/evaluation.py: Basic, EPEChecker, ShotCounter
- Outputs metrics: L2, PVBand, EPE, Shots
G. Output
- Final mask images saved in tmp/
- Figures in figs/

##### Architectural Patterns & Design Principles
- Modular, plug-and-play stages (Simulation, Initialization, Optimization, Evaluation)
- Clear separation of concerns: file I/O (pycommon), simulation (pylitho), optimization (pyilt), evaluation (pyilt + thirdparty)
- Use of framework (PyTorch) to unify differentiable components
- Configuration-driven: all numeric parameters or kernel selections live in config/ and kernel/

##### Technologies, Frameworks, Libraries
- Python 3.8–3.10, PyTorch (≥1.8) for GPU-accelerated tensor ops and auto-diff
- NumPy, SciPy for numeric routines
- Custom binary kernel files for litho simulation
- Standard Python packaging and requirements files

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Inputs"
        BI["benchmark/ICCAD2013/*.glp & *.gds"]:::data
        CFG["config/*.txt"]:::data
        KER["kernel/ (M1OPC, M1OPC_def, kernels, scales)"]:::data
        UT["utils/ (gds2img, layout, polygon)"]:::data
    end

    subgraph "Core Libraries"
        PC["pycommon/ (readGDS, glp, infoGDS, settings, logging)"]:::core
        EXT["thirdparty/adaptive-boxes"]:::ext
    end

    subgraph "Modules"
        subgraph "Initialization"
            INIT["pyilt/initializer.py"]:::module
        end
        subgraph "Simulation"
            EX["pylitho/exact.py"]:::module
            SIMP["pylitho/simple.py"]:::module
        end
        subgraph "Optimization"
            SI["pyilt/simpleilt.py"]:::module
            CM["pyilt/curvmulti.py"]:::module
            LS["pyilt/levelset.py"]:::module
            ML["pyilt/multilevel.py"]:::module
        end
        subgraph "OPC (Classical)"
            ICC["opc/iccad13.py"]:::module
            SOP["opc/simpleopc.py"]:::module
        end
        subgraph "Evaluation"
            EVAL["pyilt/evaluation.py"]:::module
            SC["thirdparty/adaptive-boxes/adabox.py"]:::module
        end
    end

    subgraph "Output"
        OUTMASK["tmp/ (masks, intermediate results)"]:::data
        FIGS["figs/"]:::data
    end

    %% Data flows
    BI -->|".glp/.gds files"| PC
    PC -->|"readGDS/glp/infoGDS"| INIT
    CFG -.->|"config injection"| PC
    CFG -.->|"config injection"| EX
    CFG -.->|"config injection"| SIMP
    CFG -.->|"config injection"| INIT
    KER -.->|"kernel injection"| EX
    KER -.->|"kernel injection"| SIMP

    INIT -->|"target image & init params"| SI
    SI -->|"mask parameters"| EX
    CM -->|"mask parameters"| EX
    LS -->|"mask parameters"| EX
    ML -->|"mask parameters"| EX

    EX -->|"printed images"| SI
    EX -->|"printed images"| CM
    EX -->|"printed images"| LS
    EX -->|"printed images"| ML

    SI -->|"optimized mask"| EVAL
    CM -->|"optimized mask"| EVAL
    LS -->|"optimized mask"| EVAL
    ML -->|"optimized mask"| EVAL

    EVAL -->|"metrics (L2, PVBand, EPE)"| SC
    EVAL -->|"metrics & figures"| OUTMASK
    EVAL -->|"metrics & figures"| FIGS
    SC -->|"shot count"| OUTMASK

    %% Click events
    click BI "https://github.com/openopc/openilt/blob/main/benchmark/ICCAD2013/*.glp"
    click CFG "https://github.com/openopc/openilt/blob/main/config/simpleilt512.txt"
    click KER "https://github.com/openopc/openilt/tree/main/kernel/M1OPC/"
    click UT "https://github.com/openopc/openilt/blob/main/utils/gds2img.py"
    click PC "https://github.com/openopc/openilt/blob/main/pycommon/readGDS.py"
    click INIT "https://github.com/openopc/openilt/blob/main/pyilt/initializer.py"
    click EX "https://github.com/openopc/openilt/blob/main/pylitho/exact.py"
    click SIMP "https://github.com/openopc/openilt/blob/main/pylitho/simple.py"
    click SI "https://github.com/openopc/openilt/blob/main/pyilt/simpleilt.py"
    click CM "https://github.com/openopc/openilt/blob/main/pyilt/curvmulti.py"
    click LS "https://github.com/openopc/openilt/blob/main/pyilt/levelset.py"
    click ML "https://github.com/openopc/openilt/blob/main/pyilt/multilevel.py"
    click ICC "https://github.com/openopc/openilt/blob/main/opc/iccad13.py"
    click SOP "https://github.com/openopc/openilt/blob/main/opc/simpleopc.py"
    click EVAL "https://github.com/openopc/openilt/blob/main/pyilt/evaluation.py"
    click SC "https://github.com/openopc/openilt/blob/main/thirdparty/adaptive-boxes/adabox.py"
    click OUTMASK "https://github.com/openopc/openilt/tree/main/tmp/"
    click FIGS "https://github.com/openopc/openilt/tree/main/figs/"

    %% Styles
    classDef data fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef core fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef module fill:#99ccff,stroke:#333,stroke-width:1px
    classDef ext fill:#ffdd99,stroke:#333,stroke-width:1px
```
