Skip to content

Commit

Permalink
Merge pull request #243 from MannLabs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sander-willems-bruker authored Nov 21, 2022
2 parents 0f1275a + 6bf2796 commit fea91d0
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 40 deletions.
2 changes: 1 addition & 1 deletion alphatims/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


__project__ = "alphatims"
__version__ = "1.0.5"
__version__ = "1.0.6"
__license__ = "Apache"
__description__ = "A Python package to index Bruker TimsTOF raw data for fast and easy accession and visualization"
__author__ = "Sander Willems, Eugenia Voytik"
Expand Down
40 changes: 39 additions & 1 deletion alphatims/tempmmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import mmap
import numpy as np

# local
import alphatims.utils


def make_temp_dir(prefix: str = "temp_mmap_") -> tuple:
"""Make a temporary directory.
Expand All @@ -34,7 +37,7 @@ def make_temp_dir(prefix: str = "temp_mmap_") -> tuple:
_TEMP_DIR, TEMP_DIR_NAME = make_temp_dir()
ARRAYS = {}
CLOSED = False
ALLOW_NDARRAY_SUBCLASS = True
ALLOW_NDARRAY_SUBCLASS = False

logging.warning(
f"WARNING: Temp mmap arrays are written to {TEMP_DIR_NAME}. "
Expand Down Expand Up @@ -162,6 +165,41 @@ def ones(shape: tuple, dtype: np.dtype) -> np.ndarray:
return _array


def arange(
start: int,
stop: int,
step: int = 1,
dtype: np.dtype = np.uint64
) -> np.ndarray:
"""Create a writable temporary mmapped array filled with as a range.
Parameters
----------
start : int
The start of this range.
stop : int
The stop of this range.
step : int
The step of this range.
dtype : type
The np.dtype of the array.
Returns
-------
type
A writable temporary mmapped array filled as a range.
"""
_array = empty((stop - start) // step, dtype)
fill_array(_array, start, stop, step)
return _array


@alphatims.utils.njit(nogil=True)
def fill_array(array, start, stop, step):
for index, value in enumerate(range(start, stop, step)):
array[index] = value


def clone(array: np.ndarray) -> np.ndarray:
"""Create a writable temporary mmapped array copy.
Expand Down
48 changes: 26 additions & 22 deletions alphatims/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def show_platform_info() -> None:
f"cpu count - {psutil.cpu_count()}"
# f" ({100 - psutil.cpu_percent()}% unused)"
)
logging.info(f"cpu frequency - {psutil.cpu_freq().current:.2f} Mhz")

