class_docstr: Base implementation of a Continual Learning benchmark instance.
  A Continual Learning benchmark instance is defined by a set of streams of
  experiences (batches or tasks depending on the terminology). Each
  experience contains the training (or test, or validation, ...) data that
  becomes available at a certain time instant.
  
  Experiences are usually defined in children classes, with this class
  serving as the more general implementation. This class handles the most
  simple type of assignment: each stream is defined as a list of experiences,
  each experience is defined by a dataset.
  
  Defining the "train" and "test" streams is mandatory. This class supports
  custom streams as well. Custom streams can be accessed by using the
  `streamname_stream` field of the created instance.
  
  The name of custom streams can only contain letters, numbers or the "_"
  character and must not start with a number.
docstr: Creates an instance of a Continual Learning benchmark instance.
  
  The benchmark instance is defined by a stream definition dictionary,
  which describes the content of each stream. The "train" and "test"
  stream are mandatory. Any other custom stream can be added.
  
  There is no constraint on the amount of experiences in each stream
  (excluding the case in which `complete_test_set_only` is set).
  
  :param stream_definitions: The stream definitions dictionary. Must
      be a dictionary where the key is the stream name and the value
      is the definition of that stream. "train" and "test" streams are
      mandatory. This class supports custom streams as well. The name of
      custom streams can only contain letters, numbers and the "_"
      character and must not start with a number. Streams can be defined
      is two ways: static and lazy. In the static case, the
      stream must be a tuple containing 1, 2 or 3 elements:
      - The first element must be a list containing the datasets
      describing each experience. Datasets must be instances of
      :class:`AvalancheDataset`.
      - The second element is optional and must be a list containing the
      task labels of each experience (as an int or a set of ints).
      If the stream definition tuple contains only one element (the list
      of datasets), then the task labels for each experience will be
      obtained by inspecting the content of the datasets.
      - The third element is optional and must be a reference to the
      originating dataset (if applicable). For instance, for SplitMNIST
      this may be a reference to the whole MNIST dataset. If the stream
      definition tuple contains less than 3 elements, then the reference
      to the original dataset will be set to None.
      In the lazy case, the stream must be defined as a tuple with 2
      elements:
      - The first element must be a tuple containing the dataset
          generator (one for each experience) and the number of
          experiences in that stream.
      - The second element must be a list containing the task labels of
          each experience (as an int or a set of ints).
  :param complete_test_set_only: If True, the test stream will contain
      a single experience containing the complete test set. This also
      means that the definition for the test stream must contain the
      definition for a single experience.
  :param stream_factory: A callable that, given the name of the
      stream and the benchmark instance, returns a stream instance.
      This parameter is usually used in subclasses (when
      invoking the super constructor) to specialize the experience class.
  :param experience_factory: A callable that, given the
      stream instance and the experience ID, returns an experience
      instance. This parameter is usually used in subclasses (when
      invoking the super constructor) to specialize the experience class.
