-
Notifications
You must be signed in to change notification settings - Fork 3
my recent changes #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,11 @@ | |
| import atexit | ||
| from collections import defaultdict | ||
| try: | ||
| from cPickle import dump | ||
| from pymor.core.pickle import dump, PicklingError | ||
| except ImportError: | ||
| from pickle import dump | ||
| from cPickle import dump, PicklingError | ||
| except ImportError: | ||
| from pickle import dump, PicklingError | ||
| import datetime | ||
| import os | ||
| if PY2: | ||
|
|
@@ -288,7 +290,15 @@ def process_data(v): | |
| data = {k: process_data(v) for k, v in _current_dataset_data.items()} | ||
|
|
||
| with open(os.path.join(_current_dataset, 'DATA'), 'wb') as f: | ||
| dump(data, f, protocol=-1) | ||
| try: | ||
| dump(data, f, protocol=-1) | ||
| except PicklingError: | ||
| for kk, vv in data.items(): | ||
| try: | ||
| dump({kk: vv}, f, protocol=-1) | ||
| except PicklingError as e: | ||
| print(f'could not pickle "{kk}"') | ||
| raise e | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems helpful. Can you make a separate PR for it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #10 |
||
|
|
||
| def get_metadata(v): | ||
| if isinstance(v, np.ndarray): | ||
|
|
@@ -405,8 +415,7 @@ def dump_failed(filename): | |
| _saved_excepthook, sys.excepthook = sys.excepthook, _excepthook | ||
|
|
||
|
|
||
| @atexit.register | ||
| def _exit_hook(): | ||
| def declare_finished(): | ||
| if _run: | ||
| finished = datetime.datetime.now() | ||
| if _current_dataset: | ||
|
|
@@ -415,3 +424,8 @@ def _exit_hook(): | |
| yaml.dump(finished, f) | ||
| with open(os.path.join(_db_path, 'RUNS', _run, 'FINISHED'), 'wt') as f: | ||
| yaml.dump(finished, f) | ||
|
|
||
|
|
||
| @atexit.register | ||
| def _exit_hook(): | ||
| declare_finished() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the benefit of these changes?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an interactive (notebook) session, I want to manually declare the run finished to start postprocessing. In particular in a notebook, the run is only declared finished upon closing the notebook, so any code relying on asserting that the current run is finished usually requires a notebook restart, and so on... |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not let have simdb any special cases for pyMOR. One could think of some mechanism, however, to customize pickling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran across the need to use pyMORs more advanced pickling in simdb quite often in the recent past, so any mechanism in simdb would be appreciated.