Skip to content
Snippets Groups Projects
Unverified Commit f13a2525 authored by Nora Abi Akar's avatar Nora Abi Akar Committed by GitHub
Browse files

Add python examples to CI (#1183)

* Add some log messages in python examples
* Add python examples to CI
parent 70cd849c
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,8 @@ install:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python$PY get-pip.py
pip$PY --version
pip$PY install pandas
pip$PY install seaborn
fi
- if [[ ( "$WITH_PYTHON" == "true" ) && ( "$TRAVIS_OS_NAME" == "osx" ) ]]; then pip$PY install numpy; fi
- |
......
import sys
import arbor
import pandas, seaborn
from math import sqrt
......@@ -109,9 +108,6 @@ print(f'{recipe}')
meters.checkpoint('recipe-create', context)
decomp = arbor.partition_load_balance(recipe, context)
print(f'{decomp}')
hint = arbor.partition_hint()
hint.prefer_gpu = True
hint.gpu_group_size = 1000
......@@ -148,8 +144,12 @@ for sp in spike_recorder.spikes:
print(' ', sp)
# Plot the recorded voltages over time.
df = pandas.DataFrame()
print("Plotting results ...")
df_list = []
for gid in range(ncells):
for s in samplers[gid].samples(arbor.cell_member(gid,0)):
df=df.append({'t/ms': s.time, 'U/mV': s.value, 'Cell': f"cell {gid}"}, ignore_index=True)
times = [s.time for s in samplers[gid].samples(arbor.cell_member(gid,0))]
volts = [s.value for s in samplers[gid].samples(arbor.cell_member(gid,0))]
df_list.append(pandas.DataFrame({'t/ms': times, 'U/mV': volts, 'Cell': f"cell {gid}"}))
df = pandas.concat(df_list)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Cell").savefig('network_ring_result.svg')
import arbor
import pandas, seaborn # You may have to pip install these.
# (1) Create a morphology with a single (cylindrical) segment of length=diameter=6 μm
tree = arbor.segment_tree()
......@@ -33,7 +34,7 @@ else:
print('no spikes')
# (8) Plot the recorded voltages over time.
import pandas, seaborn # You may have to pip install these.
print("Plotting results ...")
seaborn.set_theme() # Apply some styling to the plot
df = pandas.DataFrame({'t/ms': m.traces[0].time, 'U/mV': m.traces[0].value})
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV").savefig('single_cell_model_result.svg')
......
......@@ -91,6 +91,7 @@ m.probe('voltage', '"dtips"', 10000) # at the tips of the dendrites.
# Run simulation for 100 ms of simulated activity.
tfinal=100
m.run(tfinal)
print("Simulation done.")
# Print spike times.
if len(m.spikes)>0:
......@@ -101,8 +102,9 @@ else:
print('no spikes')
# Plot the recorded voltages over time.
print("Plotting results...")
df = pandas.DataFrame()
for t in m.traces:
df=df.append( pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': t.location, "Variable": t.variable}) )
df=df.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': t.location, "Variable": t.variable}) )
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable").savefig('single_cell_multi_branch_result.svg')
......@@ -12,9 +12,16 @@ import arbor
from arbor import mechanism as mech
from arbor import location as loc
import pandas, seaborn
import sys
# Load a cell morphology from an swc file.
tree = arbor.load_swc('../../test/unit/swc/pyramidal.swc')
# Example present here: ../../test/unit/swc/pyramidal.swc
if len(sys.argv) < 2:
print("No SWC file passed to the program")
sys.exit(0)
filename = sys.argv[1]
tree = arbor.load_swc(filename)
# Define the regions and locsets in the model.
defs = {'soma': '(tag 1)', # soma has tag 1 in swc files.
......@@ -45,7 +52,7 @@ cell.paint('"dend"', rL=500)
cell.place('"stim_site"', arbor.iclamp(3, 1, current=2))
cell.place('"stim_site"', arbor.iclamp(8, 1, current=4))
# Detect spikes at the soma with a voltage threshold of -10 mV.
cell.place('"root"', arbor.spike_detector(-10))
cell.place('"axon_end"', arbor.spike_detector(-10))
# Have one compartment between each sample point.
cell.compartments_on_segments()
......@@ -62,6 +69,7 @@ m.probe('voltage', where='"axon_end"', frequency=50000)
# Simulate the cell for 15 ms.
tfinal=15
m.run(tfinal)
print("Simulation done.")
# Print spike times.
if len(m.spikes)>0:
......@@ -72,8 +80,11 @@ else:
print('no spikes')
# Plot the recorded voltages over time.
df = pandas.DataFrame()
print("Plotting results ...")
df_list = []
for t in m.traces:
df=df.append( pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': t.location, "Variable": t.variable}) )
df_list.append(pandas.DataFrame({'t/ms': t.time, 'U/mV': t.value, 'Location': t.location, "Variable": t.variable}))
df = pandas.concat(df_list)
seaborn.relplot(data=df, kind="line", x="t/ms", y="U/mV",hue="Location",col="Variable").savefig('single_cell_swc.svg')
......@@ -107,9 +107,14 @@ fi
if [[ "${WITH_PYTHON}" == "true" ]]; then
progress "Building python module"
make pyarb -j4 || error "building pyarb"
make pyarb -j4 || error "building pyarb"
progress "Python unit tests"
python$PY $python_path/test/unit/runner.py -v2 || error "running python unit tests (serial)"
python$PY $python_path/test/unit/runner.py -v2 || error "running python unit tests (serial)"
progress "Python examples"
python$PY $python_path/example/network_ring.py || error "running python network_ring example"
python$PY $python_path/example/single_cell_model.py || error "running python single_cell_model example"
python$PY $python_path/example/single_cell_multi_branch.py || error "running python single_cell_multi_branch example"
python$PY $python_path/example/single_cell_swc.py $base_path/test/unit/swc/pyramidal.swc || error "running python single_cell_swc example"
if [[ "${WITH_DISTRIBUTED}" = "mpi" ]]; then
if [[ "$TRAVIS_OS_NAME" = "osx" ]]; then
progress "Python distributed unit tests (MPI)"
......
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