Skip to content

Chapter 7 script crashes on macOS (DataLoader workers + no main guard); mapie and scikit-learn missing from pyproject.toml #3

Description

@codetasks

Summary

Chapter_07/chapter07_conformal_prediction.py fails out of the box on macOS with RuntimeError: DataLoader worker (pid(s) ...) exited unexpectedly. There is also a small packaging gap: two imports the chapter needs are not declared in pyproject.toml. With the two fixes below the script runs end to end on macOS (Apple Silicon, Python 3.11, MPS) and prints sensible results (target coverage 90%, achieved 0.879).

Bug 1: DataLoader workers crash on macOS

Line 496 enables multiprocessing workers on every platform except Windows:

_num_workers = 0 if platform.system() == 'Windows' else min(os.cpu_count() or 1, 4)

The script has no if __name__ == "__main__": guard, and macOS uses the spawn start method. Each worker process therefore reimports the main module, which executes the whole script again (including trainer.fit), hits the freeze_support() error, and the workers die:

RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.
...
RuntimeError: DataLoader worker (pid(s) 19545) exited unexpectedly

Linux is unaffected because it forks. Suggested fix, mirroring the existing Windows special case (the dataset is tiny, so workers add nothing here):

_num_workers = 0 if platform.system() in ('Windows', 'Darwin') else min(os.cpu_count() or 1, 4)

Alternatively, wrap the executable code in a main guard, which also fixes any other chapter scripts with the same pattern.

Bug 2: mapie and scikit-learn not declared in pyproject.toml

The chapter imports sklearn (preprocessing, model selection, base estimator) and mapie (mapie.regression.TimeSeriesRegressor, mapie.subsample.BlockBootstrap), but neither appears in any dependency group in pyproject.toml. A fresh uv sync --group torch --group visualization cannot run the chapter. Suggested fix: add a conformal group (or extend an existing one):

conformal = [
    "mapie>=1.0,<2.0",
    "scikit-learn>=1.4,<2.0",
]

Note the script uses the MAPIE v1 API (confidence_level, TimeSeriesRegressor), so the bound should exclude 0.x, where the class is MapieTimeSeriesRegressor with alpha.

Environment

  • macOS (Apple Silicon), Python 3.11.14, deps resolved from the repo's uv.lock
  • Verified working after the two fixes: full run, exit 0, achieved coverage 0.879 vs 90% target, mean interval width 0.158 (scaled units)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions