Skip to content

[patch] as_dataclass_node pickle compatibility #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 9, 2024

Conversation

liamhuber
Copy link
Member

@liamhuber liamhuber commented Aug 8, 2024

Closes #319.

TODO:

  • Wait for the new version of pyiron_snippets
  • See if as_node_function and as_macro_function can use the same new syntax for _reduce_imports_as
  • Add as_node_function to the default creator now that it's working for pickle
  • Wait for then bump pyiron_base I'll make the bump landing-page PR wait, but I want to collapse this stack.

With the introduction of a pickle backend, this test wound up failing. I haven't been able to work out exactly why, but since pickle is much faster my guess is that something in the test parallelization gets in a race condition with deleting a saved workflow from another test. Simply renaming it here solved the issue, which is an innocuous change.
Ok, the reason workflow storage tests were failing after introducing pickle was that the original version of the test had the wrong order of the try/finally scope and the for-loop scope. I got away with it earlier because of interplay between the outer-most member of the loop and the default storage backend. Actually fixing the problem is as simple as ensuring the "finally delete" clause happens after _each_ loop step. This does that and reverts the renaming of the workflow.
You're only supposed to use it as a decorator to start with, so the kwarg was senseless
This is necessary (but not sufficient) to get `as_dataclass_node` decorated classes to pickle. The field name is a bit off compared to `Function` and `Macro`, as now we decorate a class definition instead of a function definition, but it's close.
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

github-actions bot commented Aug 8, 2024

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/as_dataclass_node_pickle

Copy link

codacy-production bot commented Aug 8, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.05% (target: -1.00%) 97.50%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (1857963) 3527 3260 92.43%
Head commit (71f021d) 3564 (+37) 3296 (+36) 92.48% (+0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#410) 40 39 97.50%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10293730104

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 30 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.05%) to 92.48%

Files with Coverage Reduction New Missed Lines %
node.py 13 93.75%
mixin/storage.py 17 92.92%
Totals Coverage Status
Change from base Build 10269404601: 0.05%
Covered Lines: 3296
Relevant Lines: 3564

💛 - Coveralls

@liamhuber liamhuber changed the base branch from main to pickle_save August 8, 2024 00:28
@liamhuber liamhuber closed this Aug 8, 2024
@liamhuber liamhuber reopened this Aug 8, 2024
@liamhuber
Copy link
Member Author

pyiron_snippets 0.1.4 is showing up on anaconda, but must not be available here. This should be done modulo closing and re-opening to trigger a fresh download of the dependencies.

@liamhuber liamhuber marked this pull request as ready for review August 8, 2024 04:47
@liamhuber liamhuber added enhancement New feature or request bug Something isn't working labels Aug 8, 2024
@liamhuber liamhuber closed this Aug 8, 2024
@liamhuber liamhuber reopened this Aug 8, 2024
@liamhuber liamhuber closed this Aug 8, 2024
@liamhuber liamhuber reopened this Aug 8, 2024
@liamhuber
Copy link
Member Author

 Could not solve for environment specs
  The following packages are incompatible
  ├─ pyiron_base 0.9.10**  is installable and it requires
  │  └─ pyiron_snippets 0.1.3 , which can be installed;
  └─ pyiron_snippets 0.1.4**  is not installable because it conflicts with any installable versions previously reported.

right 🤦‍♂️

