SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.20881 · ICLR · 2025

Generalizable Heuristic Generation Through LLMs with Meta-Optimization

Jie Zhang, Zhiguang Cao, Wen Song, Jieyi Bi, Jianan Zhou, Yaoxin Wu, Yiding Shi, Meta - Optimizer, Heuristic -Optimizer, M Heuristic- Optimizer

arXiv · PDF · Open in the Atlas

Code that ran

9 of 13 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 6 failures of our instrument; 4 no recorded run), measured 2026-11-24; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2505.20881.json · badge: /api/ran/2505.20881.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
yiding-s/MoH community
Papers with Code archive
9 ran · 4 no recorded run
FunctionStatusWhere it lives
BaseClient Ran
ran on a synthesized input · constructed an object; no result was computed
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("6bbb074549eb8d0a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, BaseClient: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import logging
from typing import Optional
import json
import time
from datetime import datetime
import concurrent.futures
from random import random
from unittest.mock import Mock, MagicMock

logger = logging.getLogger(__name__)

class BaseClient:

    def __init__(self, model: str, temperature: float=1.0, batch_size: int=5, cache_dir: Optional[str]=None) -> None:
        self.model = model
        self.temperature = temperature
        self.batch_size = batch_size
        self.cache_dir = cache_dir
        self._call_counter = 0
        if cache_dir:
            os.makedirs(cache_dir, exist_ok=True)

    def _chat_completion_api(self, messages: list[dict], temperature: float, n: int=1):
        raise NotImplementedError

    def _single_call(self, messages: list[dict], temperature: float) -> str:
        """Single API call with retry, returns content string."""
        time.sleep(random() * 0.5)
        for attempt in range(10):
            try:
                choices = self._chat_completion_api(messages, temperature, n=1)
                return choices[0].message.content.strip()
            except Exception as e:
                logger.warning(f'Attempt {attempt + 1} failed: {e}')
                time.sleep(min(2 ** attempt, 30))
        logger.error('All retry attempts exhausted')
        return 'Error: API call failed after retries'

    def _log_to_cache(self, messages: list[dict], temperature: float, response: str):
        if not self.cache_dir:
            return
        self._call_counter += 1
        record = {'id': self._call_counter, 'timestamp': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'model': self.model, 'temperature': temperature, 'messages': messages, 'response': response}
        ts = datetime.now().strftime('%Y%m%d_%H%M%S')
        filename = f'{ts}_{self._call_counter:04d}.json'
        path = os.path.join(self.cache_dir, filename)
        with open(path, 'w') as f:
            json.dump(record, f, ensure_ascii=False, indent=2)

    def prompt(self, expertise: str, message: str, temperature: Optional[float]=None) -> str:
        """
        Single prompt call
        Args:
            expertise: system role content
            message: user message content
            temperature: sampling temperature (defaults to self.temperature)
        """
        temperature = temperature or self.temperature
        messages = [{'role': 'system', 'content': expertise}, {'role': 'user', 'content': message}]
        response = self._single_call(messages, temperature)
        self._log_to_cache(messages, temperature, response)
        return response

    def prompt_batch(self, expertise: str, message_batch: list[str], temperature: Optional[float]=None) -> list[str]:
        """
        Parallel batch prompt call.
        Args:
            expertise: system role content (shared across batch)
            message_batch: list of user messages
            temperature: sampling temperature (defaults to self.temperature)
        """
        temperature = temperature or self.temperature
        with concurrent.futures.ThreadPoolExecutor(max_workers=len(message_batch)) as executor:
            futures = {executor.submit(self.prompt, expertise, msg, temperature): i for i, msg in enumerate(message_batch)}
            results = [None] * len(message_batch)
            for future in concurrent.futures.as_completed(futures):
                idx = futures[future]
                results[idx] = future.result()
        return results


ARGS = {
    'model': 'gpt-3.5-turbo',
    'temperature': 0.7,
    'batch_size': 5,
    'cache_dir': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type BaseClient — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a BaseClient output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Pop Ran
ran on a synthesized input · constructed an object; no result was computed
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("91a30e2df0db4521")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Pop: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import logging
import numpy as np
import json
import re
import heapq

# Set up logging
logging.basicConfig(level=logging.DEBUG)

# Define ARGS for the Pop class constructor
ARGS = {
    'name_list': ['task1', 'task2', 'meta-optimizer'],
    'size': 5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Pop — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Pop output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
clean_code Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("7bb761fcfadb6e28")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def code_only(code_string):
    """Remove # comments and redundant blank lines."""
    code_without_comments = re.sub('#.*', '', code_string)
    cleaned_code = re.sub('\\n\\s*\\n', '\n', code_without_comments)
    return cleaned_code.strip()

def clean_code(algorithm_str):
    if isinstance(algorithm_str, str):
        return code_only(algorithm_str)
    elif isinstance(algorithm_str, list):
        return [code_only(s) for s in algorithm_str]

# Test with a string input
test_string = """
x = 5  # this is a comment
y = 10


z = x + y  # another comment
"""

# Test with a list input
test_list = [
    "a = 1  # comment",
    "b = 2\n\n\nc = 3  # another",
    "def foo():\n    pass  # do nothing"
]

ARGS = {
    "algorithm_str": test_string
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
code_only Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("8a5a672d8056c8eb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def code_only(code_string):
    """Remove # comments and redundant blank lines."""
    code_without_comments = re.sub('#.*', '', code_string)
    cleaned_code = re.sub('\\n\\s*\\n', '\n', code_without_comments)
    return cleaned_code.strip()


# Construct valid arguments
code_string = """
def hello():
    # This is a comment
    x = 5
    
    
    y = 10  # Another comment
    return x + y
"""

ARGS = {
    "code_string": code_string
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
extract_idea Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("c4556869df45be56")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import re

def find_braces(response):
    """Extract content inside first {} pair."""
    match = re.search('\\{(.*?)\\}', response, re.DOTALL)
    if match:
        return match.group(1)
    if 'import' in response:
        return response.split('import')[0]
    return None

def extract_idea(algorithm_str):
    if isinstance(algorithm_str, str):
        return find_braces(algorithm_str)
    elif isinstance(algorithm_str, list):
        return [extract_idea(s) for s in algorithm_str]

# Test case 1: string with braces
test_string_with_braces = "some text {content inside braces} more text"

# Test case 2: string with import
test_string_with_import = "before import after"

# Test case 3: string with neither
test_string_plain = "just plain text"

# Test case 4: list of strings
test_list = [
    "algorithm {idea1}",
    "something import other",
    "plain string"
]

# Test case 5: nested list
test_nested_list = [
    ["{nested content}", "import statement"],
    "{top level}",
    "no match here"
]

ARGS = {
    "algorithm_str": test_list
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
find_braces Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("e0a5d1dfc846373b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def find_braces(response):
    """Extract content inside first {} pair."""
    match = re.search('\\{(.*?)\\}', response, re.DOTALL)
    if match:
        return match.group(1)
    if 'import' in response:
        return response.split('import')[0]
    return None

# Test case 1: response with braces
response_with_braces = "some text {content inside braces} more text"

# Test case 2: response with import statement
response_with_import = "some code here import sys\nmore code"

# Test case 3: response with neither
response_with_neither = "just plain text"

ARGS = {
    "response": response_with_braces
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
find_txt_block Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("d73d0729456794d7")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

# Setup code for find_txt_block function

ARGS = {
    "string": """Here is some content.
txt
This is inside a txt block
with multiple lines

More content after the block.
txt
Another txt block

Final content."""
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
match_number Ran
ran, honoured the contract we drafted
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("f5955b21dc0ea936")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re

def match_number(string):
    """Extract first integer from string, default 1."""
    match = re.search('\\d+', string)
    if match:
        try:
            return int(match.group())
        except ValueError:
            return 1
    return 1

ARGS = {
    "string": "abc123def456"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
read_file_as_str Ran
ran; our contract draft was wrong, not the code
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("6869ebaec683982d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import tempfile
import os

# Create a temporary file with some content
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as f:
    f.write("Hello, this is test file content.\nLine 2.\nLine 3.")
    temp_file_path = f.name

try:
    ARGS = {
        'path': temp_file_path
    }
finally:
    # Clean up will happen after ARGS is defined
    pass
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MoH Not yet run
unverified (harvested, no recorded run)
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("b10d5f52bf08e39a")
How it ran

no invocation recorded.

RunLogger Not yet run
unverified (harvested, no recorded run)
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("a64e631a6334c5e0")
How it ran

no invocation recorded.

extract_code Not yet run
unverified (harvested, no recorded run)
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("02ffbc411e44afd8")
How it ran

no invocation recorded.

find_largest_code_block_line_by_line Not yet run
unverified (harvested, no recorded run)
yiding-s/MoH/moh.py
code served (permissive licence) · get_code("f8269cf574311791")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 12 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
find_largest_code_block_line_by_line
brick of this paper's assembly: helper
1 other paper
1 dated earlier
2310.02304 (2023-10)
Self-Taught Optimizer (STOP): Recursively Self-Improving Code Generation

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Heuristic design with large language models (LLMs) has emerged as a promising approach for tackling combinatorial optimization problems (COPs). However, existing approaches often rely on manually predefined evolutionary computation (EC) heuristic-optimizers and single-task training schemes, which may constrain the exploration of diverse heuristic algorithms and hinder the generalization of the resulting heuristics. To address these issues, we propose Meta-Optimization of Heuristics (MoH), a novel framework that operates at the optimizer level, discovering effective heuristic-optimizers through the principle of meta-learning. Specifically, MoH leverages LLMs to iteratively refine a meta-optimizer that autonomously constructs diverse heuristic-optimizers through (self-)invocation, thereby eliminating the reliance on a predefined EC heuristic-optimizer. These constructed heuristicoptimizers subsequently evolve heuristics for downstream tasks, enabling broader heuristic exploration. Moreover, MoH employs a multi-task training scheme to promote its generalization capability. Experiments on classic COPs demonstrate that MoH constructs an effective and interpretable meta-optimizer, achieving stateof-the-art performance across various downstream tasks, particularly in cross-size settings. Our code is available at: https://github.com/yiding-s/MoH.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2505.20881")
get_code_for_paper("2505.20881")
have("2505.20881")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2505.20881.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2505.20881.svg)](https://syntology.ai/paper/2505.20881)

Connect an agent — have() is free.