class_docstr: A task that asks the model to induce an unknown polynomial at a point given a set of function evaluations.
  Unlike pre-existing tasks testing arithmetic, this task attempts to test a deeper notion of numeracy
  which the model cannot rely purely on rote memorization of standard tables of arithmetic operations
  in order to succeed on and which intuitively occurs as a implicit subroutine in broader contexts.
  
  Decomposes into 4 function classes:
  - linear                    (1 degree,  1 variable)
  - parabola                  (2 degrees, 2 variables)
  - plane                     (1 degree,  2 variables)
  - (elliptic) paraboloid    (2 degrees, 2 variables)
  
      with coefficients drawn from restricted ranges
      (see dict `RELTYPE_INFO`), and
      where {parabola, paraboloid} have nonnegative domains,
      ie. the right ray of the x-axis or upper-right
      quadrant of the plane resp. so that the model cannot
      rely on symmetry.
  
  and independently 2 + 1 modes:
  - standard
      - A single dataset corresponding to the same polynomial.
      Evaluate on different points.
  - function
      - Multiple datasets, where each dataset instance corresponds to
      an independently sampled polynomial belonging to the same class.
      Evaluate on different (dataset, point) pairs.
  and
  - example
      - A single dataset corresponding to the same fixed representative for each class.
  
  If `overlap` is `True`:
      Train and test datapoints are drawn from the same rectilinear region
      centered at the origin (see function `select_ranges`),
      making sure to exclude the training set from the test set.
  Otherwise:
      Train datapoints are drawn from a rectilinear border region while
      test datapoints are drawn from a disjoint rectilinear interior region,
      centered at the origin (see function `select_ranges`).
  
  Example prompt for `relation_type=parabola,mode=function` with `num_function_train=num_function_test=num_train=2`:
      x,y
      1,4
      -1,2
      0,2
  
      x,y
      -1,0
      1,20
      0,8
  
      x,y
      -1,7
      1,11
      0,
