Skip to content

Commit

Permalink
pyx fix for numpy and cython updates (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
kathyxchen authored Jul 9, 2024
1 parent 6ff4a5e commit 8c50da4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Please see our [release notes](./RELEASE_NOTES.md) for the latest updates to Sel

## Installation

We recommend using Selene with Python 3.6 or above.
We recommend using Selene with Python 3.9 or above.
Package installation should only take a few minutes (less than 10 minutes, typically ~2-3 minutes) with any of these methods (conda, pip, source).

**First, install [PyTorch](https://pytorch.org/get-started/locally/).** If you have an NVIDIA GPU, install a version of PyTorch that supports it--Selene will run much faster with a discrete GPU.
The library is currently compatible with PyTorch versions between 0.4.1 and 1.9.
The library is currently compatible with PyTorch versions between 1.0.0 and 2.3.1.
We will continue to update Selene to be compatible with the latest version of PyTorch.

### Installing selene with [Anaconda](https://www.anaconda.com/download/) (for Linux):
Expand Down Expand Up @@ -73,6 +73,10 @@ Join our [Google group](https://groups.google.com/forum/#!forum/selene-sdk) if y
The documentation for Selene is available [here](https://selene.flatironinstitute.org/).
If you are interested in running Selene through the command-line interface (CLI), [this document](https://selene.flatironinstitute.org/overview/cli.html) describes how the configuration file format (used by the CLI) works and details all the possible configuration parameters you may need to build your own configuration file.

**Important**: The tutorials and manuscript examples were originally run on Selene version 0.1.3---and later with Selene 0.2.0 (PyTorch version 0.4.1). Selene has since been updated substantially and files such as `selene-gpu.yml` specify PyTorch version 1.0.0. Please note that models created with an older version of PyTorch (such as those downloadable with the manuscript case studies) are NOT compatible with newer versions of PyTorch. If you run into errors loading trained model weights files, it is likely the result of differences in PyTorch or CUDA toolkit versions.

We recommend referring to the API documentation linked above, along with more current usages of Selene in related papers (e.g. [Sei framework code](https://github.com/FunctionLab/sei-framework)) as the easiest starting point as of right now.

## Examples

We provide 2 sets of examples: Jupyter notebook tutorials and case studies that we've described in our manuscript.
Expand All @@ -88,8 +92,6 @@ These examples reflect how we most often use Selene in our own projects, whereas
We recommend that the examples be run on a machine with a CUDA-enabled GPU. All examples take significantly longer when run on a CPU machine.
(See the following sections for time estimates.)

**Important**: The tutorials and manuscript examples were originally run on Selene version 0.1.3---and later with Selene 0.2.0 (PyTorch version 0.4.1). Selene has since been updated and files such as `selene-gpu.yml` specify PyTorch version 1.0.0. Please note that models created with an older version of PyTorch (such as those downloadable with the manuscript case studies) are NOT compatible with newer versions of PyTorch. If you run into errors loading trained model weights files, it is likely the result of differences in PyTorch or CUDA toolkit versions.

### Tutorials

Tutorials for Selene are available [here](https://github.com/FunctionLab/selene/tree/master/tutorials).
Expand Down
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This is a document describing new functionality, bug fixes, breaking changes, etc. associated with Selene version releases from v0.5.0 onwards.

## Version 0.5.2
- Fix Cython type error causing build issues with Python 3.9+

## Version 0.5.1
- PyTorch<=1.9 compatibility

## Version 0.5.0

### New functionality
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "numpy", "cython"]
requires = ["setuptools", "wheel", "numpy>=1.26.4", "cython>=3.0.10"]

[tool.poetry.dependencies]
python = ">=3.9"
12 changes: 6 additions & 6 deletions selene_sdk/targets/_genomic_features.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import numpy as np
cimport cython
cimport numpy as np

ctypedef np.int_t DTYPE_t
ctypedef np.int64_t DTYPE_t
ctypedef np.float32_t FDTYPE_t

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.wraparound(False)
def _fast_get_feature_data(int start,
int end,
np.ndarray[FDTYPE_t, ndim=1] thresholds,
Expand All @@ -18,14 +18,14 @@ def _fast_get_feature_data(int start,
cdef int query_length = end - start
cdef int feature_start, feature_end, index_start, index_end, index_feat
cdef np.ndarray[DTYPE_t, ndim=2] encoding = np.zeros(
(query_length, n_features), dtype=np.int)
(query_length, n_features), dtype=np.int64)
cdef np.ndarray[DTYPE_t, ndim=1] targets = np.zeros(
n_features, dtype=np.int)
n_features, dtype=np.int64)
cdef list row

if rows is None:
return np.zeros((n_features,))

for row in rows:
feature_start = int(row[1])
feature_end = int(row[2])
Expand All @@ -37,6 +37,6 @@ def _fast_get_feature_data(int start,
encoding[index_start:index_end, index_feat] = 1

thresholds = (thresholds * query_length - 1).clip(min=0)
targets = (np.sum(encoding, axis=0) > thresholds.astype(int)).astype(int)
targets = (np.sum(encoding, axis=0) > thresholds.astype(np.int64)).astype(np.int64)
return targets

2 changes: 1 addition & 1 deletion selene_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.5.2"
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
cmdclass = {'build_ext': build_ext}

setup(name="selene-sdk",
version="0.5.0",
version="0.5.2",
long_description=long_description,
long_description_content_type='text/markdown',
description=("framework for developing sequence-level "
Expand All @@ -48,12 +48,13 @@
],
ext_modules=ext_modules,
cmdclass=cmdclass,
python_requires='>=3.9',
install_requires=[
"cython>=0.27.3",
"cython>=3.0.10",
'click',
"h5py",
"matplotlib>=2.2.3",
"numpy",
"numpy>=1.26.4",
"pandas",
"plotly",
"pyfaidx",
Expand All @@ -63,7 +64,7 @@
"scipy",
"seaborn",
"statsmodels",
"torch>=0.4.1, <=1.9",
"torch>=1.0.0, <=2.3.1",
],
entry_points={
'console_scripts': [
Expand Down

0 comments on commit 8c50da4

Please sign in to comment.