-
Notifications
You must be signed in to change notification settings - Fork 23
added attr_lock to parallelanalysisbase #52
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
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 |
|---|---|---|
|
|
@@ -21,3 +21,5 @@ Chronological list of authors | |
|
|
||
| 2018 | ||
| - Shujie Fan | ||
| - Richard J Gowers | ||
|
Member
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. And add entry to CHANGELOG. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| """ | ||
| from __future__ import absolute_import, division | ||
| from contextlib import contextmanager | ||
| from six.moves import range | ||
|
|
||
| import MDAnalysis as mda | ||
|
|
@@ -154,6 +155,32 @@ def __init__(self, universe, atomgroups): | |
| self._traj = universe.trajectory.filename | ||
| self._indices = [ag.indices for ag in atomgroups] | ||
|
|
||
| @contextmanager | ||
| def readonly_attributes(self): | ||
| """Set the attributes of this class to be read only | ||
|
|
||
| Useful to avoid the class being modified when passing it around. | ||
|
|
||
| To be used as a context manager:: | ||
|
|
||
| with analysis.readonly_attributes(): | ||
| some_function(analysis) | ||
|
|
||
| """ | ||
| self._attr_lock = True | ||
| yield | ||
| self._attr_lock = False | ||
|
|
||
| def __setattr__(self, key, val): | ||
| # guards to stop people assigning to self when they shouldn't | ||
| # if locked, the only attribute you can modify is _attr_lock | ||
| # if self._attr_lock isn't set, default to unlocked | ||
| if key == '_attr_lock' or not getattr(self, '_attr_lock', False): | ||
| super(ParallelAnalysisBase, self).__setattr__(key, val) | ||
| else: | ||
| # raise HalError("I'm sorry Dave, I'm afraid I can't do that") | ||
|
Member
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. Haha.
Member
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.
Honestly, no idea. |
||
| raise AttributeError("Can't set attribute at this time") | ||
|
|
||
| def _conclude(self): | ||
| """Finalise the results you've gathered. | ||
|
|
||
|
|
@@ -259,18 +286,19 @@ def run(self, | |
| self._prepare() | ||
| time_prepare = prepare.elapsed | ||
| blocks = [] | ||
| for b in range(n_blocks): | ||
| task = delayed( | ||
| self._dask_helper, pure=False)( | ||
| b * bsize * step + start, | ||
| min(stop, (b + 1) * bsize * step + start), | ||
| step, | ||
| self._indices, | ||
| self._top, | ||
| self._traj, ) | ||
| blocks.append(task) | ||
| blocks = delayed(blocks) | ||
| res = blocks.compute(**scheduler_kwargs) | ||
| with self.readonly_attributes(): | ||
| for b in range(n_blocks): | ||
| task = delayed( | ||
| self._dask_helper, pure=False)( | ||
| b * bsize * step + start, | ||
| min(stop, (b + 1) * bsize * step + start), | ||
| step, | ||
| self._indices, | ||
| self._top, | ||
| self._traj, ) | ||
| blocks.append(task) | ||
| blocks = delayed(blocks) | ||
| res = blocks.compute(**scheduler_kwargs) | ||
| self._results = np.asarray([el[0] for el in res]) | ||
| with timeit() as conclude: | ||
| self._conclude() | ||
|
|
||
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 think you also have to add yourself to
docs/conf.py– we haven't introduced fancy authorship processing here.