@liamhuber liamhuber added the format_black trigger the Black formatting bot label Aug 8, 2024
Base automatically changed from pickle_save to patch_bump August 9, 2024 16:46
@liamhuber liamhuber merged commit 162b4e3 into patch_bump Aug 9, 2024
3 of 14 checks passed
@liamhuber liamhuber deleted the as_dataclass_node_pickle branch August 9, 2024 16:49
liamhuber added a commit that referenced this pull request Aug 13, 2024
* [patch] Pickle storage backend (#408)

* Refactor storage test

* Remove empty line

* Rename workflow in tests

With the introduction of a pickle backend, this test wound up failing. I haven't been able to work out exactly why, but since pickle is much faster my guess is that something in the test parallelization gets in a race condition with deleting a saved workflow from another test. Simply renaming it here solved the issue, which is an innocuous change.

* Introduce `pickle` as a backend for saving

* Fix root cause of storage conflict

Ok, the reason workflow storage tests were failing after introducing pickle was that the original version of the test had the wrong order of the try/finally scope and the for-loop scope. I got away with it earlier because of interplay between the outer-most member of the loop and the default storage backend. Actually fixing the problem is as simple as ensuring the "finally delete" clause happens after _each_ loop step. This does that and reverts the renaming of the workflow.

* Again, correctly order try/finally and for-loops

* [patch] `as_dataclass_node` pickle compatibility (#410)

* Refactor storage test

* Remove empty line

* Rename workflow in tests

With the introduction of a pickle backend, this test wound up failing. I haven't been able to work out exactly why, but since pickle is much faster my guess is that something in the test parallelization gets in a race condition with deleting a saved workflow from another test. Simply renaming it here solved the issue, which is an innocuous change.

* Introduce `pickle` as a backend for saving

* Fix root cause of storage conflict

Ok, the reason workflow storage tests were failing after introducing pickle was that the original version of the test had the wrong order of the try/finally scope and the for-loop scope. I got away with it earlier because of interplay between the outer-most member of the loop and the default storage backend. Actually fixing the problem is as simple as ensuring the "finally delete" clause happens after _each_ loop step. This does that and reverts the renaming of the workflow.

* Again, correctly order try/finally and for-loops

* Remove keyword argument from pure-decorator

You're only supposed to use it as a decorator to start with, so the kwarg was senseless

* Add factory import source

This is necessary (but not sufficient) to get `as_dataclass_node` decorated classes to pickle. The field name is a bit off compared to `Function` and `Macro`, as now we decorate a class definition instead of a function definition, but it's close.

* Bring the dataclass node in line with function and macro

* Leverage new pyiron_snippets.factory stuff to find the class

* Mangle the stored dataclass qualname so it can be found later

* Add tests

* Update docs examples to reflect new naming

* Update snippets dependency

* [dependabot skip] Update env file

* Use new pyiron_snippets syntax consistently

* Expose `as_dataclass_node` in the API

Now that it's pickling as well as anything else

* Format black

---------

Co-authored-by: pyiron-runner <pyiron@mpie.de>

* [patch] Fall back on cloudpickle (#411)

* Refactor storage test

* Remove empty line

* Rename workflow in tests

With the introduction of a pickle backend, this test wound up failing. I haven't been able to work out exactly why, but since pickle is much faster my guess is that something in the test parallelization gets in a race condition with deleting a saved workflow from another test. Simply renaming it here solved the issue, which is an innocuous change.

* Introduce `pickle` as a backend for saving

* Fix root cause of storage conflict

Ok, the reason workflow storage tests were failing after introducing pickle was that the original version of the test had the wrong order of the try/finally scope and the for-loop scope. I got away with it earlier because of interplay between the outer-most member of the loop and the default storage backend. Actually fixing the problem is as simple as ensuring the "finally delete" clause happens after _each_ loop step. This does that and reverts the renaming of the workflow.

* Again, correctly order try/finally and for-loops

* Remove keyword argument from pure-decorator

You're only supposed to use it as a decorator to start with, so the kwarg was senseless

* Add factory import source

This is necessary (but not sufficient) to get `as_dataclass_node` decorated classes to pickle. The field name is a bit off compared to `Function` and `Macro`, as now we decorate a class definition instead of a function definition, but it's close.

* Bring the dataclass node in line with function and macro

* Leverage new pyiron_snippets.factory stuff to find the class

* Mangle the stored dataclass qualname so it can be found later

* Add tests

* Update docs examples to reflect new naming

* Update snippets dependency

* [dependabot skip] Update env file

* Use new pyiron_snippets syntax consistently

* Expose `as_dataclass_node` in the API

Now that it's pickling as well as anything else

* [patch] Fall back on cloudpickle

When the pickle backend fails

* Format black

---------

Co-authored-by: pyiron-runner <pyiron@mpie.de>

* [patch] Make pickle the default storage backend (#412)

* Refactor storage test

* Remove empty line

* Rename workflow in tests

With the introduction of a pickle backend, this test wound up failing. I haven't been able to work out exactly why, but since pickle is much faster my guess is that something in the test parallelization gets in a race condition with deleting a saved workflow from another test. Simply renaming it here solved the issue, which is an innocuous change.

* Introduce `pickle` as a backend for saving

* Fix root cause of storage conflict

Ok, the reason workflow storage tests were failing after introducing pickle was that the original version of the test had the wrong order of the try/finally scope and the for-loop scope. I got away with it earlier because of interplay between the outer-most member of the loop and the default storage backend. Actually fixing the problem is as simple as ensuring the "finally delete" clause happens after _each_ loop step. This does that and reverts the renaming of the workflow.

* Again, correctly order try/finally and for-loops

* Remove keyword argument from pure-decorator

You're only supposed to use it as a decorator to start with, so the kwarg was senseless

* Add factory import source

This is necessary (but not sufficient) to get `as_dataclass_node` decorated classes to pickle. The field name is a bit off compared to `Function` and `Macro`, as now we decorate a class definition instead of a function definition, but it's close.

* Bring the dataclass node in line with function and macro

* Leverage new pyiron_snippets.factory stuff to find the class

* Mangle the stored dataclass qualname so it can be found later

* Add tests

* Update docs examples to reflect new naming

* Update snippets dependency

* [dependabot skip] Update env file

* Use new pyiron_snippets syntax consistently

* Expose `as_dataclass_node` in the API

Now that it's pickling as well as anything else

* [patch] Fall back on cloudpickle

When the pickle backend fails

* [minor] Make pickle the default storage backend

* Format black

* Fall back on loading any storage contents

Regardless of what the specified storage backend was.

* Format black

---------

Co-authored-by: pyiron-runner <pyiron@mpie.de>

* Format black

* Update pyiron deps

* [dependabot skip] Update env file

---------

Co-authored-by: pyiron-runner <pyiron@mpie.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request format_black trigger the Black formatting bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Dataclass nodes made from a decorator are not pickleable
3 participants