in evals/elsuite/identifying_variables/utils.py [0:0]
def parse_solver_preds(solver_result: SolverResult) -> Answer:
solver_string = solver_result.output.strip().lower()
pattern = (
r"\[@answer " # Matches the beginning of the answer
r"valid_hyp: (true|false|True|False)" # valid hyp part
r"(?:; independent: ([^;]*))?" # Optionally matches the independent part
r"(?:; dependent: ([^;]*))?" # Optionally matches the dependent part
r"(?:; control: ([^\]]*))?" # Optionally matches the control part
r"\]" # Matches the end of the answer
)
match = re.search(pattern, solver_string)
if match:
valid_hyp = match.group(1).lower() == "true"
if not valid_hyp:
return Answer(
valid_hypothesis=False,
ind_var=None,
dep_var=None,
ctrl_vars=None,
)
ind_var = match.group(2)
ind_var = ind_var if ind_var is not None else "WRONG"
dep_var = match.group(3)
dep_var = dep_var if dep_var is not None else "WRONG"
ctrl_vars = match.group(4)
if ctrl_vars is not None:
ctrl_vars = ctrl_vars.split(",")
ctrl_vars = [var.strip() for var in ctrl_vars]
if ctrl_vars[0].lower().strip("\"'`«»<>") == "none":
ctrl_vars = []
else:
ctrl_vars = ["WRONG"]
return Answer(
valid_hypothesis=True,
ind_var=ind_var,
dep_var=dep_var,
ctrl_vars=ctrl_vars,
)
else:
raise ValueError("Invalid solver output")