Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ai_scientist/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# Anthropic models
"claude-3-5-sonnet-20240620",
"claude-3-5-sonnet-20241022",
# Anthropic Claude 4.x family
"claude-opus-4-7",
"claude-sonnet-4-6",
"claude-haiku-4-5-20251001",
# OpenAI models
"gpt-4o-mini",
"gpt-4o-mini-2024-07-18",
Expand Down
20 changes: 14 additions & 6 deletions ai_scientist/perform_writeup.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ def compile_latex(cwd, pdf_file, timeout=30):
- Duplicate headers, e.g. duplicated \\section{{Introduction}} or \\end{{document}}
- Unescaped symbols, e.g. shakespeare_char should be shakespeare\\_char in text
- Incorrect closing of environments, e.g. </end{{figure}}> instead of \\end{{figure}}
- Any non-English text (Korean, Chinese, Japanese, etc.) in the paper body or LaTeX comments
"""

LANGUAGE_RULE = """
IMPORTANT — LANGUAGE RULE:
Write 100% of the paper body AND all LaTeX comments in English only.
Do NOT use Korean, Chinese, Japanese, or any other non-English language anywhere in `template.tex`.
When producing *SEARCH/REPLACE* blocks, the SEARCH section MUST match the existing file byte-for-byte (including whitespace); do not invent lines that are not in the file.
"""

refinement_prompt = (
Expand Down Expand Up @@ -403,13 +411,13 @@ def perform_writeup(
):
# CURRENTLY ASSUMES LATEX
abstract_prompt = f"""We've provided the `latex/template.tex` file to the project. We will be filling it in section by section.

{LANGUAGE_RULE}
First, please fill in the "Title" and "Abstract" sections of the writeup.

Some tips are provided below:
{per_section_tips["Abstract"]}

Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment.
Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment (in English).

Be sure to first name the file and use *SEARCH/REPLACE* blocks to perform these edits.
"""
Expand All @@ -429,14 +437,14 @@ def perform_writeup(
]:
section_prompt = f"""Please fill in the {section} of the writeup. Some tips are provided below:
{per_section_tips[section]}

{LANGUAGE_RULE}
Be sure to use \cite or \citet where relevant, referring to the works provided in the file.
Do not cite anything that is not already in `references.bib`. Do not add any new entries to this.

Keep the experimental results (figures and tables) only in the Results section, and make sure that any captions are filled in.
In this pass, do not reference anything in later sections of the paper.

Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment.
Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment (in English).

Be sure to first name the file and use *SEARCH/REPLACE* blocks to perform these edits.
"""
Expand All @@ -451,9 +459,9 @@ def perform_writeup(
section_prompt = f"""Please fill in the Related Work of the writeup. Some tips are provided below:

{per_section_tips["Related Work"]}

{LANGUAGE_RULE}
For this section, very briefly sketch out the structure of the section, and clearly indicate what papers you intend to include.
Do this all in LaTeX comments using %.
Do this all in LaTeX comments using % (comments MUST be in English).
The related work should be concise, only plan to discuss the most relevant work.
Do not modify `references.bib` to add any new citations, this will be filled in at a later stage.

Expand Down
30 changes: 28 additions & 2 deletions launch_scientist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
import shutil
import sys
import time
import torch
try:
import torch
except Exception as _torch_err:
# torch is only needed for GPU enumeration; non-torch templates (e.g. sklearn-based)
# should still run without it. Fall through with torch=None.
torch = None
print(f"[warn] torch import failed ({_torch_err.__class__.__name__}); "
f"GPU auto-detection disabled. Use --gpus to force-select if needed.")
from aider.coders import Coder
from aider.io import InputOutput
from aider.models import Model
Expand Down Expand Up @@ -95,7 +102,12 @@ def parse_arguments():
def get_available_gpus(gpu_ids=None):
if gpu_ids is not None:
return [int(gpu_id) for gpu_id in gpu_ids.split(",")]
return list(range(torch.cuda.device_count()))
if torch is None or not hasattr(torch, "cuda"):
return []
try:
return list(range(torch.cuda.device_count()))
except Exception:
return []


def check_latex_dependencies():
Expand Down Expand Up @@ -204,6 +216,8 @@ def do_idea(
main_model = Model("deepseek/deepseek-reasoner")
elif model == "llama3.1-405b":
main_model = Model("openrouter/meta-llama/llama-3.1-405b-instruct")
elif model.startswith("claude-"):
main_model = Model("anthropic/" + model)
else:
main_model = Model(model)
coder = Coder.create(
Expand All @@ -214,6 +228,12 @@ def do_idea(
use_git=False,
edit_format="diff",
)
# Bump Aider's retry budget when SEARCH/REPLACE blocks fail to match
# (default is 3; increase so transient mismatches don't abort writeup)
try:
coder.max_reflections = 6
except Exception:
pass

print_time()
print(f"*Starting Experiments*")
Expand All @@ -240,6 +260,8 @@ def do_idea(
main_model = Model("deepseek/deepseek-reasoner")
elif model == "llama3.1-405b":
main_model = Model("openrouter/meta-llama/llama-3.1-405b-instruct")
elif model.startswith("claude-"):
main_model = Model("anthropic/" + model)
else:
main_model = Model(model)
coder = Coder.create(
Expand All @@ -250,6 +272,10 @@ def do_idea(
use_git=False,
edit_format="diff",
)
try:
coder.max_reflections = 6
except Exception:
pass
try:
perform_writeup(idea, folder_name, coder, client, client_model, engine=args.engine)
except Exception as e:
Expand Down