Repository navigation
Closed
Labels
phaseEpic implementation phase
Description
🤖 Phase 5 designs and implements Python-native large-dataset storage semantics instead of porting MATLAB memory classes directly.
Summary
EEGLAB's @memmapdata, @mmo, and storedisk behavior are not stale for large EEG datasets, but a one-for-one MATLAB class port would be poor Python. This phase builds an explicit EEGPrep storage backend that preserves EEGLAB user semantics from GUI, pop_newset, ALLEEG, STUDY, and eegprep-console.
Scope
- Define and implement Python-native lazy/on-disk dataset storage for large EEG arrays where useful.
- Make
pop_newset,eeg_store,eeg_retrieve,EEGPrepSession, STUDY workflows, and save/load paths honest about memory residency. - Support sample and synthetic large-data tests without committing large files.
- Preserve EEGLAB-facing
storedisksemantics where they matter: saved flags, dataset retrieval, overwrite/new dataset, STUDY caches, and history. - Do not port MATLAB
@memmapdata/@mmomethods one-for-one unless a direct behavior is required.
Acceptance Criteria
- Users can work with large continuous/epoched datasets without surprising full-memory copies where the backend promises lazy storage.
- GUI and console always see the same dataset state.
- Save/load/retrieve/delete operations are deterministic and tested.
- Unsupported storage modes fail clearly instead of pretending data is unloaded.
- Performance tests or benchmarks demonstrate no obvious UI lockups for representative large arrays.
Required References
AGENTS.mdsrc/eegprep/eeglab/functions/@memmapdata/src/eegprep/eeglab/functions/@mmo/src/eegprep/functions/adminfunc/eeg_store.pysrc/eegprep/functions/adminfunc/eeg_retrieve.pysrc/eegprep/functions/guifunc/session.pysrc/eegprep/functions/popfunc/pop_newset.py.agents/skills/eegprep-feature-development/SKILL.md
/goal
/goal Implement EEGPrep's Python-native large-dataset storage and storedisk semantics for the final parity epic. Use EEGLAB memory classes as user-semantics references, not as one-for-one design, and build a maintainable backend that keeps EEG/ALLEEG/CURRENTSET/STUDY/eegprep-console synchronized. Verify with synthetic large-data integration tests, pop_newset/eeg_store/eeg_retrieve/save-load tests, GUI/console mixed workflows, performance smoke tests, ruff/format/ty, non-slow pytest, and pre-commit. Do not fake unloaded data or introduce hidden global state.
Metadata
Metadata
Assignees
Labels
phaseEpic implementation phase
Activity
claude commentedon Jun 7, 2026
🤖 Plan:
This is a phase-epic spanning storage, session, save/load, STUDY, and GUI/console — far above the 100-line cap. Posting design for human review instead of a PR.
Research
The
option_storedisk/option_memmapdataflags are declared ineeg_options.pybut no runtime path honors them:eeg_storealwaysdeepcopys the full dict,eeg_retrievereturns a deep copy,pop_savesetwrites one MAT file withdatainline, andpop_loadsetmaterializes the full array intoEEG["data"]. The vendoredsrc/eegprep/eeglab/tree is empty in CI, so any design must specify EEGPrep-native semantics rather than importing MATLAB class behavior at runtime. Thesavedfield is already wired through (justloaded/yes/no) andEEGPrepSessionalready centralizes ALLEEG/CURRENTSET/history mutations, so a backend swap can land without touching pop_* call sites ifEEG["data"]keeps a numpy-array-like interface.Relevant code
src/eegprep/functions/adminfunc/eeg_options.py#L15-L23—option_storedisk/option_memmapdataflags, currently unreadsrc/eegprep/functions/adminfunc/eeg_store.py#L40-L48— unconditionaldeepcopy, ignoresoption_storedisksrc/eegprep/functions/adminfunc/eeg_retrieve.py#L17-L21— unconditionaldeepcopyon retrievesrc/eegprep/functions/popfunc/pop_saveset.py#L332-L378— single.setMAT path, no.fdtsidecar branchsrc/eegprep/functions/guifunc/session.py#L153-L303—store_current/mark_current_saved/notify_changedchoke pointsrc/eegprep/functions/sigprocfunc/epoch.py#L58-L59— explicit TODO acknowledgingoption_memmapdatais unimplementedProposed Design
Goals (in priority order)
option_storedisk=1keep at most one EEG fully in memory; the rest live on disk and round-trip througheeg_retrieve/eeg_storewithout losingsaved/history/STUDY state.option_memmapdata=1exposeEEG["data"]as a numpy-compatible lazy array that pop_* functions can read likendarraywithout code changes for the read-only path.eegprep-consolecommands see identical residency state; the GUI never shows a dataset that the console thinks is unloaded..setfiles matches EEGLAB on disk: whenoption_savetwofiles=1(already declared, unimplemented) the float data goes to a.fdtsidecar and the.setMAT carriesdatfileinstead ofdata.numpy.memmapcovers the contiguous(nbchan, pnts[, trials])case;h5pyis already a dependency and covers the streaming/random-access case if needed for STUDY caches.Non-Goals
@memmapdata/@mmoMATLAB classes. Their public surface is method-dispatch wrappingmemmapfile; the Python equivalent isnumpy.memmapdirectly, and exposing it through a thin wrapper class is the only fidelity that matters.icaact) — out of scope; they are derived caches, not primary data.Architecture
Introduce
src/eegprep/functions/adminfunc/storage.pywith three concrete data-handle types and a single resolver:InMemoryData— wraps annp.ndarray; the current default; identity semantics unchanged.MemmapData— wrapsnumpy.memmapover an EEGLAB-shaped.fdt(column-major float32(nbchan, pnts*trials)). Implements__array__,__array_interface__,shape,dtype, slicing, and__getitem__so existing numpy consumers (data[:, :100],np.mean(data, axis=1), etc.) work unmodified.OffloadedData— placeholder that holds the.set/.fdtpath of an evicted dataset;EEG["data"]returns this whenoption_storedisk=1evicts a non-current set. Materializing requires going througheeg_retrieve, which lazily rehydrates from disk and updates thesavedflag (yesstaysyes;nois impossible because eviction requires saved state).EEG["data"]keeps duck-typing as a numpy array for read paths vianp.asarray(EEG["data"]). Pop_* functions that mutate data already assign a new array (EEG["data"] = ...), which transparently swaps the handle back toInMemoryData.Session and ALLEEG semantics
eeg_storelearns one new branch: whenoption_storedisk=1and the dataset being stored is not the current selection, and the existing ALLEEG entry hassaved == "yes"and a known on-disk path, replace itsdatawith anOffloadedDatahandle and drop the in-memory array.eeg_retrievemirrors this: if the retrieved dataset hasOffloadedData, callpop_loadsetto rehydrate, then re-store using normal in-memory rules.EEGPrepSession.store_currentis the single mutation point and already callsnotify_changed, so GUI/console refresh comes for free.Eviction is refused (not silently retained) when
saved != "yes": an explicitRuntimeError("Cannot evict unsaved dataset N; save it first."). This is the EEGLAB-equivalent of the "save before switching" prompt; the GUI dialog can catch it and reuse the existingpop_savesetflow.Save / load
pop_savesetgrows atwo_files: boolbranch keyed offoption_savetwofiles. When true, write the float data to<base>.fdtas column-major float32 and emitdatfile=<base>.fdtin the MAT instead ofdata.pop_loadsetgrows a symmetric branch: when the loaded MAT hasdatfileand nodata, mmap the sidecar withnumpy.memmap(dtype="<f4", shape=(nbchan, pnts*trials), order="F")and wrap inMemmapData. Existing single-file.setfiles keep working unchanged.pop_loadset_h5.pyis left alone — it is for HDF5-saved sessions, not the EEGLAB.fdtformat.STUDY caches
STUDY does not need a separate storage layer for Phase 5. STUDY entries reference datasets by
filename/filepath; withoption_storedisk=1the cache is implicit because only the current dataset is materialized. STUDY-level precomputed measures (spectra, ERSP) keep using whatever per-dataset cache already exists; flag explicitly in Phase 4/6 if a separate STUDY-cache eviction policy is needed.Tests
tests/test_storage.py(new): synthetic 64 ch x 60s float32 array; round-trippop_saveset(two_files=True)->pop_loadset-> assertMemmapDataandnp.allcloseagainst original.tests/test_eeg_store_storedisk.py(new): withoption_storedisk=1, store two sets, switch current, assert non-currentdataisOffloadedData, asserteeg_retrieverehydrates correctly, assert eviction withoutsaved=="yes"raises.tests/test_console_workspace.py(extend): after a GUI-level dataset switch underoption_storedisk=1, consoleALLEEG[1]["data"]is still numpy-array-readable (lazy) andEEGis the current set.tests/test_pop_saveset.py(extend): assertoption_savetwofiles=0keeps the legacy single-file layout (no behavioral regression).slowmarker): allocate a 256 ch x 600s synthetic float32, save, reload as memmap, assert resident memory grows by <50% of the dataset size duringpop_loadset(RSS check viapsutilif available, elsetracemalloc).No MATLAB parity gate is required since
@memmapdata/@mmoare not user-visible field types in the.setfile — onlydatavsdatfileis.Open Questions
EEG["data"]always expose the handle, or should pop_* writers see a rawndarray(forcing a.materialize()call before the first read)? Recommended: duck-typed handle. Lowest-friction path for the dozens of existingnp.asarray(EEG["data"])/ direct-slice sites..fdtas 2-D(nbchan, pnts*trials)column-major and reshapes on load. Confirm we want to preserve that on-disk layout (yes, recommended — round-trips with MATLAB EEGLAB) or switch to 3-D(nbchan, pnts, trials)C-order on disk (cleaner Python; breaks parity).option_storedisk=1; recommend matching that and deferring LRU..fdtsidecar is missing on load: hard error vs synthesize zeros vs prompt. Recommend hard error to match EEGLAB.pop_delsetto remove the.fdtalongside the.set? (Probably yes — short hook.)Rough Size Estimate
storage.py(new): ~180 lines (3 handle classes + resolver + numpy protocol glue).eeg_store.py/eeg_retrieve.py: ~30 lines added each for the offload/rehydrate branches.pop_saveset.py/pop_loadset.py: ~60 lines added each for the.fdtsidecar branches.EEGPrepSession: ~20 lines for theoption_storedisk-aware path throughstore_current.Total ~800 lines net new — confirming the "no PR, design comment first" call.
Requesting human review on the five open questions before any branch is cut.
suraj-ranganath commentedon Jun 7, 2026
🤖 Phase PR for this issue has merged into feature/eeglab-full-standalone-completion and integration checks are passing on the epic branch. Closing this phase issue as completed.