class_docstr_tok: ["A","task","that","asks","the","model","to","induce","an","unknown","polynomial","at","a","point","given","a","set","of","function","evaluations",".","Unlike","pre-existing","tasks","testing","arithmetic",",","this","task","attempts","to","test","a","deeper","notion","of","numeracy","which","the","model","can","not","rely","purely","on","rote","memorization","of","standard","tables","of","arithmetic","operations","in","order","to","succeed","on","and","which","intuitively","occurs","as","a","implicit","subroutine","in","broader","contexts",".","Decomposes","into","4","function","classes",":","-","linear","(","1","degree",",","1","variable",")","-","parabola","(","2","degrees",",","2","variables",")","-","plane","(","1","degree",",","2","variables",")","-","(","elliptic",")","paraboloid","(","2","degrees",",","2","variables",")","with","coefficients","drawn","from","restricted","ranges","(","see","dict","`","RELTYPE_INFO","`",")",",","and","where","{","parabola",",","paraboloid","}","have","nonnegative","domains",",","ie",".","the","right","ray","of","the","x-axis","or","upper-right","quadrant","of","the","plane","resp",".","so","that","the","model","can","not","rely","on","symmetry",".","and","independently","2","+","1","modes",":","-","standard","-","A","single","dataset","corresponding","to","the","same","polynomial",".","Evaluate","on","different","points",".","-","function","-","Multiple","datasets",",","where","each","dataset","instance","corresponds","to","an","independently","sampled","polynomial","belonging","to","the","same","class",".","Evaluate","on","different","(","dataset",",","point",")","pairs",".","and","-","example","-","A","single","dataset","corresponding","to","the","same","fixed","representative","for","each","class",".","If","`","overlap","`","is","`","True","`",":","Train","and","test","datapoints","are","drawn","from","the","same","rectilinear","region","centered","at","the","origin","(","see","function","`","select_ranges","`",")",",","making","sure","to","exclude","the","training","set","from","the","test","set",".","Otherwise",":","Train","datapoints","are","drawn","from","a","rectilinear","border","region","while","test","datapoints","are","drawn","from","a","disjoint","rectilinear","interior","region",",","centered","at","the","origin","(","see","function","`","select_ranges","`",")",".","Example","prompt","for","`","relation_type=parabola",",","mode=function","`","with","`","num_function_train=num_function_test=num_train=2","`",":","x",",","y","1,4","-1,2","0,2","x",",","y","-1,0","1,20","0,8","x",",","y","-1,7","1,11","0",","]
code: def get_instances(self) -> List[Instance]:
      assert self.random_seed is not None
      random.seed(self.random_seed)
      np.random.seed(self.random_seed)
  
      train_range, test_range = select_ranges(
          num_train=100,
          num_test=100,
          dim=self.num_variables,  # not a typo
          overlap=self.overlap,
          nonnegative_only=self.relation_type
          in ["parabola", "paraboloid"],
      )
      #               train_range = test_range:
      #               -------------------------
      # linear:       [(-100, 100)]
      # parabola:     [(0, 200)]
      # plane:        [(-10, 10), (-10, 10)]
      # paraboloid:   [(0, 20), (0, 20)]
  
      test_vals = list(
          product(*[range(r[0], r[1] + 1) for r in test_range])
      )
      if self.overlap:
          train_vals = test_vals
      else:
          train_vals = list(
              set(
                  product(*[range(r[0], r[1] + 1) for r in train_range])
              )
              - set(test_vals)
          )
      if self.sort_vals:
          train_vals = list(sorted(train_vals))
      if self.num_variables == 2:
          test_vals = list(filter(lambda _: _[0] <= _[1], test_vals))
          train_vals = list(filter(lambda _: _[0] <= _[1], train_vals))
  
      def generate_datapoint(
          rel: Polynomial, vals: List[int]
      ) -> Tuple[List[str], str]:
          y = rel.eval(vals)
          return list(map(str, vals)), str(y)
  
      def generate_datapoint_instances_for_split(
          rel, idxs, eval_vals, split
      ):
          instances = []
          for idx in idxs:
              vals = eval_vals[idx]
              str_vals, y = generate_datapoint(rel, vals)
              input = self.delimiter.join(str_vals)
              output = y
              var = get_var(self.dim)
              solution = f"{var} = {rel}"
              references = [
                  Reference(Output(text=output), tags=[CORRECT_TAG]),
                  Reference(Output(text=solution), tags=[SOLUTION_TAG]),
                  Reference(
                      Output(text=self.relation_type), tags=[CLASS_TAG]
                  ),
              ]
              instance = Instance(
                  Input(text=input), references=references, split=split
              )
              instances.append(instance)
          return instances
  
      def generate_datapoint_instances(rel: Polynomial):
          train_idxs = list(
              np.random.choice(
                  range(len(train_vals)), self.num_train, replace=False
              )
          )
          if self.sort_vals:
              train_idxs = list(sorted(train_idxs))
          if self.overlap:
              all_test_idxs = list(
                  set(range(len(test_vals))) - set(train_idxs)
              )
          else:
              all_test_idxs = list(range(len(test_vals)))
          test_idxs = np.random.choice(
              all_test_idxs, self.num_test, replace=False
          )
  
          train_instances = generate_datapoint_instances_for_split(
              rel, train_idxs, train_vals, TRAIN_SPLIT
          )
          test_instances = generate_datapoint_instances_for_split(
              rel, test_idxs, test_vals, TEST_SPLIT
          )
          instances = train_instances + test_instances
          return instances
  
      def generate_dataset():
          generate_func = globals()[f"generate_{self.relation_type}"]
          rel = generate_func(self.range_coeffs)
          instances = generate_datapoint_instances(rel)
          return instances
  
      def generate_datasets(num_instances: int, split: str):
          # TODO: construct_prompt is no longer part of adapter, and this function needs to be rewritten
          #       https://github.com/stanford-crfm/benchmarking/issues/569
          return []
          # spec = get_numeracy_adapter_spec(self.num_train, self.num_test, self.dim, self.delimiter)
          # service = get_test_tokenizer_service()
          # adapter = Adapter(spec, service)
          # outer_spec = get_numeracy_adapter_spec(
          #    self.num_train,
          #    self.num_test,
          #    self.dim,
          #    instructions="",
          #    instance_prefix="\n\n",
          #    delimiter=self.delimiter,
          # )
          # outer_adapter = Adapter(outer_spec, service)
          # instances = []
          # for idx in range(num_instances):
          #    datapoint_instances = generate_dataset()
          #    train_instances = datapoint_instances[: self.num_train]
          #    eval_instances = datapoint_instances[self.num_train :]
          #    dataset_instances = []
          #    for idx in range(self.num_test):
          #        eval_instance = eval_instances[idx]
          #        input = adapter.construct_prompt(
          #            train_instances, eval_instance, include_output=False, reference_index=None
          #        ).text
          #        input = input[: -len(spec.output_prefix.rstrip())]  # strip output_prefix
          #        references = eval_instance.references
          #        dataset_instance = Instance(input=input, references=references, split=split)  # split doesn't matter
          #        dataset_instances.append(dataset_instance)
  
          #    input = outer_adapter.construct_prompt(
          #        dataset_instances[:-1], dataset_instances[-1], include_output=False, reference_index=None
          #    ).text
          #    input = input[: -len(spec.output_prefix.rstrip())]  # strip output_prefix
          #    references = dataset_instances[-1].references
          #    instance = Instance(input=input, references=references, split=split)
          #    instances.append(instance)
  
          # return instances
  
      def generate_instances():
          generate_func = globals()[f"generate_{self.relation_type}"]
          if self.mode == "example":
              coeffs = RELTYPE_INFO[self.relation_type].example_coeffs
              rel = Polynomial(self.degree, self.num_variables, coeffs)
              return generate_datapoint_instances(rel)
          if self.mode == "standard":
              rel = generate_func(self.range_coeffs)
              return generate_datapoint_instances(rel)
          if self.mode == "function":
              return generate_datasets(
                  self.num_function_train, TRAIN_SPLIT
              ) + generate_datasets(self.num_function_test, TEST_SPLIT)
  
      return generate_instances()
  
imports: from collections import defaultdict
  from dataclasses import dataclass, field
  from itertools import combinations_with_replacement, product
  import math
  from math import comb
  import numpy
  import numpy.typing
  import random
  import sympy
  from sympy import Symbol, Poly, diff
  from sympy.parsing.sympy_parser import standard_transformations, implicit_multiplication_application
  from typing import List, Optional, Tuple, Dict
  from helm.benchmark.adaptation.adapters.adapter_factory import ADAPT_GENERATION
  from helm.benchmark.adaptation.adapter_spec import AdapterSpec
  from helm.benchmark.window_services.tokenizer_service import TokenizerService
  from helm.common.authentication import Authentication
  from helm.proxy.services.server_service import ServerService
  from .scenario import Scenario, Instance, Reference, TRAIN_SPLIT, TEST_SPLIT, CORRECT_TAG, Input, Output
label_desc: Use image node_id 2 for calling the NumeracyScenario obj's underlying member method code with example usage: obj.get_instances() and returns: generate_instances, list,  str, instances, instances, instances, list, generate_datapoint_instances, generate_datapoint_instances, unknown