nbaldwin's picture
first version FunSearch
97e363b
#default configuration of your flow (if needed) goes here
_target_: flow_modules.aiflows.FunSearchFlowModule.ProgramDBFlow.instantiate_from_default_config
input_interface:
- "operation"
output_interface:
- "retrieved"
name: ProgramDBFlow
description: A flow that saves programs in a database of islands
artifact_to_evolve_name: solve_function
evaluate_function: |2-
def evaluate(solve_function: str, tests_inputs: List[str], expected_outputs: str) -> float:\n """Returns the score of the solve function we\'re evolving based on the tests_inputs and expected_outputs.\n Scores are between 0 and 1, unless the program fails to run, in which case the score is -1.\n """\n if solve(solve_function, tests_inputs, expected_outputs) == True:\n return 1.0\n return 0.0
evaluate_file_full_content: |2-
"""Problem Description:\nServal has a string s that only consists of 0 and 1 of length n. The i-th character of s is denoted as s_i, where 1\\leq i\\leq n.\nServal can perform the following operation called Inversion Magic on the string s:\nChoose an segment [l, r] (1\\leq l\\leq r\\leq n). For l\\leq i\\leq r, change s_i into 1 if s_i is 0, and change s_i into 0 if s_i is 1.\nFor example, let s be 010100 and the segment [2,5] is chosen. The string s will be 001010 after performing the Inversion Magic.\nServal wants to make s a palindrome after performing Inversion Magic exactly once. Help him to determine whether it is possible.\nA string is a palindrome iff it reads the same backwards as forwards. For example, 010010 is a palindrome but 10111 is not.\n\nInput Description:\nInput\nEach test contains multiple test cases. The first line contains the number of test cases t (1\\leq t\\leq 10^4). The description of the test cases follows.\nThe first line of each test case contains a single integer n (2\\leq n\\leq 10^5) — the length of string s.\nThe second line of each test case contains a binary string s of length n. Only characters 0 and 1 can appear in s.\nIt\'s guaranteed that the sum of n over all test cases does not exceed 2\\cdot 10^5.\n\nOutput Description:\nOutput\nFor each test case, print Yes if s can be a palindrome after performing Inversion Magic exactly once, and print No if not.\nYou can output Yes and No in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).\n\nPublic Tests:\nTest 1:\n Input: [\'1\', \'4\', \'1001\']\n Output: \'YES\'\nTest 2:\n Input: [\'1\', \'5\', \'10010\']\n Output: \'YES\'\nTest 3:\n Input: [\'1\', \'7\', \'0111011\']\n Output: \'NO\'\n\n"""\n\n\nimport ast\nimport itertools\nimport numpy as np\nfrom typing import List\n\ndef solve(solve_function: str,input: List[str], expected_output: str) -> str:\n """function used to run the solve function on input *kwargs and return the the predicted output\n \n :param solve_function: the function to run (the solve function below as a string)\n :type solve_function: str\n :param kwargs: the inputs to the solve function\n :type kwargs: List[str]\n """\n local_namespace = {}\n exec(solve_function,local_namespace)\n found_name, program_name = get_function_name_from_code(solve_function)\n \n if not found_name:\n raise ValueError(f"Function name not found in program: {solve_function}")\n \n solve_fn = local_namespace.get(program_name)\n \n prediction = solve_fn(input)\n \n prediction = prediction.split()\n expected_output = expected_output.split()\n \n if len(prediction) != len(expected_output):\n raise ValueError(f"Invalid Format of prediction")\n \n for i in range(len(prediction)):\n if prediction[i] != expected_output[i]:\n return False\n \n return True\n\ndef evaluate(solve_function: str, tests_inputs: List[str], expected_outputs: str) -> float:\n """Returns the score of the solve function we\'re evolving based on the tests_inputs and expected_outputs.\n Scores are between 0 and 1, unless the program fails to run, in which case the score is -1.\n """\n if solve(solve_function,tests_inputs,expected_outputs) == True:\n return 1.0\n return 0.0\n\n\ndef get_function_name_from_code(code):\n tree = ast.parse(code)\n for node in ast.walk(tree):\n if isinstance(node, ast.FunctionDef):\n return True, node.name\n\n # something is wrong\n return False, None\n\n\n\n\n \n
num_islands: 3
reset_period : 14400 #4 hours in seconds
artifacts_per_prompt: 2
temperature: 0.1
temperature_period: 30000
sample_with_replacement: False
portion_of_islands_to_reset: 0.5
template:
preface: ""