|
""" |
|
This code is an implementation of Funsearch (https://www.nature.com/articles/s41586-023-06924-6) and is heavily inspired by the original code (https://github.com/google-deepmind/funsearch) |
|
|
|
**Citation**: |
|
|
|
@Article{FunSearch2023, |
|
author = {Romera-Paredes, Bernardino and Barekatain, Mohammadamin and Novikov, Alexander and Balog, Matej and Kumar, M. Pawan and Dupont, Emilien and Ruiz, Francisco J. R. and Ellenberg, Jordan and Wang, Pengming and Fawzi, Omar and Kohli, Pushmeet and Fawzi, Alhussein}, |
|
journal = {Nature}, |
|
title = {Mathematical discoveries from program search with large language models}, |
|
year = {2023}, |
|
doi = {10.1038/s41586-023-06924-6} |
|
} |
|
""" |
|
from typing import Any, Optional |
|
import dataclasses |
|
|
|
|
|
@dataclasses.dataclass |
|
class AbstractArtifact: |
|
""" Abstract class for artifacts.""" |
|
|
|
name: str |
|
args: str |
|
body: str |
|
return_type: Optional[str] = None |
|
docstring: Optional[str] = None |
|
|
|
def __str__(self)->str: |
|
raise NotImplementedError() |
|
|
|
def __setattr__(self, name: str, value: str) -> None: |
|
|
|
if name == 'body': |
|
value = value.strip('\n') |
|
|
|
if name == 'docstring' and value is not None: |
|
if '"""' in value: |
|
value = value.strip() |
|
value = value.replace('"""', '') |
|
super().__setattr__(name, value) |
|
|
|
def rename_artifact_calls(self, source_name, target_name) -> str: |
|
raise NotImplementedError |
|
|
|
def text_to_artifact(self): |
|
raise NotImplementedError |
|
|
|
def calls_ancestor(self,artifact_to_evolve: str) -> bool: |
|
raise NotImplementedError |