diff --git a/ai_scientist/perform_writeup.py b/ai_scientist/perform_writeup.py index 7dc9eebe..7bf7dadb 100644 --- a/ai_scientist/perform_writeup.py +++ b/ai_scientist/perform_writeup.py @@ -5,6 +5,7 @@ import re import shutil import subprocess + from typing import Optional, Tuple from ai_scientist.generate_ideas import search_for_papers @@ -15,7 +16,7 @@ def generate_latex(coder, folder_name, pdf_file, timeout=30, num_error_corrections=5): folder = osp.abspath(folder_name) cwd = osp.join(folder, "latex") # Fixed potential issue with path - writeup_file = osp.join(cwd, "template.tex") + writeup_file = osp.join(cwd, "template_segments.tex") # Check all references are valid and in the references.bib file with open(writeup_file, "r") as f: @@ -27,7 +28,7 @@ def generate_latex(coder, folder_name, pdf_file, timeout=30, num_error_correctio re.DOTALL, ) if references_bib is None: - print("No references.bib found in template.tex") + print("No references.bib found in template_segments.tex") return bib_text = references_bib.group(1) cites = [cite.strip() for item in cites for cite in item.split(",")] @@ -35,7 +36,7 @@ def generate_latex(coder, folder_name, pdf_file, timeout=30, num_error_correctio if cite not in bib_text: print(f"Reference {cite} not found in references.") prompt = f"""Reference {cite} not found in references.bib. Is this included under a different name? -If so, please modify the citation in template.tex to match the name in references.bib at the top. Otherwise, remove the cite.""" +If so, please modify the citation in template_segments.tex to match the name in references.bib at the top. Otherwise, remove the cite.""" coder.run(prompt) # Check all included figures are actually in the directory. @@ -79,7 +80,7 @@ def generate_latex(coder, folder_name, pdf_file, timeout=30, num_error_correctio # Filter trivial bugs in chktex check_output = os.popen(f"chktex {writeup_file} -q -n2 -n24 -n13 -n1").read() if check_output: - prompt = f"""Please fix the following LaTeX errors in `template.tex` guided by the output of `chktek`: + prompt = f"""Please fix the following LaTeX errors in `template_segments.tex` guided by the output of `chktek`: {check_output}. Make the minimal fix required and do not remove or change any packages. @@ -95,10 +96,10 @@ def compile_latex(cwd, pdf_file, timeout=30): print("GENERATING LATEX") commands = [ - ["pdflatex", "-interaction=nonstopmode", "template.tex"], + ["pdflatex", "-interaction=nonstopmode", "template_segments.tex"], ["bibtex", "template"], - ["pdflatex", "-interaction=nonstopmode", "template.tex"], - ["pdflatex", "-interaction=nonstopmode", "template.tex"], + ["pdflatex", "-interaction=nonstopmode", "template_segments.tex"], + ["pdflatex", "-interaction=nonstopmode", "template_segments.tex"], ] for command in commands: @@ -122,7 +123,7 @@ def compile_latex(cwd, pdf_file, timeout=30): # Attempt to move the PDF to the desired location try: - shutil.move(osp.join(cwd, "template.pdf"), pdf_file) + shutil.move(osp.join(cwd, "template_segments.pdf"), pdf_file) except FileNotFoundError: print("Failed to rename PDF.") @@ -401,18 +402,48 @@ def get_citation_aider_prompt( def perform_writeup( idea, folder_name, coder, cite_client, cite_model, num_cite_rounds=20 ): - # 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. + dic_section_files = {"TITLE": "TITLE_HERE.tex", + "ABSTRACT" : "ABSTRACT_HERE.tex", + "Introduction" : "INTRO_HERE.tex", + "Background" : "BACKGROUND_HERE.tex", + "Related work" : "RELATED_WORK_HERE.tex", + "Method" : "METHOD_HERE.tex", + "Experimental Setup" : "EXPERIMENTAL_SETUP_HERE.tex", + "Results" : "RESULTS_HERE.tex", + "Conclusion": "CONCLUSIONS_HERE.tex", + } + + title_prompt = f"""We've provided the file to the project. + We will be filling it in section by section. Every section is located in a separate file. + + First, please fill the "Title" sections of the writeup in file {dic_section_files["TITLE"]}. + + Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment. + + Be sure to first name the file and then filling. + """ + coder_out = coder.run(title_prompt) + coder_out = coder.run( + refinement_prompt.format(section="Title") + .replace(r"{{", "{") + .replace(r"}}", "}") + ) -First, please fill in the "Title" and "Abstract" sections of the writeup. + # CURRENTLY ASSUMES LATEX + abstract_prompt = f"""We've provided the `latex/template_segments.tex` file to the project. + We will be filling it in section by section. Every section is located in a separate file. -Some tips are provided below: -{per_section_tips["Abstract"]} + First, please fill the "Abstract" sections of the writeup in file {dic_section_files["ABSTRACT"]}. + + 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. + + Be sure to first name the file and then filling. + """ -Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment. -Be sure to first name the file and use *SEARCH/REPLACE* blocks to perform these edits. -""" coder_out = coder.run(abstract_prompt) coder_out = coder.run( refinement_prompt.format(section="Abstract") @@ -427,7 +458,7 @@ def perform_writeup( "Results", "Conclusion", ]: - section_prompt = f"""Please fill in the {section} of the writeup. Some tips are provided below: + section_prompt = f"""Please fill in the {section} of the writeup in file {dic_section_files[section]}. Some tips are provided below: {per_section_tips[section]} Be sure to use \cite or \citet where relevant, referring to the works provided in the file. @@ -438,7 +469,7 @@ def perform_writeup( Before every paragraph, please include a brief description of what you plan to write in that paragraph in a comment. -Be sure to first name the file and use *SEARCH/REPLACE* blocks to perform these edits. +Be sure to first name the file and then filling. """ coder_out = coder.run(section_prompt) coder_out = coder.run( @@ -448,7 +479,7 @@ def perform_writeup( ) # SKETCH THE RELATED WORK - section_prompt = f"""Please fill in the Related Work of the writeup. Some tips are provided below: + section_prompt = f"""Please fill in the Related Work of the writeup in file {dic_section_files['Related work']}. Some tips are provided below: {per_section_tips["Related Work"]} @@ -457,13 +488,13 @@ def perform_writeup( 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. -Be sure to first name the file and use *SEARCH/REPLACE* blocks to perform these edits. +Be sure to first name the file and then filling. """ coder_out = coder.run(section_prompt) # Fill paper with cites. for _ in range(num_cite_rounds): - with open(osp.join(folder_name, "latex", "template.tex"), "r") as f: + with open(osp.join(folder_name, "latex", "template_segments.tex"), "r") as f: draft = f.read() prompt, done = get_citation_aider_prompt( cite_client, cite_model, draft, _, num_cite_rounds @@ -476,7 +507,7 @@ def perform_writeup( # insert this into draft before the "\end{filecontents}" line search_str = r"\end{filecontents}" draft = draft.replace(search_str, f"{bibtex_string}{search_str}") - with open(osp.join(folder_name, "latex", "template.tex"), "w") as f: + with open(osp.join(folder_name, "latex", "template_segments.tex"), "w") as f: f.write(draft) coder_out = coder.run(prompt) @@ -537,7 +568,7 @@ def perform_writeup( vis_file = osp.join(folder_name, "plot.py") notes = osp.join(folder_name, "notes.txt") model = args.model - writeup_file = osp.join(folder_name, "latex", "template.tex") + writeup_file = osp.join(folder_name, "latex", "template_segments.tex") ideas_file = osp.join(folder_name, "ideas.json") with open(ideas_file, "r") as f: ideas = json.load(f) @@ -561,7 +592,7 @@ def perform_writeup( io=io, stream=False, use_git=False, - edit_format="diff", + edit_format="whole", ) if args.no_writing: generate_latex(coder, args.folder, f"{args.folder}/test.pdf") diff --git a/launch_scientist.py b/launch_scientist.py index 4e9e719e..212c27c8 100644 --- a/launch_scientist.py +++ b/launch_scientist.py @@ -200,8 +200,22 @@ def do_idea( print(f"*Starting Writeup*") ## PERFORM WRITEUP if writeup == "latex": - writeup_file = osp.join(folder_name, "latex", "template.tex") - fnames = [exp_file, writeup_file, notes] + writeup_file = osp.join(folder_name, "latex", "template_segments.tex") + TITLE_file = osp.join(folder_name, "latex", "TITLE_HERE.tex") + ABSTRACT_file = osp.join(folder_name, "latex", "ABSTRACT_HERE.tex") + + + INTRO_file = osp.join(folder_name, "latex", "INTRO_HERE.tex") + RELATED_WORK_file = osp.join(folder_name, "latex", "RELATED_WORK_HERE.tex") + BACKGROUND_file = osp.join(folder_name, "latex", "BACKGROUND_HERE.tex") + METHOD_file = osp.join(folder_name, "latex", "METHOD_HERE.tex") + EXPERIMENTAL_SETUP_file = osp.join(folder_name, "latex", "EXPERIMENTAL_SETUP_HERE.tex") + RESULTS_file = osp.join(folder_name, "latex", "RESULTS_HERE.tex") + CONCLUSIONS_file = osp.join(folder_name, "latex", "CONCLUSIONS_HERE.tex") + + fnames = [exp_file, writeup_file, notes,\ + TITLE_file, ABSTRACT_file, INTRO_file, RELATED_WORK_file, BACKGROUND_file,\ + METHOD_file, EXPERIMENTAL_SETUP_file, RESULTS_file, CONCLUSIONS_file] if model == "deepseek-coder-v2-0724": main_model = Model("deepseek/deepseek-coder") elif model == "llama3.1-405b": diff --git a/templates/2d_diffusion/latex/ABSTRACT_HERE.tex b/templates/2d_diffusion/latex/ABSTRACT_HERE.tex new file mode 100644 index 00000000..e5388f6d --- /dev/null +++ b/templates/2d_diffusion/latex/ABSTRACT_HERE.tex @@ -0,0 +1 @@ +ABSTRACT*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/BACKGROUND_HERE.tex b/templates/2d_diffusion/latex/BACKGROUND_HERE.tex new file mode 100644 index 00000000..ea25d08c --- /dev/null +++ b/templates/2d_diffusion/latex/BACKGROUND_HERE.tex @@ -0,0 +1 @@ +BACKGROUND*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/CONCLUSIONS_HERE.tex b/templates/2d_diffusion/latex/CONCLUSIONS_HERE.tex new file mode 100644 index 00000000..8d27b09e --- /dev/null +++ b/templates/2d_diffusion/latex/CONCLUSIONS_HERE.tex @@ -0,0 +1 @@ +CONCLUSIONS*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/EXPERIMENTAL_SETUP_HERE.tex b/templates/2d_diffusion/latex/EXPERIMENTAL_SETUP_HERE.tex new file mode 100644 index 00000000..a7233dc8 --- /dev/null +++ b/templates/2d_diffusion/latex/EXPERIMENTAL_SETUP_HERE.tex @@ -0,0 +1,12 @@ +EXPERIMENTAL*SETUP*HERE + +% EXAMPLE FIGURE: REPLACE AND ADD YOUR OWN FIGURES / CAPTIONS +\begin{figure}[t] + \centering + \begin{subfigure}{0.9\textwidth} + \includegraphics[width=\textwidth]{generated_images.png} + \label{fig:diffusion-samples} + \end{subfigure} + \caption{PLEASE FILL IN CAPTION HERE} + \label{fig:first_figure} +\end{figure} \ No newline at end of file diff --git a/templates/2d_diffusion/latex/INTRO_HERE.tex b/templates/2d_diffusion/latex/INTRO_HERE.tex new file mode 100644 index 00000000..c2c88fc2 --- /dev/null +++ b/templates/2d_diffusion/latex/INTRO_HERE.tex @@ -0,0 +1 @@ +INTRO*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/METHOD_HERE.tex b/templates/2d_diffusion/latex/METHOD_HERE.tex new file mode 100644 index 00000000..7865ed96 --- /dev/null +++ b/templates/2d_diffusion/latex/METHOD_HERE.tex @@ -0,0 +1 @@ +METHOD*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/RELATED_WORK_HERE.tex b/templates/2d_diffusion/latex/RELATED_WORK_HERE.tex new file mode 100644 index 00000000..ab47841e --- /dev/null +++ b/templates/2d_diffusion/latex/RELATED_WORK_HERE.tex @@ -0,0 +1 @@ +RELATED*WORK*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/RESULTS_HERE.tex b/templates/2d_diffusion/latex/RESULTS_HERE.tex new file mode 100644 index 00000000..625385cf --- /dev/null +++ b/templates/2d_diffusion/latex/RESULTS_HERE.tex @@ -0,0 +1 @@ +RESULTS*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/TITLE_HERE.tex b/templates/2d_diffusion/latex/TITLE_HERE.tex new file mode 100644 index 00000000..a588dc87 --- /dev/null +++ b/templates/2d_diffusion/latex/TITLE_HERE.tex @@ -0,0 +1 @@ +TITLE*HERE \ No newline at end of file diff --git a/templates/2d_diffusion/latex/template_segments.tex b/templates/2d_diffusion/latex/template_segments.tex new file mode 100644 index 00000000..9d2c55a0 --- /dev/null +++ b/templates/2d_diffusion/latex/template_segments.tex @@ -0,0 +1,184 @@ +\documentclass{article} % For LaTeX2e +\usepackage{iclr2024_conference,times} + +\usepackage[utf8]{inputenc} % allow utf-8 input +\usepackage[T1]{fontenc} % use 8-bit T1 fonts +\usepackage{hyperref} % hyperlinks +\usepackage{url} % simple URL typesetting +\usepackage{booktabs} % professional-quality tables +\usepackage{amsfonts} % blackboard math symbols +\usepackage{nicefrac} % compact symbols for 1/2, etc. +\usepackage{microtype} % microtypography +\usepackage{titletoc} + +\usepackage{subcaption} +\usepackage{graphicx} +\usepackage{amsmath} +\usepackage{multirow} +\usepackage{color} +\usepackage{colortbl} +\usepackage{cleveref} +\usepackage{algorithm} +\usepackage{algorithmicx} +\usepackage{algpseudocode} + +\DeclareMathOperator*{\argmin}{arg\,min} +\DeclareMathOperator*{\argmax}{arg\,max} + +\graphicspath{{../}} % To reference your generated figures, see below. +\begin{filecontents}{references.bib} +@article{lu2024aiscientist, + title={The {AI} {S}cientist: Towards Fully Automated Open-Ended Scientific Discovery}, + author={Lu, Chris and Lu, Cong and Lange, Robert Tjarko and Foerster, Jakob and Clune, Jeff and Ha, David}, + journal={arXiv preprint arXiv:2408.06292}, + year={2024} +} + +@book{goodfellow2016deep, + title={Deep learning}, + author={Goodfellow, Ian and Bengio, Yoshua and Courville, Aaron and Bengio, Yoshua}, + volume={1}, + year={2016}, + publisher={MIT Press} +} + +@article{yang2023diffusion, + title={Diffusion models: A comprehensive survey of methods and applications}, + author={Yang, Ling and Zhang, Zhilong and Song, Yang and Hong, Shenda and Xu, Runsheng and Zhao, Yue and Zhang, Wentao and Cui, Bin and Yang, Ming-Hsuan}, + journal={ACM Computing Surveys}, + volume={56}, + number={4}, + pages={1--39}, + year={2023}, + publisher={ACM New York, NY, USA} +} + +@inproceedings{ddpm, + author = {Ho, Jonathan and Jain, Ajay and Abbeel, Pieter}, + booktitle = {Advances in Neural Information Processing Systems}, + editor = {H. Larochelle and M. Ranzato and R. Hadsell and M.F. Balcan and H. Lin}, + pages = {6840--6851}, + publisher = {Curran Associates, Inc.}, + title = {Denoising Diffusion Probabilistic Models}, + url = {https://proceedings.neurips.cc/paper/2020/file/4c5bcfec8584af0d967f1ab10179ca4b-Paper.pdf}, + volume = {33}, + year = {2020} +} + +@inproceedings{vae, + added-at = {2020-10-15T14:36:56.000+0200}, + author = {Kingma, Diederik P. and Welling, Max}, + biburl = {https://www.bibsonomy.org/bibtex/242e5be6faa01cba2587f4907ac99dce8/annakrause}, + booktitle = {2nd International Conference on Learning Representations, {ICLR} 2014, Banff, AB, Canada, April 14-16, 2014, Conference Track Proceedings}, + eprint = {http://arxiv.org/abs/1312.6114v10}, + eprintclass = {stat.ML}, + eprinttype = {arXiv}, + file = {:http\://arxiv.org/pdf/1312.6114v10:PDF;:KingmaWelling_Auto-EncodingVariationalBayes.pdf:PDF}, + interhash = {a626a9d77a123c52405a08da983203cb}, + intrahash = {42e5be6faa01cba2587f4907ac99dce8}, + keywords = {cs.LG stat.ML vae}, + timestamp = {2021-02-01T17:13:18.000+0100}, + title = {{Auto-Encoding Variational Bayes}}, + year = 2014 +} + +@inproceedings{gan, + author = {Goodfellow, Ian and Pouget-Abadie, Jean and Mirza, Mehdi and Xu, Bing and Warde-Farley, David and Ozair, Sherjil and Courville, Aaron and Bengio, Yoshua}, + booktitle = {Advances in Neural Information Processing Systems}, + editor = {Z. Ghahramani and M. Welling and C. Cortes and N. Lawrence and K.Q. Weinberger}, + pages = {}, + publisher = {Curran Associates, Inc.}, + title = {Generative Adversarial Nets}, + url = {https://proceedings.neurips.cc/paper/2014/file/5ca3e9b122f61f8f06494c97b1afccf3-Paper.pdf}, + volume = {27}, + year = {2014} +} + +@InProceedings{pmlr-v37-sohl-dickstein15, + title = {Deep Unsupervised Learning using Nonequilibrium Thermodynamics}, + author = {Sohl-Dickstein, Jascha and Weiss, Eric and Maheswaranathan, Niru and Ganguli, Surya}, + booktitle = {Proceedings of the 32nd International Conference on Machine Learning}, + pages = {2256--2265}, + year = {2015}, + editor = {Bach, Francis and Blei, David}, + volume = {37}, + series = {Proceedings of Machine Learning Research}, + address = {Lille, France}, + month = {07--09 Jul}, + publisher = {PMLR} +} + +@inproceedings{ +edm, +title={Elucidating the Design Space of Diffusion-Based Generative Models}, +author={Tero Karras and Miika Aittala and Timo Aila and Samuli Laine}, +booktitle={Advances in Neural Information Processing Systems}, +editor={Alice H. Oh and Alekh Agarwal and Danielle Belgrave and Kyunghyun Cho}, +year={2022}, +url={https://openreview.net/forum?id=k7FuTOWMOc7} +} + +@misc{kotelnikov2022tabddpm, + title={TabDDPM: Modelling Tabular Data with Diffusion Models}, + author={Akim Kotelnikov and Dmitry Baranchuk and Ivan Rubachev and Artem Babenko}, + year={2022}, + eprint={2209.15421}, + archivePrefix={arXiv}, + primaryClass={cs.LG} +} + +\end{filecontents} + +\title{\input{TITLE_HERE.tex}} + +\author{GPT-4o \& Claude\\ +Department of Computer Science\\ +University of LLMs\\ +} + +\newcommand{\fix}{\marginpar{FIX}} +\newcommand{\new}{\marginpar{NEW}} + +\begin{document} + +\maketitle + +\begin{abstract} +\input{ABSTRACT_HERE.tex} +\end{abstract} + +\section{Introduction} +\label{sec:intro} +\input{INTRO_HERE.tex} + +\section{Related Work} +\label{sec:related} +\input{RELATED_WORK_HERE.tex} + +\section{Background} +\label{sec:background} +\input{BACKGROUND_HERE.tex} + +\section{Method} +\label{sec:method} +\input{METHOD_HERE.tex} + +\section{Experimental Setup} +\label{sec:experimental} +\input{EXPERIMENTAL_SETUP_HERE.tex} + + +\section{Results} +\label{sec:results} +\input{RESULTS_HERE.tex} + +\section{Conclusions and Future Work} +\label{sec:conclusion} +\input{CONCLUSIONS_HERE.tex} + +This work was generated by \textsc{The AI Scientist} \citep{lu2024aiscientist}. + +\bibliographystyle{iclr2024_conference} +\bibliography{references} + +\end{document}