diff --git a/.travis.yml b/.travis.yml index 66ddee2ae3a2afec20a9af28f00c09d7178aa600..7db143a8d465f93dd0da35ad150ed827165e6a01 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 - | diff --git a/python/example/network_ring.py b/python/example/network_ring.py index b7d2a9bc7bfede9af0b940237ee23bacd2ddef8b..e486c624a71b39f235f4f293743cb4d63d8f274d 100644 --- a/python/example/network_ring.py +++ b/python/example/network_ring.py @@ -1,4 +1,3 @@ -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') diff --git a/python/example/single_cell_model.py b/python/example/single_cell_model.py index 5ef30b3ac4eabbad8568234889d13918a7c125d7..7634541773075f7f0b12cc38c043ebf4e4f184a6 100644 --- a/python/example/single_cell_model.py +++ b/python/example/single_cell_model.py @@ -1,4 +1,5 @@ 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') diff --git a/python/example/single_cell_multi_branch.py b/python/example/single_cell_multi_branch.py index 444eb0b3f30d91b5d476a24d20dcd5051e1f8550..6bc6c013fe2e98dcd56f23023a6927a52d197864 100644 --- a/python/example/single_cell_multi_branch.py +++ b/python/example/single_cell_multi_branch.py @@ -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') diff --git a/python/example/single_cell_swc.py b/python/example/single_cell_swc.py index bb9429d3ca496968e422580e932adfbd53923aed..5136218b6f4982ff872bd92ef2c97d4a081af0fb 100644 --- a/python/example/single_cell_swc.py +++ b/python/example/single_cell_swc.py @@ -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') diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh index b81f3ae6659164b242012675e136a40618531f09..8875dfca32364e16e55d5bff756bb0036a14f1aa 100755 --- a/scripts/travis/build.sh +++ b/scripts/travis/build.sh @@ -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)"