Skip to content

Commit

Permalink
Silence NumPy warning about float subnormals
Browse files Browse the repository at this point in the history
The dependency pyhmmer is compiled with -funsafe-math-optimizations. Loading a
lib compiled with that flag will set some flags in the CPU for the whole
process, which changes float subnormal behaviour.
This is detected when loading NumPy, raising a warning.
I believe this is not an issue for Vamb, so I just silence the warning for now.
I'm not too happy with this "solution".
  • Loading branch information
jakobnissen committed Sep 4, 2024
1 parent c923347 commit e62308c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ requires = [
build-backend = "setuptools.build_meta"

[tool.ruff]
lint.ignore = ["E722", "E501"]
lint.ignore = [
"E722", # Use bare except.
"E402", # import not at top - needed for the hack in __init__.py
]

# pyproject.toml
[tool.pytest.ini_options]
Expand Down
10 changes: 10 additions & 0 deletions vamb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Documentation: https://github.com/RasmussenLab/vamb/
"""

# TODO: Pyhmmer is compiled with -funsafe-math-optimizations, which toggles some
# flag in the CPU controlling float subnormal behaviour.
# This causes a warning in NumPy.
# This is not an issue in Vamb (I think), so we silence the warning here as a
# temporary fix.
# See https://github.com/althonos/pyhmmer/issues/71
import warnings

warnings.filterwarnings("ignore", category=UserWarning, module="numpy")

from . import vambtools
from . import parsebam
from . import parsecontigs
Expand Down
2 changes: 1 addition & 1 deletion vamb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ def add_clustering_arguments(subparser):
dest="max_clusters",
metavar="",
type=int,
default=None, # meaning: do not stop
default=None, # meaning: do not stop
help=argparse.SUPPRESS,
)

Expand Down
4 changes: 3 additions & 1 deletion vamb/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def make_dataloader(
raise ValueError(f"Batch size must be minimum 1, not {batchsize}")

if len(abundance) != len(tnf) or len(tnf) != len(lengths):
raise ValueError("Lengths of abundance, TNF and lengths arrays must be the same")
raise ValueError(
"Lengths of abundance, TNF and lengths arrays must be the same"
)

if not (abundance.dtype == tnf.dtype == _np.float32):
raise ValueError("TNF and abundance must be Numpy arrays of dtype float32")
Expand Down
2 changes: 1 addition & 1 deletion vamb/vambtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, binsplitter: Optional[str]):
self.splitter = None
else:
self.splitter = binsplitter

self.is_initialized = False

@classmethod
Expand Down

0 comments on commit e62308c

Please sign in to comment.