# check if architecture is arm64 as psutil.cpu_freq() is not yet supported on apple silicon
if platform.machine() != 'arm64':
logging.info(f"cpu frequency - {psutil.cpu_freq().current:.2f} Mhz")
logging.info(
f"ram - "
f"{psutil.virtual_memory().available/1024**3:.1f}/"
Expand Down Expand Up @@ -424,7 +427,6 @@ def starfunc(iterable):
def njit(_func=None, *args, **kwargs):
"""A wrapper for the numba.njit decorator.
The "cache" option is set to True by default.
This can be overriden with kwargs.
Parameters
Expand All @@ -442,11 +444,7 @@ def njit(_func=None, *args, **kwargs):
A numba.njit decorated function.
"""
import numba
if "cache" in kwargs:
cache = kwargs.pop("cache")
else:
cache = True
return numba.njit(_func, *args, cache=cache, **kwargs)
return numba.njit(_func, *args, **kwargs)


def class_njit(
Expand All @@ -463,17 +461,28 @@ def parse_dict(dict_to_parse):
result_dict = {}
for key, value in dict_to_parse.items():
if isinstance(value, pd.DataFrame):
key_module = types.ModuleType(f"{key}")
key_module = types.ModuleType(f"{value.__class__}_{id(value)}")
for column in value.columns:
key_module.__dict__[column] = np.array(
value[column].values,
copy=False
)
result_dict[key] = key_module
else:
result_dict[key] = value
import numba.core.registry
if hasattr(value, "__dict__") and not isinstance(
value,
numba.core.registry.CPUDispatcher
):
key_module = types.ModuleType(f"{value.__class__}_{id(value)}")
key_module.__dict__.update(parse_dict(value.__dict__))
result_dict[key] = key_module
else:
result_dict[key] = value
return result_dict
def wrapper(func):
import functools
@functools.wraps(func)
def inner_func(self, *args, **kwargs):
self_ = self
self = types.ModuleType(f"{self.__class__}_{id(self)}")
Expand All @@ -490,14 +499,17 @@ def inner_func(self, *args, **kwargs):
# ]
tree.body[0].decorator_list = []
tree.body[0].args.args = tree.body[0].args.args[1:]
tree.body[0].name = f"{func.__name__}_class_njit"
# tree.body[0].name = f"{func.__name__}_class_njit"
tree.body[0].name = f"{func.__name__}"
src = ast.unparse(tree)
env = dict(locals())
env.update(globals())
env["numba"] = numba
exec(src, env, env)
src = f"self_.{func.__name__} = numba.njit(env['{func.__name__}_class_njit'])"
# src = f"self_.{func.__name__} = env['{func.__name__}_performance']"
# src = f"self_.{func.__name__} = numba.njit(env['{func.__name__}_class_njit'])"
# src = f"object.__setattr__(self_, '{func.__name__}', numba.njit(env['{func.__name__}_class_njit']))"
# src = f"self_.{func.__name__} = env['{func.__name__}_performance']"
src = f"object.__setattr__(self_, '{func.__name__}', numba.njit(env['{func.__name__}']))"
exec(src)
result = eval(f"self_.{func.__name__}(*args, **kwargs)")
return result
Expand All @@ -513,7 +525,6 @@ def pjit(
*,
thread_count=None,
include_progress_callback: bool = True,
cache: bool = True,
**kwargs
):
"""A decorator that parallelizes the numba.njit decorator with threads.
Expand Down Expand Up @@ -543,9 +554,6 @@ def pjit(
If False, no callback is added.
See `set_progress_callback` for callback styles.
Default is True.
cache : bool
See numba.njit decorator.
Default is True (in contrast to numba).
Returns
-------
Expand All @@ -558,13 +566,9 @@ def pjit(
import numpy as np

def parallel_compiled_func_inner(func):
if "cache" in kwargs:
cache = kwargs.pop("cache")
else:
cache = True
numba_func = numba.njit(nogil=True, cache=cache, **kwargs)(func)
numba_func = numba.njit(nogil=True, **kwargs)(func)

@numba.njit(nogil=True, cache=cache)
@numba.njit(nogil=True)
def numba_func_parallel(
iterable,
thread_id,
Expand Down
2 changes: 1 addition & 1 deletion misc/bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.5
current_version = 1.0.6
commit = True
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<build>\d+))?
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_linux/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: AlphaTims
Version: 1.0.5
Version: 1.0.6
Architecture: all
Maintainer: Mann Labs <opensource@alphapept.com>
Description: AlphaTims GUI
Expand Down
4 changes: 2 additions & 2 deletions misc/one_click_linux/create_installer_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ rm -rf dist
rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_linux
pip install "../../dist/alphatims-1.0.5-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==4.10
pip install "../../dist/alphatims-1.0.6-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==5.6.2
pyinstaller ../pyinstaller/alphatims.spec -y
conda deactivate
# mv dist/alphatims dist/AlphaTims
Expand Down
4 changes: 2 additions & 2 deletions misc/one_click_macos/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<key>CFBundleIconFile</key>
<string>alpha_logo.icns</string>
<key>CFBundleIdentifier</key>
<string>alphatims.1.0.5</string>
<string>alphatims.1.0.6</string>
<key>CFBundleShortVersionString</key>
<string>1.0.5</string>
<string>1.0.6</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
8 changes: 4 additions & 4 deletions misc/one_click_macos/create_installer_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ rm -rf dist
rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_macos
pip install pyinstaller==4.10
pip install "../../dist/alphatims-1.0.5-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==5.6.2
pip install "../../dist/alphatims-1.0.6-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
conda list
pyinstaller ../pyinstaller/alphatims.spec -y
conda deactivate
Expand All @@ -34,7 +34,7 @@ if false; then
# https://scriptingosx.com/2019/09/notarize-a-command-line-tool/
for f in $(find dist/alphatims -name '*.so' -or -name '*.dylib'); do codesign --sign "Developer ID Application: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)" $f; done
codesign --sign "Developer ID Application: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)" dist/alphatims/Contents/MacOS/alphatims_gui --force --options=runtime --entitlements entitlements.xml
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.5 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.6 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
productbuild --distribution distribution.xml --resources Resources --package-path alphatims.pkg dist/alphatims_gui_installer_macos.pkg --sign "Developer ID Installer: Max-Planck-Gesellschaft zur Förderung der Wissenschaften e.V. (7QSY5527AQ)"
requestUUID=$(xcrun altool --notarize-app --primary-bundle-id "de.mpg.biochem.alphatims.app" --username "willems@biochem.mpg.de" --password "@keychain:Alphatims-develop" --asc-provider 7QSY5527AQ --file dist/alphatims_gui_installer_macos.pkg 2>&1 | awk '/RequestUUID/ { print $NF; }')
request_status="in progress"
Expand All @@ -46,6 +46,6 @@ if false; then
xcrun altool --notarization-info "$requestUUID" --username "willems@biochem.mpg.de" --password "@keychain:Alphatims-develop"
xcrun stapler staple dist/alphatims_gui_installer_macos.pkg
else
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.5 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg
pkgbuild --root dist/alphatims --identifier de.mpg.biochem.alphatims.app --version 1.0.6 --install-location /Applications/AlphaTims.app --scripts scripts alphatims.pkg
productbuild --distribution distribution.xml --resources Resources --package-path alphatims.pkg dist/alphatims_gui_installer_macos.pkg
fi
2 changes: 1 addition & 1 deletion misc/one_click_macos/distribution.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<installer-script minSpecVersion="1.000000">
<title>AlphaTims 1.0.5</title>
<title>AlphaTims 1.0.6</title>
<background mime-type="image/png" file="alpha_logo.png" scaling="proportional"/>
<welcome file="welcome.html" mime-type="text/html" />
<conclusion file="conclusion.html" mime-type="text/html" />
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_windows/alphatims_innoinstaller.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "AlphaTims"
#define MyAppVersion "1.0.5"
#define MyAppVersion "1.0.6"
#define MyAppPublisher "Max Planck Institute of Biochemistry, Mann department"
#define MyAppURL "https://github.com/MannLabs/alphatims"
#define MyAppExeName "alphatims_gui.exe"
Expand Down
2 changes: 1 addition & 1 deletion misc/one_click_windows/create_installer_windows.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ call rmdir dist /s /q
call rmdir build /s /q
call python setup.py sdist bdist_wheel
call cd misc/one_click_windows
call pip install "../../dist/alphatims-1.0.5-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
call pip install "../../dist/alphatims-1.0.6-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
call pip install pyinstaller==4.10
call pyinstaller ../pyinstaller/alphatims.spec -y
call conda deactivate
Expand Down
4 changes: 2 additions & 2 deletions misc/one_click_windows/create_installer_windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ rm -rf dist
rm -rf build
python setup.py sdist bdist_wheel
cd misc/one_click_windows
pip install "../../dist/alphatims-1.0.5-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==4.10
pip install "../../dist/alphatims-1.0.6-py3-none-any.whl[plotting-stable,stable,legacy-stable]"
pip install pyinstaller==5.6.2
# TODO https://stackoverflow.com/questions/54175042/python-3-7-anaconda-environment-import-ssl-dll-load-fail-error/60405693#60405693
pyinstaller ../pyinstaller/alphatims.spec -y
conda deactivate
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements_development.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jupyter==1.0.0
jupyter_contrib_nbextensions==0.5.1
pyinstaller==4.10
pyinstaller==5.6.2
autodocsumm==0.2.7
sphinx-rtd-theme==0.5.2
plotly==4.12.0
Expand Down

0 comments on commit fea91d0

Please sign in to comment.