code: def generate_artificial_tuplets(
      dataset_name: str,
      context_length: int,
      support_length: int,
      prediction_length: int,
      support_set_size: int,
      item_id: int,
  ) -> Tuple:
      if dataset_name == "marker":
          noise_level = 0.01
          context = np.random.normal(0, noise_level, context_length)
          signal_type = random.choice([-1, 1])
          target = signal_type * np.arange(0, 1, 1 / prediction_length)
          query = np.concatenate((context, target))
  
          # support time series without the marker
          support_set = list(
              np.random.normal(0, noise_level, context_length)
              for _ in range(support_set_size - 1)
          )
          # build support time series which contains the marker
          marker = (
              (-1)
              * signal_type
              * np.concatenate(
                  (
                      np.arange(0, 1, 1 / 6),
                      np.flip(np.arange(0, 1, 1 / 6)),
                  )
              )
          )
          marker_start = np.random.choice(
              np.arange(0, context_length - len(marker))
          )
          support_ts = np.random.normal(0, noise_level, context_length)
          support_ts[
              marker_start : marker_start + len(marker)
          ] += marker
          # insert at random position in support set
          support_set.insert(
              np.random.choice(support_set_size), support_ts
          )
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
  
      if dataset_name == "marker_v2":
          noise_level = 0.01
          context = np.random.normal(0, noise_level, context_length)
          signal_type = random.choice([-1, 1])
          target = signal_type * np.arange(0, 1, 1 / prediction_length)
          query = np.concatenate((context, target))
  
          # support time series without the marker
          support_set = list(
              np.random.normal(0, noise_level, context_length)
              for _ in range(support_set_size - 1)
          )
          # build support time series which contains the marker
          ramp = np.arange(0, 1, 1 / 6)
          if signal_type == -1:
              marker = np.concatenate((ramp, np.flip(ramp)))
          else:
              marker = np.concatenate(
                  (ramp, np.array([1, 0.8, 1]), np.flip(ramp))
              )
          marker_start = np.random.choice(
              np.arange(0, context_length - len(marker))
          )
          support_ts = np.random.normal(0, noise_level, context_length)
          support_ts[
              marker_start : marker_start + len(marker)
          ] += marker
          # insert at random position in support set
          support_set.insert(
              np.random.choice(support_set_size), support_ts
          )
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "marker_v3":
          noise_level = 0.01
          context = np.random.normal(0, noise_level, context_length)
          signal_type = random.choice([-1, 0, 1])
          target = signal_type * np.arange(0, 1, 1 / prediction_length)
          query = np.concatenate((context, target))
  
          # support time series without the marker
          support_set = list(
              np.random.normal(0, noise_level, context_length)
              for _ in range(support_set_size - 1)
          )
          # build support time series which contains the marker
          ramp = np.arange(0, 1, 1 / 6)
          if signal_type == -1:
              marker = np.concatenate((ramp, np.flip(ramp)))
          elif signal_type == 1:
              marker = np.concatenate(
                  (ramp, np.array([1, 0.8, 1]), np.flip(ramp))
              )
          else:
              marker = np.concatenate(
                  (ramp, np.array([1, 1, 1, 1, 1]), np.flip(ramp))
              )
          marker_start = np.random.choice(
              np.arange(0, context_length - len(marker))
          )
          support_ts = np.random.normal(0, noise_level, context_length)
          support_ts[
              marker_start : marker_start + len(marker)
          ] += marker
          # insert at random position in support set
          support_set.insert(
              np.random.choice(support_set_size), support_ts
          )
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "marker_v4":
          noise_level = 0.01
          context = np.random.normal(0, noise_level, context_length)
          signal_type = random.choice([-1, 0, 1])
          target = signal_type * np.arange(0, 1, 1 / prediction_length)
          query = np.concatenate((context, target))
  
          # support time series without the marker
          support_set = list(
              np.random.normal(0, noise_level, context_length)
              for _ in range(support_set_size - 1)
          )
          # build support time series which contains the marker
          ramp = np.arange(0, 1, 1 / 3)
          if signal_type == -1:
              marker = np.concatenate((ramp, np.flip(ramp)))
          elif signal_type == 1:
              marker = np.concatenate(
                  (ramp, np.array([1, 0.8, 1]), np.flip(ramp))
              )
          else:
              marker = np.concatenate(
                  (ramp, np.array([1, 1, 1]), np.flip(ramp))
              )
          marker_start = np.random.choice(
              np.arange(0, context_length - len(marker))
          )
          support_ts = np.random.normal(0, noise_level, context_length)
          support_ts[
              marker_start : marker_start + len(marker)
          ] += marker
          # insert at random position in support set
          support_set.insert(
              np.random.choice(support_set_size), support_ts
          )
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "marker_v6":
          noise_level = 0.01
          context = np.random.normal(0, noise_level, context_length)
          signal_type = random.choice([-1, 0, 1])
          target = signal_type * np.arange(0, 1, 1 / prediction_length)
          query = np.concatenate((context, target))
  
          # support time series without the marker
          support_set = list(
              np.random.normal(0, noise_level, context_length)
              for _ in range(support_set_size - 1)
          )
          # build support time series which contains the marker
          markers = [4 * [0.2], [0, 0.2, 0.2, 0], [0, 0.15, 0.2, 0.25]]
          marker = markers[signal_type + 1]
          marker_start = np.random.choice(
              np.arange(0, context_length - len(marker))
          )
          support_ts = np.random.normal(0, noise_level, context_length)
          support_ts[marker_start : marker_start + len(marker)] = marker
          # insert at random position in support set
          support_set.insert(
              np.random.choice(support_set_size), support_ts
          )
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "cheat_random":
          context = np.random.normal(0, 0.001, context_length)
          target = np.random.normal(0, 0.1, prediction_length)
          query = np.concatenate((context, target))
          support_set = list(
              np.random.normal(0, 0.001, context_length)
              for _ in range(support_set_size)
          )
          si = np.random.choice(support_set_size)
          support_set[si][-prediction_length:] = query[
              -prediction_length:
          ]
          # insert at random position in support set
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "cheat_random_gp":
          kernel = 0.5 * RBF(
              length_scale=5.0, length_scale_bounds=(1e-1, 10.0)
          )
          gpr = GaussianProcessRegressor(
              kernel=kernel, random_state=item_id
          )
          query = gpr.sample_y(
              np.arange(prediction_length + context_length).reshape(
                  -1, 1
              ),
              1,
              random_state=item_id + np.random.randint(100000),
          ).squeeze()
  
          marker_length = prediction_length
  
          support_set = gpr.sample_y(
              np.arange(support_length).reshape(-1, 1),
              support_set_size,
              random_state=item_id + np.random.randint(100000),
          ).T
          signal_length = marker_length + prediction_length
          marker_start = np.random.choice(
              np.arange(0, support_length - signal_length)
          )
          si = np.random.choice(support_set_size)
          support_set[si][
              marker_start : marker_start + signal_length
          ] = query[-signal_length:]
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "cheat_random_gp_fitted":
          kernel = 0.5 * RBF(
              length_scale=5.0, length_scale_bounds=(1e-1, 10.0)
          )
          gpr = GaussianProcessRegressor(
              kernel=kernel, random_state=item_id
          )
          query = gpr.sample_y(
              np.arange(prediction_length + context_length).reshape(
                  -1, 1
              ),
              1,
              random_state=item_id + np.random.randint(100000),
          ).squeeze()
  
          marker_length = prediction_length
  
          support_set = gpr.sample_y(
              np.arange(context_length).reshape(-1, 1),
              support_set_size,
              random_state=item_id + np.random.randint(100000),
          ).T
          signal_length = marker_length + prediction_length
          marker_start = np.random.choice(
              np.arange(0, context_length - signal_length)
          )
          si = np.random.choice(support_set_size)
          x = np.arange(marker_start, marker_start + signal_length)
          gpr.fit(
              x.reshape(-1, 1), query[-signal_length:].reshape(-1, 1)
          )
          s_ts = gpr.sample_y(
              np.arange(context_length).reshape(-1, 1),
              1,
              random_state=item_id + np.random.randint(100000),
          )
          support_set[si] = s_ts.squeeze()
  
          # insert at random position in support set
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "cheat_random_gp_mix_marker":
          signal_type = random.choice(["gp", "marker"])
          kernel = 0.5 * RBF(
              length_scale=5.0, length_scale_bounds=(1e-1, 10.0)
          )
          gpr = GaussianProcessRegressor(
              kernel=kernel, random_state=item_id
          )
          query = gpr.sample_y(
              np.arange(prediction_length + context_length).reshape(
                  -1, 1
              ),
              1,
              random_state=item_id + np.random.randint(100000),
          ).squeeze()
          support_set = gpr.sample_y(
              np.arange(context_length).reshape(-1, 1),
              support_set_size,
              random_state=item_id + np.random.randint(100000),
          ).T
          if signal_type == "gp":
              marker_length = prediction_length
              signal_length = marker_length + prediction_length
              marker_start = np.random.choice(
                  np.arange(0, context_length - signal_length)
              )
              si = np.random.choice(support_set_size)
              support_set[si][
                  marker_start : marker_start + signal_length
              ] = query[-signal_length:]
          else:
              signal = np.concatenate(
                  (np.ones((4,)), query[-prediction_length:])
              )
              signal_length = prediction_length + 4
              marker_start = np.random.choice(
                  np.arange(0, context_length - signal_length)
              )
              si = np.random.choice(support_set_size)
  
              support_set[si][
                  marker_start : marker_start + signal_length
              ] = signal
          # insert at random position in support set
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "cheat_random_gp_mix":
          signal_type = random.choices(
              ["gp", "marker"], weights=[0.5, 0.5], k=1
          )[0]
          kernel = 0.5 * RBF(
              length_scale=5.0, length_scale_bounds=(1e-1, 10.0)
          )
          gpr = GaussianProcessRegressor(
              kernel=kernel, random_state=item_id
          )
          query = gpr.sample_y(
              np.arange(prediction_length + context_length).reshape(
                  -1, 1
              ),
              1,
              random_state=item_id + np.random.randint(100000),
          ).squeeze()
          support_set = gpr.sample_y(
              np.arange(context_length).reshape(-1, 1),
              support_set_size,
              random_state=item_id + np.random.randint(100000),
          ).T
          if signal_type == "gp":
              marker_length = prediction_length
              signal_length = marker_length + prediction_length
              marker_start = np.random.choice(
                  np.arange(0, context_length - signal_length)
              )
              si = np.random.choice(support_set_size)
              support_set[si][
                  marker_start : marker_start + signal_length
              ] = query[-signal_length:]
          # else:
          #     signal = query[-prediction_length:]
          #     signal_length = prediction_length
          #     marker_start = np.random.choice(np.arange(0, context_length - signal_length))
          #     si = np.random.choice(support_set_size)
  
          #     support_set[si][marker_start : marker_start + signal_length] = signal
          # insert at random position in support set
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
      if dataset_name == "random_gp":
          kernel = 0.5 * RBF(
              length_scale=5.0, length_scale_bounds=(1e-1, 10.0)
          )
          gpr = GaussianProcessRegressor(
              kernel=kernel, random_state=item_id
          )
          query = gpr.sample_y(
              np.arange(prediction_length + context_length).reshape(
                  -1, 1
              ),
              1,
              random_state=item_id + np.random.randint(100000),
          ).squeeze()
  
          support_set = gpr.sample_y(
              np.arange(context_length).reshape(-1, 1),
              support_set_size,
              random_state=item_id + np.random.randint(100000),
          ).T
  
          q = {
              "target": query.tolist(),
              "item_id": item_id,
              "start": "2012-01-01 00:00:00",
          }
          s = [
              {
                  "target": s.tolist(),
                  "start": "2012-01-01 00:00:00",
                  "item_id": item_id,
              }
              for s in support_set
          ]
          return q, s
  
imports: from dataclasses import dataclass, asdict
  from typing import Optional, Literal, Tuple
  from pathlib import Path
  from tqdm.auto import tqdm
  import json
  import numpy
  import random
  import pytorch_lightning
  from gluonts.dataset.field_names import FieldName
  from gluonts.dataset.repository.datasets import get_dataset, materialize_dataset
  from torch.utils.data import DataLoader
  from sklearn.gaussian_process import GaussianProcessRegressor
  from sklearn.gaussian_process.kernels import RBF
  import warnings
  from meta.data.batch import TripletBatch
  from meta.datasets.splits import DatasetSplits
  from meta.data.sampling import TripletDataset
  from meta.datasets.registry import register_data_module
label_desc: Use image node_id 2 for calling a global function with example usage: generate_artificial_tuplets(dataset_name, context_length, support_length, prediction_length, support_set_size, item_id) and returns: q,  s, q,  s, q,  s, q,  s, q,  s, q,  s, q,  s, q,  s, q,  s, q,  s, q,  s