{"record":{"id":"5e405048a41509d0","repo":"microsoft/qlib","slug":"invalid-memory-mode-self-memory-mode","errorCode":null,"errorMessage":"invalid memory_mode `{self.memory_mode}`","messagePattern":"invalid memory_mode `(.+?)`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/data/dataset.py","lineNumber":206,"sourceCode":"            assert self._data.shape[1] % self.input_size == 0, \"data mismatch, please check `input_size`\"\n\n        # create batch slices\n        self._batch_slices = _create_ts_slices(self._index, self.seq_len)\n\n        # create daily slices\n        daily_slices = {date: [] for date in sorted(self._index.unique(level=1))}  # sorted by date\n        for i, (code, date) in enumerate(self._index):\n            daily_slices[date].append(self._batch_slices[i])\n        self._daily_slices = np.array(list(daily_slices.values()), dtype=\"object\")\n        self._daily_index = pd.Series(list(daily_slices.keys()))  # index is the original date index\n\n        # add memory (sample wise and daily)\n        if self.memory_mode == \"sample\":\n            self._memory = np.zeros((len(self._data), self.num_states), dtype=np.float32)\n        elif self.memory_mode == \"daily\":\n            self._memory = np.zeros((len(self._daily_index), self.num_states), dtype=np.float32)\n        else:\n            raise ValueError(f\"invalid memory_mode `{self.memory_mode}`\")\n\n        # padding tensor\n        self._zeros = np.zeros((self.seq_len, max(self.num_states, self._data.shape[1])), dtype=np.float32)\n\n    def _prepare_seg(self, slc, **kwargs):\n        fn = _get_date_parse_fn(self._index[0][1])\n        if isinstance(slc, slice):\n            start, stop = slc.start, slc.stop\n        elif isinstance(slc, (list, tuple)):\n            start, stop = slc\n        else:\n            raise NotImplementedError(f\"This type of input is not supported\")\n        start_date = pd.Timestamp(fn(start))\n        end_date = pd.Timestamp(fn(stop))\n        obj = copy.copy(self)  # shallow copy\n        # NOTE: Seriable will disable copy `self._data` so we manually assign them here\n        obj._data = self._data  # reference (no copy)\n        obj._label = self._label","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/data/dataset.py#L188-L224","documentation":"The reinforcement-learning dataset in qlib/contrib/data/dataset.py allocates an internal state-memory tensor sized either per sample ('sample') or per trading day ('daily'). memory_mode must be exactly one of these two strings; anything else raises ValueError at dataset construction, after batch slicing is set up.","triggerScenarios":"Constructing the RL dataset (e.g. MTSDataset/DataLoaderRL-family classes) with memory_mode unset (None) or misspelled ('samples', 'per_day', 'Sample'), or with num_states>0 but an invalid memory_mode string.","commonSituations":"Copy-pasted RL workflow YAML with a renamed field; refactoring that passes None as a placeholder; users assuming memory_mode is optional when num_states>0.","solutions":["Set memory_mode='sample' or memory_mode='daily' explicitly.","If you truly need no state memory, configure the dataset with num_states=0 — then no memory block is allocated and the mode is irrelevant.","Validate the value at config-load time and fail with a clear message listing the allowed values."],"exampleFix":"# before\nds = RLDataSet(data, seq_len=20, num_states=4, memory_mode=None)  # -> ValueError\n# after\nds = RLDataSet(data, seq_len=20, num_states=4, memory_mode='sample')  # or 'daily'","handlingStrategy":"validation","validationCode":"SUPPORTED_MEM = ('sample', 'daily')\nassert memory_mode in SUPPORTED_MEM, f'memory_mode must be one of {SUPPORTED_MEM}, got {memory_mode!r}'","typeGuard":"def is_valid_memory_mode(m) -> bool:\n    return m in ('sample', 'daily')","tryCatchPattern":null,"preventionTips":["Set memory_mode explicitly whenever num_states > 0.","Validate RL dataset config enums once at config-load time."],"tags":["qlib","reinforcement-learning","dataset","config"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}