Skip to content

Commit

Permalink
Merge pull request #52 from CovertLab/name_change
Browse files Browse the repository at this point in the history
Rename arrow module to stochastic_arrow
  • Loading branch information
thalassemia authored Jun 30, 2023
2 parents fdf3db7 + 4bd8eae commit fabb713
Show file tree
Hide file tree
Showing 28 changed files with 192 additions and 58 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Modified from GitHub Actions template

name: Pytest

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test-on-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install numpy
pip install -r requirements.txt
- name: Compile Cython
run: |
make clean compile
- name: Test with pytest
run: |
pytest
test-on-windows:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install numpy
pip install -r requirements.txt
- name: Compile Cython
run: |
make clean compile
- name: Test with pytest
run: |
pytest
test-on-mac:
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install numpy
pip install -r requirements.txt
- name: Compile Cython
run: |
make clean compile
- name: Test with pytest
run: |
pytest
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ profile
/.idea/
/tmp/

arrow/arrowhead.c
arrow/*.html
stochastic_arrow/arrowhead.c
stochastic_arrow/arrowhead.*.pyd
stochastic_arrow/*.html

arrow.egg-info/
stochastic_arrow.egg-info/
Expand Down
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include arrow/obsidian.h
include arrow/mersenne.h
include stochastic_arrow/obsidian.h
include stochastic_arrow/mersenne.h
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
.DEFAULT_GOAL := compile

clean:
rm -rf arrow/arrowhead*.so arrow/arrowhead.c arrow/arrowhead.html build/ dist/ MANIFEST .pytest_cache/ stochastic_arrow.egg-info/
### Files for older versions of stochastic_arrow are in arrow folder
rm -rf arrow/arrowhead*.so arrow/arrowhead.c arrow/arrowhead.html
rm -rf stochastic_arrow/arrowhead*.so stochastic_arrow/arrowhead.c stochastic_arrow/arrowhead.html build/ dist/ MANIFEST .pytest_cache/ stochastic_arrow.egg-info/
find . -name "*.pyc" -delete
find . -name "__pycache__" -delete

Expand Down
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@ Add the following to your `requirements.txt`, or run

stochastic-arrow

**NOTE:** If upgrading from a version older than 1.0.0, check if the [`arrow`](https://github.com/arrow-py/arrow) datetime package is installed. If so, uninstall `arrow` before upgrading `stochastic-arrow`, then reinstall `arrow`.

> pip show arrow
> pip uninstall arrow
> pip install stochastic-arrow
> pip install arrow

## Usage

The `arrow` library presents a single class as an interface,
The `stochastic_arrow` library presents a single class as an interface,
`StochasticSystem`, which operates on a set of reactions (encoded as a `numpy`
matrix of stoichiometrix coefficients) and associated reaction rates:

```python
from arrow import StochasticSystem
from stochastic_arrow import StochasticSystem
import numpy as np

# Each row is a reaction and each column is a molecular species (or other
Expand Down Expand Up @@ -79,14 +86,14 @@ derived from the list of events and the stoichiometric matrix, along with the in
state. `reenact_events` will do this for you:

```python
from arrow import reenact_events
from stochastic_arrow import reenact_events

history = reenact_events(stoichiometry, result['events'], state)
history = reenact_events(stoichiometric_matrix, result['events'], state)
```

## Testing

`arrow` uses [pytest](https://docs.pytest.org/en/latest/). To test it:
`stochastic_arrow` uses [pytest](https://docs.pytest.org/en/latest/). To test it:

> make clean compile
> pytest
Expand All @@ -95,26 +102,30 @@ history = reenact_events(stoichiometry, result['events'], state)

There are more command line features in test_arrow:

> python -m arrow.test.test_arrow --complexation
> python -m stochastic_arrow.test.test_arrow --complexation

> python -m arrow.test.test_arrow --plot
> python -m stochastic_arrow.test.test_arrow --plot

> python -m arrow.test.test_arrow --obsidian
> python -m stochastic_arrow.test.test_arrow --obsidian

> python -m arrow.test.test_arrow --memory
> python -m stochastic_arrow.test.test_arrow --memory

> python -m arrow.test.test_arrow --time
> python -m stochastic_arrow.test.test_arrow --time

More examples:

> python -m arrow.test.test_hang
> python -m stochastic_arrow.test.test_hang

> pytest -m arrow/test/test_arrow.py
> pytest -m stochastic_arrow/test/test_arrow.py

> pytest -k flagella

## Changelog

### Version 1.0.0

* Rename module to `stochastic_arrow` to avoid name conflict (Issue #51). **All users must update their import statements to use `stochastic_arrow` instead of `arrow`.**

### Version 0.5.2

* Update to Cython 0.29.34. (Cython 3.0.0 is now in beta.)
Expand Down
21 changes: 12 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
_ = setuptools


with open("README.md", 'r') as readme:
with open("README.md", 'r', encoding="utf-8") as readme:
long_description = readme.read()

current_dir = os.getcwd()
arrow_dir = os.path.join(current_dir, 'arrow')
arrow_dir = os.path.join(current_dir, 'stochastic_arrow')

# Compile the Cython code to C for development builds:
# USE_CYTHON=1 python setup.py build_ext --inplace
Expand All @@ -30,25 +30,28 @@
ext = '.pyx' if USE_CYTHON else '.c'

cython_extensions = [
Extension('arrow.arrowhead',
sources=['arrow/mersenne.c', 'arrow/obsidian.c', 'arrow/arrowhead'+ext,],
include_dirs=['arrow', np.get_include()],
Extension('stochastic_arrow.arrowhead',
sources=[
'stochastic_arrow/mersenne.c',
'stochastic_arrow/obsidian.c',
'stochastic_arrow/arrowhead'+ext,],
include_dirs=['stochastic_arrow', np.get_include()],
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
)]

if USE_CYTHON:
from Cython.Build import cythonize
cython_extensions = cythonize(
cython_extensions,
include_path=['arrow'],
include_path=['stochastic_arrow'],
annotate=True, # to get an HTML code listing
)

setup(
name='stochastic-arrow',
version='0.5.2',
packages=['arrow'],
author='Ryan Spangler, John Mason, Jerry Morrison, Chris Skalnik, Travis Ahn-Horst',
version='1.0.0',
packages=['stochastic_arrow'],
author='Ryan Spangler, John Mason, Jerry Morrison, Chris Skalnik, Travis Ahn-Horst, Sean Cheah',
author_email='[email protected]',
url='https://github.com/CovertLab/arrow',
license='MIT',
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _last_where(bool_array):
if __name__ == '__main__':
import matplotlib.pyplot as plt

from arrow.analysis.plotting import plot_full_history
from stochastic_arrow.analysis.plotting import plot_full_history

(fig, axes) = plt.subplots(constrained_layout = True)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion arrow/arrow.pxd → stochastic_arrow/arrow.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cython: language_level=3str

# This file works around a Cython 3.0.0a1+ error on arrowhead.pyx:
# arrow/arrowhead.pyx:14:0: 'arrow.pxd' not found
# stochastic_arrow/arrowhead.pyx:14:0: 'arrow.pxd' not found
6 changes: 3 additions & 3 deletions arrow/arrow.py → stochastic_arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def flat_indexes(assorted_lists):

lengths = np.array([
len(l)
for l in assorted_lists])
indexes = np.insert(lengths, 0, 0).cumsum()[:-1]
flat = np.array(flatten(assorted_lists))
for l in assorted_lists], dtype=np.int64)
indexes = np.insert(lengths, 0, 0).cumsum()[:-1].astype(np.int64)
flat = np.array(flatten(assorted_lists), dtype=np.int64)
return flat, lengths, indexes

def reenact_events(stoichiometry, events, state):
Expand Down
4 changes: 2 additions & 2 deletions arrow/arrowhead.pyx → stochastic_arrow/arrowhead.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ cdef class Arrowhead:
self.random_seed = random_seed
mersenne.seed(self.info.random_state, random_seed)

self.info.reactions_count = stoichiometry.shape[0]
self.info.substrates_count = stoichiometry.shape[1]
self.info.reactions_count = <int>stoichiometry.shape[0]
self.info.substrates_count = <int>stoichiometry.shape[1]
self.info.stoichiometry = &stoichiometry[0, 0]

self.info.reactants_lengths = &reactants_lengths[0]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions arrow/obsidian.c → stochastic_arrow/obsidian.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ evolve_result evolve(Info *info, double duration, int64_t *state, double *rates)

// if something goes wrong (like an overflow in propensities), the status will be
// set to some meaningful number
int64_t status = 0;
int status = 0;

if (time == NULL ||
events == NULL ||
outcome == NULL ||
propensities == NULL ||
update == NULL) {
printf("arrow.obsidian.evolve - failed to allocate memory: %d", errno);
printf("stochastic_arrow.obsidian.evolve - failed to allocate memory: %d", errno);

free(time);
free(events);
Expand Down Expand Up @@ -187,14 +187,14 @@ evolve_result evolve(Info *info, double duration, int64_t *state, double *rates)

if (isnan(total)) {
printf("failed simulation: total propensity is NaN\n");
int max_reaction = 0;
int64_t max_reaction = 0;
for (reaction = 0; reaction < reactions_count; reaction++) {
printf("reaction %lld is %f\n", reaction, propensities[reaction]);
printf("reaction %lld is %f\n", (long long)reaction, propensities[reaction]);
if (isnan(propensities[reaction]) || propensities[reaction] > propensities[max_reaction]) {
max_reaction = reaction;
}
}
printf("largest reaction is %d at %f\n", max_reaction, propensities[max_reaction]);
printf("largest reaction is %lld at %f\n", (long long)max_reaction, propensities[max_reaction]);
interval = 0.0;
choice = -1;
status = 1; // overflow
Expand Down Expand Up @@ -278,7 +278,7 @@ evolve_result evolve(Info *info, double duration, int64_t *state, double *rates)
if (step >= event_bounds) {
double *new_time = malloc((sizeof (double)) * event_bounds * 2);
if (new_time == NULL) {
printf("arrow.obsidian.evolve - failed to allocate memory: %d", errno);
printf("stochastic_arrow.obsidian.evolve - failed to allocate memory: %d", errno);

free(time);
free(events);
Expand All @@ -295,7 +295,7 @@ evolve_result evolve(Info *info, double duration, int64_t *state, double *rates)

int64_t *new_events = malloc((sizeof (int64_t)) * event_bounds * 2);
if (new_events == NULL) {
printf("arrow.obsidian.evolve - failed to allocate memory: %d", errno);
printf("stochastic_arrow.obsidian.evolve - failed to allocate memory: %d", errno);

free(time);
free(events);
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion arrow/reference.py → stochastic_arrow/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from six import moves

from arrow.math import multichoose
from stochastic_arrow.math import multichoose


def derive_reactants(stoichiometric_matrix):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from arrow import StochasticSystem
from stochastic_arrow import StochasticSystem
import numpy as np


Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fabb713

Please sign in to comment.