forked from CSNG-MFF/mozaik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request CSNG-MFF#96 from RCagnol/SortAds
Adding functionality to sort ADS in DatastoreView
- Loading branch information
Showing
9 changed files
with
195 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
name: Fast model MPI tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
|
||
pytest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Pytest Unit Tests | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- name: Install prerequisites | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install python3-setuptools subversion git libopenmpi-dev g++ libjpeg8 libjpeg8-dev libfreetype6 libfreetype6-dev zlib1g-dev libpng++-dev libncurses5 libncurses5-dev libreadline-dev liblapack-dev libblas-dev gfortran libgsl0-dev openmpi-bin python-tk cmake | ||
pip3 install pytest pytest-cov pytest-randomly coverage black | ||
# TODO: Remove fixed numpy and pynn versions after the PyNN pull request | ||
# https://github.com/NeuralEnsemble/PyNN/pull/762 is accepted | ||
pip3 install numpy==1.23.5 scipy mpi4py matplotlib quantities lazyarray interval Pillow param==1.5.1 parameters neo cython pynn==0.10.0 psutil future requests elephant pytest-xdist pytest-timeout junitparser numba | ||
- name: Download and install imagen | ||
run: | | ||
git clone https://github.com/antolikjan/imagen.git | ||
cd imagen | ||
python setup.py install | ||
cd .. | ||
- name: Install Nest | ||
run: | | ||
wget https://github.com/nest/nest-simulator/archive/v3.1.tar.gz | ||
tar xvfz v3.1.tar.gz | ||
cd nest-simulator-3.1 | ||
cmake -Dwith-mpi=ON -Dwith-boost=ON -DCMAKE_INSTALL_PREFIX:PATH=$pythonLocation -Dwith-optimize='-O3' ./ | ||
make -j8 | ||
make -j8 install | ||
cd .. | ||
python -c 'import nest' | ||
- name: Install mozaik | ||
run: python setup.py install | ||
|
||
- name: Test with pytest | ||
run: pytest -m "mpi and not not_github and mpi_explosion" ./tests/full_model/test_models_mpi.py --cov=mozaik |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import matplotlib | ||
|
||
matplotlib.use("Agg") | ||
from mozaik.analysis.analysis import * | ||
from mozaik.storage.datastore import * | ||
from mozaik.storage.queries import param_filter_query | ||
import mozaik | ||
import logging | ||
import os | ||
|
||
import pytest | ||
|
||
|
||
class TestDatastore: | ||
ref_path = "tests/full_model/reference_data/LSV1M_tiny" | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
""" | ||
Runs the model and loads its result and a saved reference result | ||
""" | ||
cls.ds = cls.load_datastore(cls.ref_path) | ||
TrialAveragedFiringRate( | ||
param_filter_query(cls.ds, st_name="FullfieldDriftingSinusoidalGrating"), | ||
ParameterSet({}), | ||
).analyse() | ||
cls.ads = cls.ds.get_analysis_result() | ||
|
||
@staticmethod | ||
def load_datastore(base_dir): | ||
""" | ||
Load PickledDataStore for reading. | ||
Parameters | ||
---------- | ||
base_dir : base directory where DataStore files are saved | ||
Returns | ||
------- | ||
PickledDataStore with the data from base_dir | ||
""" | ||
return PickledDataStore( | ||
load=True, | ||
parameters=ParameterSet( | ||
{"root_directory": base_dir, "store_stimuli": False} | ||
), | ||
replace=False, | ||
) | ||
|
||
def test_ADS_sorting_homogeneity(self): | ||
dsv_sorted = param_filter_query( | ||
self.ds, st_name="FullfieldDriftingSinusoidalGrating" | ||
) | ||
dsv_sorted.sort_analysis_results("sheet_name") | ||
adss_sorted = dsv_sorted.get_analysis_result() | ||
count_incorrect = 0 | ||
for ads in adss_sorted: | ||
if ads not in self.ads: | ||
count_incorrect += 1 | ||
for ads in self.ads: | ||
if ads not in adss_sorted: | ||
count_incorrect += 1 | ||
assert count_incorrect == 0 | ||
|
||
pass | ||
|
||
def test_ADS_sorting_st_homogeneity(self): | ||
dsv_sorted = param_filter_query(self.ds) | ||
dsv_sorted.sort_analysis_results("st_orientation") | ||
adss_sorted = dsv_sorted.get_analysis_result() | ||
count_incorrect = 0 | ||
for ads in adss_sorted: | ||
if ads not in self.ads: | ||
count_incorrect += 1 | ||
for ads in self.ads: | ||
if ads not in adss_sorted: | ||
count_incorrect += 1 | ||
assert count_incorrect == 0 | ||
|
||
pass | ||
|
||
def test_ADS_sorting_order(self): | ||
dsv_sorted = param_filter_query(self.ds) | ||
dsv_sorted.sort_analysis_results("sheet_name") | ||
adss_sorted = dsv_sorted.get_analysis_result() | ||
count_correct = 0 | ||
for ads, ads_next in zip(adss_sorted[:-1], adss_sorted[1:]): | ||
if not hasattr(ads, "sheet_name"): | ||
count_correct += 1 | ||
elif hasattr(ads_next, "sheet_name") and getattr( | ||
ads, "sheet_name" | ||
) <= getattr(ads_next, "sheet_name"): | ||
count_correct += 1 | ||
assert count_correct + 1 == len(adss_sorted) | ||
|
||
pass | ||
|
||
def test_ADS_sorting_st_order(self): | ||
dsv_sorted = param_filter_query(self.ds) | ||
dsv_sorted.sort_analysis_results("st_orientation") | ||
adss_sorted = dsv_sorted.get_analysis_result() | ||
count_correct = 0 | ||
for ads, ads_next in zip(adss_sorted[:-1], adss_sorted[1:]): | ||
if ads.stimulus_id == None: | ||
count_correct += 1 | ||
elif ads_next.stimulus_id and not hasattr( | ||
ads.stimulus_id, "st_orientation" | ||
): | ||
count_correct += 1 | ||
elif ads_next.stimulus_id and hasattr( | ||
ads_next.stimulus_id, "st_orientation" | ||
): | ||
if getattr( | ||
MozaikParametrized.idd(ads.stimulus_id), "st_orientation" | ||
) <= getattr(MozaikParametrized.idd(ads_next), "st_orientation"): | ||
count_correct += 1 | ||
assert count_correct + 1 == len(adss_sorted) | ||
|
||
pass |