Skip to content
Snippets Groups Projects
Unverified Commit 0637b3af authored by Didi Hou's avatar Didi Hou Committed by GitHub
Browse files

Merge pull request #3 from didi-hou/test_suit

Test suit
parents e90915f3 76292781
No related branches found
No related tags found
No related merge requests found
name: Mirror to EBRAINS
on:
push:
branches: [ master ]
jobs:
sync_to_ebrains:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'didi-hou' }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
with:
egress-policy: audit
disable-telemetry: true
- name: sycnmaster
uses: wei/git-sync@55c6b63b4f21607da0e9877ca9b4d11a29fc6d83
with:
source_repo: "didi-hou/multi-area-model"
source_branch: "master"
destination_repo: "https://ghpusher:${{ secrets.EBRAINS_GITLAB_ACCESS_TOKEN }}@gitlab.ebrains.eu/didihou/multi-area-model.git"
destination_branch: "master"
- name: synctags
uses: wei/git-sync@55c6b63b4f21607da0e9877ca9b4d11a29fc6d83
with:
source_repo: "didi-hou/multi-area-model"
source_branch: "refs/tags/*"
destination_repo: "https://ghpusher:${{ secrets.EBRAINS_GITLAB_ACCESS_TOKEN }}@gitlab.ebrains.eu/didihou/multi-area-model.git"
destination_branch: "refs/tags/*"
\ No newline at end of file
File added
%% Cell type:code id:0bc96f39-b94f-40d5-be5c-a0d9ebdf8180 tags:
``` python
import numpy as np
import os
import sys
import json
sys.path.append('./figures/MAM2EBRAINS')
from multiarea_model import MultiAreaModel
from multiarea_model import Analysis
from M2E_compute_pop_rates import compute_pop_rates
base_path = os.path.abspath(".")
data_path = os.path.abspath("simulations")
```
%% Cell type:code id:c907631c-4611-469a-941c-ddb31ef753c8 tags:
``` python
# Set the threshold of matching rate of mean firing rate of all populations
# if smaller than this value, raise error so that the test won't pass and something is wrong and needs to be checked manually
match_rate_threshold = 0.95
```
%% Cell type:code id:97fbab67-7282-4800-a6d4-78bb3a36640a tags:
``` python
"""
Down-scaled model.
Neurons and indegrees are both scaled down to 10 %.
Can usually be simulated on a local machine.
Warning: This will not yield reasonable dynamical results from the
network and is only meant to demonstrate the simulation workflow.
"""
d = {}
conn_params = {'replace_non_simulated_areas': 'het_poisson_stat',
'cc_weights_factor': 1.9, # run model in Ground State
'cc_weights_I_factor': 2.0}
network_params = {'N_scaling': 0.006,
'K_scaling': 0.006,
'fullscale_rates': os.path.join(base_path, 'tests/fullscale_rates.json')}
sim_params = {'t_sim': 2000.,
'num_processes': 1,
'local_num_threads': 1}
M = MultiAreaModel(network_params, simulation=True,
sim_spec=sim_params,
theory=True)
M.simulation.simulate()
```
%% Cell type:code id:6730fe7b-e8bf-4aff-9497-bc614f44febd tags:
``` python
# Create an instance of Analysis to load data
A = Analysis(M, M.simulation, data_list=['spikes'], load_areas=None)
```
%% Cell type:code id:1c907303-d2ad-4f17-83df-8b0e21749a1d tags:
``` python
# Create pop_rates, load stationary firing rates, and calculate mean firing rate for all populations
label = M.simulation.label
complete_area_list = ['V1', 'V2', 'VP', 'V3', 'V3A', 'MT', 'V4t', 'V4', 'VOT', 'MSTd',
'PIP', 'PO', 'DP', 'MIP', 'MDP', 'VIP', 'LIP', 'PITv', 'PITd',
'MSTl', 'CITv', 'CITd', 'FEF', 'TF', 'AITv', 'FST', '7a', 'STPp',
'STPa', '46', 'AITd', 'TH']
area_list = complete_area_list
compute_pop_rates(M, data_path, label) # Compute pop_rates
fn = os.path.join(data_path, label, 'Analysis', 'pop_rates.json') # Load stationary firing rates
with open(fn, 'r') as f:
pop_rates = json.load(f)
# Process spike data and calculate mean firing rate for all populations, save them in a dict
rates = np.zeros((len(area_list), 8))
for i, area in enumerate(area_list):
for j, pop in enumerate(M.structure[area][::-1]):
rate = pop_rates[area][pop]
if rate == 0.0:
rate = 1e-5
if area == 'TH' and j > 3: # To account for missing layer 4 in TH
rates[i][j + 2] = rate
else:
rates[i][j] = rate
rates = np.transpose(rates)
rates = np.array(rates)
```
%% Cell type:code id:34d46019-38f2-4b5d-af09-575906b1d4d2 tags:
``` python
# Compare the calculated mean firing rate with the reference values saved in M2E_reference_MFRs.json and calculate the percentage of matching
# Load the array
pop_rates_ref = np.load('M2E_pop_rates_ref.npy')
# Count the percentage of cells that values match (the same)
comparison_result = pop_rates_ref == rates
# print(comparison_result)
same_cells = np.sum(comparison_result)
# print(same_cells)
total_cells = np.prod(pop_rates_ref.shape)
# print(total_cells)
match_rate = same_cells / total_cells
# print(match_rate)
# Judge if the matching rate is lower than threshold set and raise error if yes
if match_rate < match_rate_threshold:
raise TestError("Mismatch of mean firing rates over populations between the latest simulation and saved reference values, there may be problems of recent updates of dependencies, please take a check!")
```
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment