agentleFS
orange4664orange4664/research-skills/code-analyzer/SKILL.md

code-analyzer

Skill41 starsChanged 8 months agoMITView on GitHub

Deep analysis of ML source code repositories — AST call graphs, training loop dissection, reproducibility scoring.

  • Installs packages

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

6 rules. 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After paper-downloader has cloned source code

    line 23
  2. Distinctive:

    Before running code-reproducer (to generate the reproduction plan)

    line 25
  3. Distinctive:

    When evaluating whether a codebase is worth trying to reproduce

    line 26
  4. Very specific:

    Class hierarchy: All classes, especially nn.Module subclasses

    line 50
  5. Distinctive:

    When encountering issues with code analysis, fetch these URLs:

    line 141
  6. Very specific:

    Solution: Ensure graphviz is installed system-wide.

    line 164

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Code Analyzer Skill

Purpose

Perform comprehensive analysis of a cloned ML research repository to understand:

  • What framework it uses (PyTorch, TensorFlow, JAX, HuggingFace)
  • How its code is structured (classes, functions, call graphs)
  • How training works (optimizer, loss, scheduler, loop structure)
  • What configuration system it uses (argparse, Hydra, YAML, etc.)
  • How reproducible it is (0-100 score based on ML Code Completeness Checklist)

This skill produces a structured JSON report consumed by other skills:

  • code-reproducer: Uses the reproduction plan to run experiments
  • paper-presenter: Uses AST analysis for code-theory alignment

When to Use

  • After paper-downloader has cloned source code
  • User asks to "analyze", "understand", or "review" source code
  • Before running code-reproducer (to generate the reproduction plan)
  • When evaluating whether a codebase is worth trying to reproduce

Quick Start

# Install optional dependencies (for flowchart generation)
pip install -r code-analyzer/requirements.txt

# Run full analysis
python code-analyzer/analyze.py workspace/<paper>/code/<repo>/ -o workspace/<paper>/code_analysis.json

# With optional code2flow flowchart
python code-analyzer/analyze.py <code_dir> -o analysis.json --flowchart

What It Analyzes

1. Framework Detection

Scans imports and dependency files to identify:

  • PyTorch, TensorFlow, JAX, HuggingFace, Diffusers, scikit-learn
  • Gives confidence scores for each framework

2. AST Deep Analysis (Python ast module, PyCG-inspired)

  • Function call graph: Who calls whom
  • Class hierarchy: All classes, especially nn.Module subclasses
  • Model layer extraction: self.conv1 = nn.Conv2d(...) from __init__
  • Key functions: trains, forwards, losses, evaluates, samples, generates
  • Import dependency graph: Module → imported modules

3. Training Loop Dissection

  • Locates for epoch in range(...) training loops via AST
  • Identifies optimizer type (Adam, SGD, AdamW, etc.)
  • Identifies loss function type (CrossEntropy, MSE, custom, etc.)
  • Detects LR scheduler, logging framework (WandB, TensorBoard, etc.)
  • Extracts hyperparameters (lr, batch_size, epochs, etc.)
  • Detects checkpoint saving, distributed training, mixed precision

4. Configuration System Detection

  • Detects: argparse, Hydra, OmegaConf, click, fire, sacred, absl, yacs
  • Extracts all argparse arguments with name, type, default, help
  • Parses YAML/TOML config files
  • Consolidates key hyperparameters

5. Reproducibility Scoring (ML Code Completeness Checklist)

Based on NeurIPS/PwC standards:

CheckPoints
Dependency spec (requirements.txt)15
Training code15
Evaluation code10
Pre-trained models10
Config files10
README training commands10
Results table10
Dockerfile5
LICENSE5
.gitignore5
Tests5

Total: 100 points → Grade A/B/C/D/F

6. Reproduction Plan Generation

Automatically generates a step-by-step reproduction plan with shell commands.

Output Format

The JSON report contains:

{
  "framework": {"primary": "pytorch", "all": {...}},
  "structure": {"total_files": 42, "total_py_files": 28},
  "ast_analysis": {
    "model_classes": [...],
    "key_functions": {"train": [...], "forward": [...], "loss": [...]},
    "call_graph": {"module.func": ["callee1", "callee2"]},
    "stats": {"total_functions": 150, "model_classes": 3}
  },
  "training": {
    "training_loops": [...],
    "optimizers": ["AdamW"],
    "loss_functions": ["CrossEntropyLoss"],
    "hyperparameters": {"lr": "0.001", "batch_size": "32"}
  },
  "configs": {
    "config_systems": ["argparse"],
    "argparse_args": [{"name": "--lr", "default": "0.001"}]
  },
  "reproducibility": {
    "total_score": 75,
    "grade": "B",
    "recommendations": [...]
  },
  "reproduction_plan": [
    {"step": 1, "name": "Environment Setup", "commands": [...]},
    {"step": 2, "name": "Training", "commands": [...]}
  ]
}

Dependencies

  • Core: Python 3.10+ (stdlib only — ast, re, json, pathlib)
  • Optional: code2flow for flowchart generation (pip install code2flow)

Integration with Other Skills

  • Input: Cloned source code directory (from paper-downloader)
  • Output: code_analysis.json used by:
    • code-reproducer → reads reproduction plan, training commands
    • paper-presenter → reads AST analysis for code-theory alignment
    • result-analyzer → reads expected metrics for comparison

📚 Reference URLs (for agent self-help)

When encountering issues with code analysis, fetch these URLs:

TopicURL
Python ast module docshttps://docs.python.org/3/library/ast.html
PyCG call graph analysishttps://github.com/vitsalis/PyCG
PyCG paper (ICSE'21)https://arxiv.org/abs/2103.00587
code2flow flowchartshttps://github.com/scottrogowski/code2flow
ML Code Completeness Checklisthttps://medium.com/paperswithcode/ml-code-completeness-checklist-e9127b168501
Papers With Code trendshttps://paperswithcode.com/trends
PyTorch model inspectionhttps://pytorch.org/docs/stable/generated/torch.nn.Module.html
HuggingFace Trainer APIhttps://huggingface.co/docs/transformers/main_classes/trainer

Troubleshooting AST Analysis

Problem: AST parsing fails on a Python file. Likely cause: Non-standard Python syntax, encoding issues, or Python 2 code.

# Fetch Python ast docs:
fetch_url("https://docs.python.org/3/library/ast.html")

Troubleshooting code2flow

Problem: code2flow not generating flowcharts. Solution: Ensure graphviz is installed system-wide.

# Windows
choco install graphviz
# Ubuntu
apt-get install graphviz
# Fetch code2flow docs:
fetch_url("https://github.com/scottrogowski/code2flow")

Understanding Reproducibility Scores

Problem: Need to understand why a repo scored low.

# Fetch the ML Code Completeness methodology:
fetch_url("https://medium.com/paperswithcode/ml-code-completeness-checklist-e9127b168501")

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.