code: def __init__(
      self: TDatasetScenario,
      *,
      stream_definitions: TStreamsUserDict,
      stream_factory: Callable[[str, TDatasetScenario], TCLStream],
      experience_factory: Callable[
          [TCLStream, int], TDatasetExperience
      ],
      complete_test_set_only: bool = False,
  ):
      """
      Creates an instance of a Continual Learning benchmark instance.
  
      The benchmark instance is defined by a stream definition dictionary,
      which describes the content of each stream. The "train" and "test"
      stream are mandatory. Any other custom stream can be added.
  
      There is no constraint on the amount of experiences in each stream
      (excluding the case in which `complete_test_set_only` is set).
  
      :param stream_definitions: The stream definitions dictionary. Must
          be a dictionary where the key is the stream name and the value
          is the definition of that stream. "train" and "test" streams are
          mandatory. This class supports custom streams as well. The name of
          custom streams can only contain letters, numbers and the "_"
          character and must not start with a number. Streams can be defined
          is two ways: static and lazy. In the static case, the
          stream must be a tuple containing 1, 2 or 3 elements:
          - The first element must be a list containing the datasets
          describing each experience. Datasets must be instances of
          :class:`AvalancheDataset`.
          - The second element is optional and must be a list containing the
          task labels of each experience (as an int or a set of ints).
          If the stream definition tuple contains only one element (the list
          of datasets), then the task labels for each experience will be
          obtained by inspecting the content of the datasets.
          - The third element is optional and must be a reference to the
          originating dataset (if applicable). For instance, for SplitMNIST
          this may be a reference to the whole MNIST dataset. If the stream
          definition tuple contains less than 3 elements, then the reference
          to the original dataset will be set to None.
          In the lazy case, the stream must be defined as a tuple with 2
          elements:
          - The first element must be a tuple containing the dataset
              generator (one for each experience) and the number of
              experiences in that stream.
          - The second element must be a list containing the task labels of
              each experience (as an int or a set of ints).
      :param complete_test_set_only: If True, the test stream will contain
          a single experience containing the complete test set. This also
          means that the definition for the test stream must contain the
          definition for a single experience.
      :param stream_factory: A callable that, given the name of the
          stream and the benchmark instance, returns a stream instance.
          This parameter is usually used in subclasses (when
          invoking the super constructor) to specialize the experience class.
      :param experience_factory: A callable that, given the
          stream instance and the experience ID, returns an experience
          instance. This parameter is usually used in subclasses (when
          invoking the super constructor) to specialize the experience class.
      """
  
      self.experience_factory: Callable[
          [TCLStream, int], TDatasetExperience
      ] = experience_factory
  
      self.stream_factory: Callable[
          [str, TDatasetScenario], TCLStream
      ] = stream_factory
  
      self.stream_definitions: Dict[
          str, StreamDef[TCLDataset]
      ] = DatasetScenario._check_stream_definitions(stream_definitions)
      """
          A structure containing the definition of the streams.
          """
  
      self.original_train_dataset: Optional[
          TOriginDataset
      ] = self.stream_definitions["train"].origin_dataset
      """ The original training set. May be None. """
  
      self.original_test_dataset: Optional[
          TOriginDataset
      ] = self.stream_definitions["test"].origin_dataset
      """ The original test set. May be None. """
  
      self.train_stream: TCLStream = self.stream_factory("train", self)
      """
          The stream used to obtain the training experiences. 
          This stream can be sliced in order to obtain a subset of this stream.
          """
  
      self.test_stream: TCLStream = self.stream_factory("test", self)
      """
          The stream used to obtain the test experiences. This stream can be 
          sliced in order to obtain a subset of this stream.
  
          Beware that, in certain scenarios, this stream may contain a single
          element. Check the ``complete_test_set_only`` field for more details.
          """
  
      self.complete_test_set_only: bool = bool(complete_test_set_only)
      """
          If True, only the complete test set will be returned from experience
          instances.
  
          This flag is usually set to True in scenarios where having one separate
          test set aligned to each training experience is impossible or doesn't
          make sense from a semantic point of view.
          """
  
      if self.complete_test_set_only:
          if len(self.stream_definitions["test"].exps_data) > 1:
              raise ValueError(
                  "complete_test_set_only is True, but the test stream"
                  " contains more than one experience"
              )
  
      # Create the original_<stream_name>_dataset fields for other streams
      self._make_original_dataset_fields()
  
      # Create the <stream_name>_stream fields for other streams
      self._make_stream_fields()
  
      super().__init__(
          [
              getattr(self, f"{stream_name}_stream")
              for stream_name in self.stream_definitions.keys()
          ]
      )
  
imports: from abc import ABC, abstractmethod
  from dataclasses import dataclass
  import re
  from typing import Generic, TypeVar, Union, Sequence, Callable, Optional, Dict, Any, Iterable, List, Set, Tuple, Mapping, TYPE_CHECKING
  from .None import DatasetExperience
  from ..generic_scenario import CLScenario, CLExperience, CLStream, SequenceCLStream
  from .lazy_dataset_sequence import LazyDatasetSequence
  from avalanche.benchmarks.utils import AvalancheDataset
  from torch.utils.data.dataset import Dataset
label_desc: Use image node_id 1 to create a new DatasetScenario object from inherited base classes: CLScenario, Generic with example: obj = DatasetScenario()