Skip to content

Commit

Permalink
Build documentation in Travis (NeuralEnsemble#335)
Browse files Browse the repository at this point in the history
* fixed _check_consistency in BinnedSpikeTrain and parallel.ipynb notebook

* added docs build in travis; fixed plt.eventplot(spiketrains)

* don't use conda-forge channel for python 2.7

* install extra requirements in docs build

* conda install pandoc

* travis hangs

* travis doc mpi error

* travis check if error is occurred

* Revert "travis check if error is occurred"

This reverts commit 3e59894.

* reverted travis
  • Loading branch information
dizcza committed Jul 27, 2020
1 parent 91c03c4 commit dea2ec4
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 19 deletions.
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ matrix:
- name: "conda 2.7"
python: 2.7
env: DISTRIB="conda"
before_install: sed -i 's/conda-forge/conda/g' requirements/environment.yml

- name: "pip 2.7"
python: 2.7
Expand Down Expand Up @@ -41,6 +42,18 @@ matrix:
python: 3.8
env: DISTRIB="pip"

- name: "docs"
python: 3.6
env: DISTRIB="conda"
before_install: sudo apt install -y libopenmpi-dev openmpi-bin
before_script:
- conda install -c conda-forge pandoc
- pip install -r requirements/requirements-docs.txt
- pip install -r requirements/requirements-tutorials.txt
- pip install -r requirements/requirements-extras.txt
- sed -i -E "s/nbsphinx_execute *=.*/nbsphinx_execute = 'always'/g" doc/conf.py
script: cd doc && make html

install:
- if [[ "${DISTRIB}" == "conda" ]];
then
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorials/asset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
],
"source": [
"plt.figure()\n",
"plt.eventplot(spiketrains, linewidths=5, linelengths=5)\n",
"plt.eventplot([st.magnitude for st in spiketrains], linewidths=5, linelengths=5)\n",
"plt.xlabel('time [ms]')\n",
"plt.ylabel('neuron id')\n",
"plt.title('Raw spikes')\n",
Expand Down Expand Up @@ -800,7 +800,7 @@
],
"source": [
"plt.figure()\n",
"plt.eventplot(reordered_sts, linewidths=5, linelengths=5)\n",
"plt.eventplot([st.magnitude for st in reordered_sts], linewidths=5, linelengths=5)\n",
"plt.xlabel('time [ms]')\n",
"plt.ylabel('reordered neuron id')\n",
"plt.title('Reconstructed ordering of the neurons (y-axis) with synfire chains');"
Expand Down Expand Up @@ -839,7 +839,7 @@
"spiketrains_ordered = [spiketrains[idx] for idx in ordering_true]\n",
"\n",
"plt.figure()\n",
"plt.eventplot(spiketrains_ordered, linewidths=5, linelengths=5)\n",
"plt.eventplot([st.magnitude for st in spiketrains_ordered], linewidths=5, linelengths=5)\n",
"plt.xlabel('time [ms]')\n",
"plt.ylabel('neuron id')\n",
"plt.title('True (unknown) ordering of the neurons (y-axis)')\n",
Expand Down
3 changes: 3 additions & 0 deletions doc/tutorials/gpfa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@
}
],
"metadata": {
"nbsphinx": {
"execute": "never"
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
Expand Down
63 changes: 56 additions & 7 deletions doc/tutorials/parallel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"\n",
"`elephant.parallel` module provides a simple interface to parallelize multiple calls to any user-specified function. The typical use case is calling a function many times with different parameters.\n",
"\n",
"\n",
"## Available executors\n",
"\n",
"`elephant.parallel` has 3 interfaces to choose from, depending whether the user has a laptop/PC or the computation is being done on a cluster machine with many nodes and MPI installed.\n",
Expand All @@ -22,6 +23,7 @@
"\n",
"All listed above classes have the same API and can be used interchangeably.\n",
"\n",
"\n",
"## How to use\n",
"\n",
"Let's say you want to call some function `my_function()` for each element in a list `iterables_list` like so:\n",
Expand All @@ -32,7 +34,11 @@
"\n",
"(eq. 2) `results = Executor().execute(my_function, iterables_list)`,\n",
"\n",
"where `Executor` can be any of the available executors listed above. For more information about parallel executors in Python refer to https://docs.python.org/3/library/concurrent.futures.html."
"where `Executor` can be any of the available executors listed above. For more information about parallel executors in Python refer to https://docs.python.org/3/library/concurrent.futures.html.\n",
"\n",
"**Note**. To successfully run this notebook, `mpi4py` package should be installed in either of ways:\n",
"* `conda install -c conda-forge mpi4py`\n",
"* `pip install mpi4py`, if you have manually installed OpenMPI with `sudo apt install libopenmpi-dev openmpi-bin`\n"
]
},
{
Expand Down Expand Up @@ -235,7 +241,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This is because both MPI executors require `-m mpi4py.futures` flag while running python scripts:\n",
"This is because MPI executors require `-m mpi4py.futures` flag while running python scripts:\n",
"\n",
"```\n",
"mpiexec -n numprocs python -m mpi4py.futures pyfile [arg] ...\n",
Expand Down Expand Up @@ -281,6 +287,49 @@
"time_hist = ProcessPoolExecutor().execute(my_custom_function, binsize_list)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[AnalogSignal with 1 channels of length 100; units dimensionless; datatype float64 \n",
" sampling rate: 10.0 1/s\n",
" time: 0.0 s to 10.0 s,\n",
" AnalogSignal with 1 channels of length 43; units dimensionless; datatype float64 \n",
" sampling rate: 4.375 1/s\n",
" time: 0.0 s to 9.82857142857143 s,\n",
" AnalogSignal with 1 channels of length 28; units dimensionless; datatype float64 \n",
" sampling rate: 2.7999999999999994 1/s\n",
" time: 0.0 s to 10.000000000000002 s,\n",
" AnalogSignal with 1 channels of length 20; units dimensionless; datatype float64 \n",
" sampling rate: 2.0588235294117645 1/s\n",
" time: 0.0 s to 9.714285714285715 s,\n",
" AnalogSignal with 1 channels of length 16; units dimensionless; datatype float64 \n",
" sampling rate: 1.627906976744186 1/s\n",
" time: 0.0 s to 9.82857142857143 s,\n",
" AnalogSignal with 1 channels of length 13; units dimensionless; datatype float64 \n",
" sampling rate: 1.346153846153846 1/s\n",
" time: 0.0 s to 9.657142857142858 s,\n",
" AnalogSignal with 1 channels of length 11; units dimensionless; datatype float64 \n",
" sampling rate: 1.1475409836065573 1/s\n",
" time: 0.0 s to 9.585714285714285 s,\n",
" AnalogSignal with 1 channels of length 10; units dimensionless; datatype float64 \n",
" sampling rate: 1.0 1/s\n",
" time: 0.0 s to 10.0 s]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"time_hist"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -294,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -307,14 +356,14 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"722 ms ± 43.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
"873 ms ± 35.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n"
]
}
],
Expand All @@ -325,7 +374,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -358,7 +407,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.8.3"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorials/statistics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"outputs": [],
"source": [
"plt.figure(figsize=(8, 3))\n",
"plt.eventplot([spiketrain1, spiketrain2], linelengths=0.75, color='black')\n",
"plt.eventplot([spiketrain1.magnitude, spiketrain2.magnitude], linelengths=0.75, color='black')\n",
"plt.xlabel('Time (ms)', fontsize=16)\n",
"plt.yticks([0,1], labels=[\"spiketrain1\", \"spiketrain2\"], fontsize=16)\n",
"plt.title(\"Figure 1\");"
Expand Down Expand Up @@ -475,7 +475,7 @@
"outputs": [],
"source": [
"plt.figure(dpi=150)\n",
"plt.eventplot(spiketrain_list, linelengths=0.75, linewidths=0.75, color='black')\n",
"plt.eventplot([st.magnitude for st in spiketrain_list], linelengths=0.75, linewidths=0.75, color='black')\n",
"plt.xlabel(\"Time, s\")\n",
"plt.ylabel(\"Neuron id\")\n",
"plt.xlim([0, 1]);"
Expand Down
11 changes: 8 additions & 3 deletions elephant/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,17 @@ def _check_consistency(self, spiketrains, binsize, num_bins, t_start,
raise ValueError(
'too many / too large time bins. Some spike trains are '
'not defined in the ending time')
if num_bins != int((
# account for rounding errors in the reference num_bins
num_bins_test = ((
(t_stop - t_start).rescale(
binsize.units) / binsize).magnitude):
binsize.units) / binsize).magnitude)
if _detect_rounding_errors(num_bins_test, tolerance=self.tolerance):
num_bins_test += 1
num_bins_test = int(num_bins_test)
if num_bins != num_bins_test:
raise ValueError(
"Inconsistent arguments t_start (%s), " % t_start +
"t_stop (%s), binsize (%d) " % (t_stop, binsize) +
"t_stop (%s), binsize (%s) " % (t_stop, binsize) +
"and num_bins (%d)" % num_bins)
if num_bins - int(num_bins) != 0 or num_bins < 0:
raise TypeError(
Expand Down
5 changes: 2 additions & 3 deletions postBuild
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pip install .[tutorials]

# Install conda version of mpi4py for mybinder service
conda install mpi4py
conda install -c conda-forge mpi4py

pip install .[tutorials]
5 changes: 5 additions & 0 deletions requirements/environment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: elephant

channels:
- conda-forge # required by mpi4py

dependencies:
- python>=3.6
- pip
Expand All @@ -10,3 +13,5 @@ dependencies:
- pandas
- scikit-learn
- statsmodels
- pip:
- -r file:requirements.txt
3 changes: 2 additions & 1 deletion requirements/requirements-tutorials.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Packages required to execute jupyter notebook tutorials
matplotlib>=3.1.0
h5py>=2.9.0
h5py>=2.9.0
nixio==1.5.0b3

0 comments on commit dea2ec4

Please sign in to comment.