# ramithuh/diff-evol-tree-search architecture

> Architecture diagram of the GitHub repository ramithuh/diff-evol-tree-search, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ramithuh/diff-evol-tree-search
- Repository: https://github.com/ramithuh/diff-evol-tree-search

## Overview

##### Project Overview
- Project Type: A research-focused, command-line driven experimentation tool for evolutionary tree search using differentiable optimization.
- Purpose: To construct and optimize phylogenetic trees from leaf sequences, offering a differentiable approach to traditional parsimony methods in evolutionary computing.

##### Main Components
- Input Handling & Parameter Parsing:
- Files: arg_parser_v2.py, various command-line parameters shown in README.
- Role: Parse input arguments (e.g., number of leaves, sequence length, mutation rate, etc.) that configure the experimental runs.

- Core Tree Generation & Optimization Modules:
- Files in modules/: gt_tree_gen.py, sankoff.py, tree_func.py.
- Role: Implement the key algorithms and mathematical models to generate trees, calculate parsimony scores, and perform differentiable optimization.

- Statistics & Utility Functions:
- Files: gt_stats.py, modules/vis_utils.py.
- Role: Compute statistics during training (e.g., soft_parsimony_score, parsimony_score) and provide visualization utilities to illustrate tree structures.

- Training & Runner Scripts:
- Files: seed_runner_maximum_parsimony.py, seed_runner_small_parismony.py, train_batch_alt.py, train_batch_implicit_diff.py, train_small_parsimony.py.
- Role: Orchestrate the training process; each script may represent different experiment configurations (e.g., with implicit differentiation feature or maximum parsimony variants).

- Deployment / Experimentation Interface:
- File: run_on_colab.ipynb.
- Role: Provide an interactive, notebook-based interface for running the experiments on Google Colab.

- External Configuration:
- Files: requirements.txt.
- Role: List dependencies used by the project (e.g., Python libraries for numerical computation and optimization).

##### Defining Relationships and Interactions
- Input flow starts with the user providing arguments/configurations (likely via command-line or interactive notebook).
- The main runner scripts trigger the training processes, which call on the tree generation modules to build tree structures based on the parsed parameters.
- Core modules collaborate in the loop: the algorithm computes parsimony scores (via [sankoff.py, tree_func.py]) with utilities in vis_utils.py optionally rendering visuals.
- The gt_stats.py module collects and logs performance metrics throughout training, with outputs (scores) being printed at regular intervals.
- Experiment settings may change the behavior (e.g., different training approaches like maximum parsimony or implicit differentiation) based on the selected script.
- Finally, colab notebooks provide an end-user interface that wraps these components into a user-friendly, documented execution environment.

##### Architectural Patterns & Technologies
- Command-line Interface/Script-Based Architecture: Multiple entry points (scripts) allow switching between approaches.
- Modular Design: Separate folders and files encapsulate specific functionality (tree generation, statistics, visualization), promoting separation of concerns.
- Research/Experimental Design: Direct scripts to experiment with model optimization parameters and configurations in evolutionary computation.
- Differentiable Optimization: Central to the approach, emphasizing gradient-based methods to adjust tree topology and sequence parameters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level components
    Param["Parameter Parsing (arg_parser_v2.py)"]:::input
    Interface["Interactive Interface (run_on_colab.ipynb)"]:::interface
    Deps["Dependencies (requirements.txt)"]:::deps

    %% Training/Runners Cluster
    subgraph "Training/Runners"
      direction TB
      Train1["seed_runner_maximum_parsimony.py"]:::runner
      Train2["seed_runner_small_parsimony.py"]:::runner
      Train3["train_batch_alt.py"]:::runner
      Train4["train_batch_implicit_diff.py"]:::runner
      Train5["train_small_parsimony.py"]:::runner
    end

    %% Core Tree Construction Cluster
    subgraph "Core Tree Construction"
      direction TB
      Core1["gt_tree_gen.py"]:::core
      Core2["sankoff.py"]:::core
      Core3["tree_func.py"]:::core
    end

    %% Statistics & Visualization Cluster
    subgraph "Statistics & Visualization"
      direction TB
      Stat["gt_stats.py"]:::stats
      Vis["vis_utils.py"]:::stats
    end

    %% Output Log/Console
    Output["Output Log/Console"]:::output

    %% Flow Connections
    Param -->|"triggers"| Train1
    Interface -->|"triggers"| Train1
    Train5 -->|"optimizes"| Core1
    Core3 -->|"computes"| Stat
    Stat -->|"visualizes"| Vis
    Vis -->|"logs"| Output

    %% Dependencies linking (dashed lines)
    Deps --- Param
    Deps --- Train1
    Deps --- Core1
    Deps --- Stat

    %% Click Events
    click Param "https://github.com/ramithuh/diff-evol-tree-search/blob/main/arg_parser_v2.py"
    click Interface "https://github.com/ramithuh/diff-evol-tree-search/blob/main/run_on_colab.ipynb"
    click Deps "https://github.com/ramithuh/diff-evol-tree-search/blob/main/requirements.txt"
    click Train1 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/seed_runner_maximum_parsimony.py"
    click Train2 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/seed_runner_small_parsimony.py"
    click Train3 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/train_batch_alt.py"
    click Train4 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/train_batch_implicit_diff.py"
    click Train5 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/train_small_parsimony.py"
    click Core1 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/modules/gt_tree_gen.py"
    click Core2 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/modules/sankoff.py"
    click Core3 "https://github.com/ramithuh/diff-evol-tree-search/blob/main/modules/tree_func.py"
    click Stat "https://github.com/ramithuh/diff-evol-tree-search/blob/main/gt_stats.py"
    click Vis "https://github.com/ramithuh/diff-evol-tree-search/blob/main/modules/vis_utils.py"

    %% Styling Classes
    classDef input fill:#A8E6CF,stroke:#333,stroke-width:2px;
    classDef interface fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef deps fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef runner fill:#FFB347,stroke:#333,stroke-width:2px;
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef stats fill:#C0C0FF,stroke:#333,stroke-width:2px;
    classDef output fill:#F5A9A9,stroke:#333,stroke-width:2px;
```
