Skip to content

MTN deterministic co_filename for dynamic code pickling - #560

Merged
ogrisel merged 25 commits into
cloudpipe:masterfrom
tomMoral:MTN_deterministic_co_filenames
Nov 5, 2025
Merged

ogrisel merged 25 commits into
cloudpipe:masterfrom
tomMoral:MTN_deterministic_co_filenames

Conversation

@tomMoral

@tomMoral tomMoral commented Mar 21, 2025 •

Copy link
Copy Markdown
Contributor

Set the co_filename to <dynamic-code> when pickling the code object to make the payload independent of where the code was defined.

TODO:

  • add test
  • add changelog

Fix #538

@codecov

codecov Bot commented Mar 26, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.35%. Comparing base (7576fff) to head (42caaae).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #560   +/-   ##
=======================================
  Coverage   96.34%   96.35%           
=======================================
  Files           3        3           
  Lines         575      576    +1     
  Branches      121      121           
=======================================
+ Hits          554      555    +1     
  Misses         11       11           
  Partials       10       10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea on how to debug the random failure but I found a typo...

Comment thread dev-requirements.txt Resolved
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
@tomMoral

Copy link
Copy Markdown
Contributor Author

The failure is deterministic and only happening on windows and on this branch (see #562 running from master and working).
Not sure how to debug either...

Comment thread tests/cloudpickle_test.py Resolved
@ogrisel

ogrisel commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

@tomMoral the bug seems to have disappeared with a more recent version of CPython 3.14 (and after sync with master.

@ogrisel

ogrisel commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

Let me trigger the CI another time.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the following, LGTM.

Comment thread tests/cloudpickle_ipykernel_test.py Resolved
Comment thread tests/cloudpickle_ipykernel_test.py Resolved
tomMoral and others added 3 commits November 4, 2025 14:18
@ogrisel

ogrisel commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Feel free to skip the new tests on pypy if they are too slow to run without triggering a timeout.

Comment thread tests/cloudpickle_ipykernel_test.py Resolved
@tomMoral

tomMoral commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

Ok I skipped the tests on Pypy to avoid making the CI longer for a test on a test utils.
Let me know if anything else is missing.

@ogrisel ogrisel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread cloudpickle/cloudpickle.py Resolved
@ogrisel
ogrisel merged commit f5199fe into cloudpipe:master Nov 5, 2025
@tomMoral
tomMoral deleted the MTN_deterministic_co_filenames branch November 5, 2025 11:08
meta-codesync Bot pushed a commit to meta-pytorch/monarch that referenced this pull request Nov 19, 2026
Summary:
Pull Request resolved: #5398

cloudpickle 3.1.3 (cloudpipe/cloudpickle#560, "deterministic co_filename for
dynamic code pickling") replaces `co_filename` with "<dynamic-code>" for every
function pickled by value. The debugger names frames with
`inspect.getmodulename(curframe.f_code.co_filename)` (pdb_wrapper.py), which is
`None` for that filename, so frames in pickled-by-value code show as
`None.<func>`. That fails `test_debug_with_pickle_by_value` in GitHub CI on main
since 3.1.3 was released (last green run installed 3.1.2, failing runs 3.1.3),
and also degrades debugging of user code pickled by value.

Pin `cloudpickle<3.1.3` until the debugger no longer depends on `co_filename` of
pickled-by-value code. `uv.lock` already resolves 3.1.1; only its recorded
requirement changes.

___

landed-with-radar-review

Differential Revision: D133032795

fbshipit-source-id: 5da396f6623e9446e3645901a7b2de6d7a5f305a
Andrew-S-Rosen added a commit to Quantum-Accelerators/quacc that referenced this pull request Nov 20, 2026
## Summary of Changes

Pin the test dependency `cloudpickle==3.1.2` to restore coverage of
serialized Dask jobs and subflows. Cloudpickle 3.1.3 replaces
`co_filename` with `<dynamic-code>` when serializing code objects
([upstream change](cloudpipe/cloudpickle#560)),
so coverage.py cannot attribute worker execution to the original source
files. The tests still pass, but Codecov reports the six Dask decorator
lines and eighteen Espresso phonon subflow lines as missed.

The successful main run
[44219904494](https://github.com/Quantum-Accelerators/quacc/actions/runs/44219904494)
installed cloudpickle 3.1.2; the regressed run
[44755338965](https://github.com/Quantum-Accelerators/quacc/actions/runs/44755338965)
installed 3.1.3. Both used coverage.py 7.17.3, distributed 2026.8.0, and
Python 3.14.10, and both passed all 24 Dask tests.

The pin is confined to the shared test requirements, with a comment
explaining why it exists. Runtime dependency requirements and coverage
exclusions are unchanged.

### Validation

On Python 3.14.10 with `COVERAGE_CORE=sysmon`, coverage.py 7.17.3, and
Dask/distributed 2026.8.0:

- `tests/dask/test_syntax.py tests/dask/test_customizers.py`: 7 passed
with both cloudpickle 3.1.2 and 3.1.3.
- Coverage XML records hits on decorators.py lines 157–158 and 546–549
with 3.1.2; all six lines have zero hits with 3.1.3.
- Expanded validation with cloudpickle 3.1.2: `tests/dask/test_syntax.py
tests/dask/test_customizers.py tests/dask/test_tutorials.py
tests/dask/test_copy_files.py`: 13 passed; all six decorator lines have
hits in the resulting coverage XML.
- `git diff --check` passes.

Full Quantum ESPRESSO validation is left to CI because its external
executables are not installed locally.

### Requirements

- [x] My PR is focused on a single bugfix.
- [x] Relevant existing tests were run to reproduce and validate the
dependency regression.
- [x] My PR is on a custom branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cloudpickle is not stable in notebooks

3 participants