-
Notifications
You must be signed in to change notification settings - Fork 17
Share the modification registry with multiprocessing workers #428
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
Open
GeorgWa
wants to merge
7
commits into
main
Choose a base branch
from
fix/modification-registry-multiprocessing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3739e1b
Share the modification registry with multiprocessing workers
1178032
Take the worker pool out of the multiprocessing interface
39e37de
Write the comments in Simplified Technical English
4d4a71a
Skip the numba tests when numba is absent
2f5325e
Merge main into fix/modification-registry-multiprocessing
f6e122c
Merge origin/fix/modification-registry-multiprocessing
d7ca78d
Trim the parallel helpers to what the callers use
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,10 @@ | ||
| """Modification registry. | ||
|
|
||
| `update_all_by_MOD_DF` calculates all other module-level lookups from `MOD_DF`. | ||
| Thus a copy of `MOD_DF` is a complete snapshot of the registry. Change the | ||
| registry only with `update_all_by_MOD_DF`, to keep this true. | ||
| """ | ||
|
|
||
| import os | ||
| from typing import Union | ||
|
|
||
|
|
@@ -463,7 +470,7 @@ def _check_mass_sanity( | |
| composition_mass = calc_mass_from_formula(composition) | ||
| if not np.allclose(composition_mass, MOD_MASS[mod_name], atol=1e-5): | ||
| raise ValueError( | ||
| f"Modification mass of {mod_name} is inconsistent with the composition formula: {composition}, df version {MOD_DF.loc[mod_name,['composition']]}" | ||
| f"Modification mass of {mod_name} is inconsistent with the composition formula: {composition}, df version {MOD_DF.loc[mod_name, ['composition']]}" | ||
| f" calculated_mass={composition_mass}, mod_mass={MOD_MASS[mod_name]}" | ||
| ) | ||
|
|
||
|
|
@@ -533,6 +540,35 @@ def has_custom_mods(): | |
| return len(MOD_DF[MOD_DF["classification"] == _MOD_CLASSIFICATION_USER_ADDED]) > 0 | ||
|
|
||
|
|
||
| def get_modification_state() -> pd.DataFrame: | ||
| """Snapshot the modification registry, for a multiprocessing worker or a test. | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| A copy of :data:`MOD_DF`, including all run-time changes. | ||
| """ | ||
| return MOD_DF.copy() | ||
|
|
||
|
|
||
| def set_modification_state(mod_df: pd.DataFrame) -> None: | ||
| """Install a registry snapshot and rebuild the derived lookups. | ||
|
|
||
| A multiprocessing worker started with "spawn" imports alphabase afresh and | ||
| so knows only `modification.tsv`. Installing the parent's snapshot gives it | ||
| every run-time change: custom modifications, modloss filtering, lower-case | ||
| amino acids, a custom TSV. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| mod_df : pd.DataFrame | ||
| A snapshot from :func:`get_modification_state`. | ||
| """ | ||
| global MOD_DF | ||
| MOD_DF = mod_df | ||
| update_all_by_MOD_DF() | ||
|
Contributor
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 mutates |
||
|
|
||
|
|
||
| def add_new_modifications(new_mods: Union[list, dict]): | ||
| """Add new modifications into :data:`MOD_DF`. | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
maybe make explcit that these methods target multiprocessing ..