| """Frontier-CS: Evolving Challenges for Evolving Intelligence""" |
|
|
| import os |
| import datasets |
|
|
| _DESCRIPTION = """ |
| Frontier-CS is an unsolved, open-ended, verifiable, and diverse benchmark |
| for evaluating AI on challenging computer science problems. |
| """ |
|
|
| _HOMEPAGE = "https://frontier-cs.org" |
| _LICENSE = "Apache-2.0" |
|
|
| class FrontierCSConfig(datasets.BuilderConfig): |
| def __init__(self, **kwargs): |
| super().__init__(**kwargs) |
|
|
| class FrontierCS(datasets.GeneratorBasedBuilder): |
| VERSION = datasets.Version("1.0.0") |
|
|
| BUILDER_CONFIGS = [ |
| FrontierCSConfig(name="algorithmic", description="118 algorithmic problems"), |
| FrontierCSConfig(name="research", description="63 research problems"), |
| FrontierCSConfig(name="all", description="All problems"), |
| ] |
|
|
| DEFAULT_CONFIG_NAME = "all" |
|
|
| def _info(self): |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=datasets.Features({ |
| "problem_id": datasets.Value("string"), |
| "category": datasets.Value("string"), |
| "statement": datasets.Value("string"), |
| "config": datasets.Value("string"), |
| }), |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={"config_name": self.config.name}, |
| ), |
| ] |
|
|
| def _generate_examples(self, config_name): |
| base_path = os.path.dirname(os.path.abspath(__file__)) |
| idx = 0 |
|
|
| |
| if config_name in ["algorithmic", "all"]: |
| algo_path = os.path.join(base_path, "algorithmic", "problems") |
| if os.path.exists(algo_path): |
| for problem_id in sorted(os.listdir(algo_path)): |
| problem_dir = os.path.join(algo_path, problem_id) |
| if not os.path.isdir(problem_dir): |
| continue |
|
|
| statement = "" |
| config = "" |
|
|
| statement_file = os.path.join(problem_dir, "statement.txt") |
| if os.path.exists(statement_file): |
| with open(statement_file, "r", encoding="utf-8") as f: |
| statement = f.read() |
|
|
| config_file = os.path.join(problem_dir, "config.yaml") |
| if os.path.exists(config_file): |
| with open(config_file, "r", encoding="utf-8") as f: |
| config = f.read() |
|
|
| yield idx, { |
| "problem_id": problem_id, |
| "category": "algorithmic", |
| "statement": statement, |
| "config": config, |
| } |
| idx += 1 |
|
|
| |
| if config_name in ["research", "all"]: |
| research_path = os.path.join(base_path, "research", "problems") |
| if os.path.exists(research_path): |
| for category in sorted(os.listdir(research_path)): |
| category_dir = os.path.join(research_path, category) |
| if not os.path.isdir(category_dir): |
| continue |
|
|
| |
| readme_file = os.path.join(category_dir, "readme") |
| config_file = os.path.join(category_dir, "config.yaml") |
|
|
| if os.path.exists(readme_file) or os.path.exists(config_file): |
| |
| statement = "" |
| config = "" |
|
|
| if os.path.exists(readme_file): |
| with open(readme_file, "r", encoding="utf-8") as f: |
| statement = f.read() |
|
|
| if os.path.exists(config_file): |
| with open(config_file, "r", encoding="utf-8") as f: |
| config = f.read() |
|
|
| yield idx, { |
| "problem_id": category, |
| "category": "research", |
| "statement": statement, |
| "config": config, |
| } |
| idx += 1 |
| else: |
| |
| for subproblem in sorted(os.listdir(category_dir)): |
| subproblem_dir = os.path.join(category_dir, subproblem) |
| if not os.path.isdir(subproblem_dir): |
| continue |
|
|
| readme_file = os.path.join(subproblem_dir, "readme") |
| config_file = os.path.join(subproblem_dir, "config.yaml") |
|
|
| statement = "" |
| config = "" |
|
|
| if os.path.exists(readme_file): |
| with open(readme_file, "r", encoding="utf-8") as f: |
| statement = f.read() |
|
|
| if os.path.exists(config_file): |
| with open(config_file, "r", encoding="utf-8") as f: |
| config = f.read() |
|
|
| if statement or config: |
| yield idx, { |
| "problem_id": f"{category}/{subproblem}", |
| "category": "research", |
| "statement": statement, |
| "config": config, |
| } |
| idx += 1 |
|
|