# taigaoma1997/optogpt architecture

> Architecture diagram of the GitHub repository taigaoma1997/optogpt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/taigaoma1997/optogpt
- Repository: https://github.com/taigaoma1997/optogpt

## Overview

OptoGPT is a research codebase for inverse design of optical multilayer films, a forward surrogate simulator, and self-improving augmentation for out-of-distribution designs. The primary supported training workflow prepares structure/spectrum pairs, builds a transformer, and trains it; augmentation adds candidate generation and optical simulation to evaluate designs. The graph also preserves the separately documented OL-Transformer and synthetic development-data capability. Source excerpts support the OptoGPT and simulator links; wiring among the unsampled self-improving scripts is left unspecified.

Main entry points: [`self_improving/run_self_improving.py`](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/run_self_improving.py) (Improvement runner), [`optogpt/run_optogpt.py`](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/run_optogpt.py) (Inverse training entry), [`self_improving/prepare_aug_data.py`](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/prepare_aug_data.py) (Augmentation preparation), [`optogpt/core/datasets/sim.py`](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/datasets/sim.py) (Thin-film simulator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_opto["OptoGPT models"]
  node_transformer["Transformer models<br/>[transformer.py]"]
  node_inverse_model["Inverse design model<br/>[transformer.py]"]
  node_forward_model["Forward surrogate<br/>[transformer.py]"]
end

subgraph group_sim["Optical simulation"]
  node_simulation["Thin-film simulator<br/>[sim.py]"]
  node_materials[("Optical constants")]
end

subgraph group_improve["Self-improving augmentation"]
  node_dev_generator["OOD spectrum generator"]
  node_augmentation["Augmentation preparation"]
  node_perturbation["Design perturbation<br/>[data_perturb.py]"]
  node_augmentation_data["Augmented data tools<br/>[combine_data.py]"]
  node_retraining["Model retraining<br/>[model_retrain.py]"]
  node_workflow["Improvement runner"]
end

subgraph group_train["Training pipeline"]
  node_inverse_entry["Inverse training entry<br/>[run_optogpt.py]"]
  node_forward_entry["Surrogate training entry"]
  node_preparation["Pair preparation<br/>[datasets.py]"]
  node_trainer["Training and loss<br/>[train.py]"]
end

node_researcher(("Researcher"))
node_pairs["Structure-spectrum data"]
node_designs["Candidate film designs"]

node_researcher -->|"starts training"| node_inverse_entry
node_pairs -->|"loads pairs"| node_preparation
node_inverse_entry -->|"prepares inverse data"| node_preparation
node_forward_entry -->|"prepares forward data"| node_preparation
node_inverse_entry -->|"builds model"| node_inverse_model
node_forward_entry -->|"builds model"| node_forward_model
node_inverse_model -->|"uses components"| node_transformer
node_forward_model -->|"uses components"| node_transformer
node_inverse_entry -->|"trains inverse model"| node_trainer
node_forward_entry -->|"trains surrogate"| node_trainer
node_researcher -->|"requests OOD data"| node_dev_generator
node_dev_generator -->|"simulates designs"| node_simulation
node_researcher -->|"prepares augmentation"| node_augmentation
node_augmentation -->|"loads checkpoint"| node_inverse_model
node_augmentation -->|"evaluates decoded designs"| node_simulation
node_perturbation -->|"scores perturbations"| node_simulation
node_materials -->|"supplies optical constants"| node_simulation
node_augmentation_data -->|"provides training data"| node_retraining
node_workflow -.->|"coordinates"| node_augmentation
node_workflow -.->|"coordinates"| node_perturbation
node_workflow -.->|"coordinates"| node_augmentation_data
node_workflow -.->|"coordinates"| node_retraining
node_trainer -->|"saves trained checkpoint"| node_designs

click node_inverse_entry "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/run_optogpt.py"
click node_forward_entry "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/run_ol_transformer.py"
click node_preparation "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/datasets/datasets.py"
click node_trainer "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/trains/train.py"
click node_transformer "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py"
click node_inverse_model "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py"
click node_forward_model "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py"
click node_simulation "https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/datasets/sim.py"
click node_materials "https://github.com/taigaoma1997/optogpt/tree/main/optogpt/nk"
click node_dev_generator "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/generate_dev_data.py"
click node_augmentation "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/prepare_aug_data.py"
click node_perturbation "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/data_perturb.py"
click node_augmentation_data "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/combine_data.py"
click node_retraining "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/model_retrain.py"
click node_workflow "https://github.com/taigaoma1997/optogpt/blob/main/self_improving/run_self_improving.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_transformer,node_inverse_model,node_forward_model toneBlue
class node_simulation,node_materials toneAmber
class node_dev_generator,node_augmentation,node_perturbation,node_augmentation_data,node_retraining,node_workflow toneMint
class node_inverse_entry,node_forward_entry,node_preparation,node_trainer toneRose
class node_researcher,node_pairs,node_designs toneIndigo
```

## Components

### OptoGPT models

- [Transformer models](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py): `optogpt/core/models/transformer.py`
- [Inverse design model](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py): `optogpt/core/models/transformer.py`
- [Forward surrogate](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/models/transformer.py): `optogpt/core/models/transformer.py`

### Optical simulation

- [Thin-film simulator](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/datasets/sim.py): `optogpt/core/datasets/sim.py`
- [Optical constants](https://github.com/taigaoma1997/optogpt/tree/main/optogpt/nk): `optogpt/nk`

### Self-improving augmentation

- [OOD spectrum generator](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/generate_dev_data.py): `self_improving/generate_dev_data.py`
- [Augmentation preparation](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/prepare_aug_data.py): `self_improving/prepare_aug_data.py`
- [Design perturbation](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/data_perturb.py): `self_improving/data_perturb.py`
- [Augmented data tools](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/combine_data.py): `self_improving/combine_data.py`
- [Model retraining](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/model_retrain.py): `self_improving/model_retrain.py`
- [Improvement runner](https://github.com/taigaoma1997/optogpt/blob/main/self_improving/run_self_improving.py): `self_improving/run_self_improving.py`

### Training pipeline

- [Inverse training entry](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/run_optogpt.py): `optogpt/run_optogpt.py`
- [Surrogate training entry](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/run_ol_transformer.py): `optogpt/run_ol_transformer.py`
- [Pair preparation](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/datasets/datasets.py): `optogpt/core/datasets/datasets.py`
- [Training and loss](https://github.com/taigaoma1997/optogpt/blob/main/optogpt/core/trains/train.py): `optogpt/core/trains/train.py`

### Other components

- **Researcher**
- **Structure-spectrum data**
- **Candidate film designs**

## Connections

- Researcher → Inverse training entry: starts training
- Structure-spectrum data → Pair preparation: loads pairs
- Inverse training entry → Pair preparation: prepares inverse data
- Surrogate training entry → Pair preparation: prepares forward data
- Inverse training entry → Inverse design model: builds model
- Surrogate training entry → Forward surrogate: builds model
- Inverse design model → Transformer models: uses components
- Forward surrogate → Transformer models: uses components
- Inverse training entry → Training and loss: trains inverse model
- Surrogate training entry → Training and loss: trains surrogate
- Researcher → OOD spectrum generator: requests OOD data
- OOD spectrum generator → Thin-film simulator: simulates designs
- Researcher → Augmentation preparation: prepares augmentation
- Augmentation preparation → Inverse design model: loads checkpoint
- Augmentation preparation → Thin-film simulator: evaluates decoded designs
- Design perturbation → Thin-film simulator: scores perturbations
- Optical constants → Thin-film simulator: supplies optical constants
- Augmented data tools → Model retraining: provides training data
- Improvement runner → Augmentation preparation: coordinates
- Improvement runner → Design perturbation: coordinates
- Improvement runner → Augmented data tools: coordinates
- Improvement runner → Model retraining: coordinates
- Training and loss → Candidate film designs: saves trained checkpoint
