Skip to content

remove multiprocessing from validation functions #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 22 additions & 34 deletions bluecellulab/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
except ImportError:
efel = None
from itertools import islice
from itertools import repeat
import logging
from matplotlib.collections import LineCollection
import matplotlib.pyplot as plt
from multiprocessing import Pool
import neuron
import numpy as np
import pathlib
Expand Down Expand Up @@ -97,20 +95,15 @@ def compute_plot_iv_curve(cell,
for amp in list_amp
]

with Pool(len(steps)) as p:
recordings = p.starmap(
run_stimulus,
zip(
repeat(cell.template_params),
steps,
repeat(injecting_section),
repeat(injecting_segment),
repeat(True), # cvode
repeat(True), # add_hypamp
repeat(recording_section),
repeat(recording_segment),
)
)
recordings = []
for step in steps:
recording = run_stimulus(cell.template_params,
step,
section=injecting_section,
segment=injecting_segment,
recording_section=recording_section,
recording_segment=recording_segment)
recordings.append(recording)

steady_states = []
# compute steady state response
Expand Down Expand Up @@ -208,24 +201,19 @@ def compute_plot_fi_curve(cell,
for amp in list_amp
]

with Pool(len(steps)) as p:
recordings = p.starmap(
run_stimulus,
zip(
repeat(cell.template_params),
steps,
repeat(injecting_section),
repeat(injecting_segment),
repeat(True), # cvode
repeat(True), # add_hypamp
repeat(recording_section),
repeat(recording_segment),
repeat(True), # enable_spike_detection
repeat(threshold_voltage), # threshold_spike_detection
)
)

spike_count = [len(recording.spike) for recording in recordings]
spikes = []
for step in steps:
recording = run_stimulus(cell.template_params,
step,
section=injecting_section,
segment=injecting_segment,
recording_section=recording_section,
recording_segment=recording_segment,
enable_spike_detection=True,
threshold_spike_detection=threshold_voltage)
spikes.append(recording.spike)

spike_count = [len(spike) for spike in spikes]

plot_fi_curve(list_amp,
spike_count,
Expand Down
78 changes: 24 additions & 54 deletions bluecellulab/validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,68 +438,38 @@ def run_validations(
)

logger.debug("Running validations...")
from bluecellulab.utils import NestedPool
with NestedPool(processes=8) as pool:
# Validation 1: Spiking Test
spiking_test_result_future = pool.apply_async(
spiking_test,
(cell.template_params, rheobase, out_dir, spike_threshold_voltage)
)

# Validation 2: Depolarization Block Test
depolarization_block_result_future = pool.apply_async(
depolarization_block_test,
(cell.template_params, rheobase, out_dir)
)
# Validation 1: Spiking Test
spiking_test_result = spiking_test(
cell.template_params, rheobase, out_dir, spike_threshold_voltage
)

# Validation 3: Backpropagating AP Test
bpap_result_future = pool.apply_async(
bpap_test,
(cell.template_params, rheobase, out_dir)
)
# Validation 2: Depolarization Block Test
depolarization_block_result = depolarization_block_test(
cell.template_params, rheobase, out_dir
)

# Validation 4: Postsynaptic Potential Test
# We have to wait for ProbAMPANMDA_EMS to be present in entitycore to implement this test
# Validation 3: Backpropagating AP Test
bpap_result = bpap_test(cell.template_params, rheobase, out_dir)

# Validation 5: AIS Spiking Test
ais_spiking_test_result_future = pool.apply_async(
ais_spiking_test,
(cell.template_params, rheobase, out_dir, spike_threshold_voltage)
)
# Validation 4: Postsynaptic Potential Test
# We have to wait for ProbAMPANMDA_EMS to be present in entitycore to implement this test

# Validation 6: Hyperpolarization Test
hyperpolarization_result_future = pool.apply_async(
hyperpolarization_test,
(cell.template_params, rheobase, out_dir)
)
# Validation 5: AIS Spiking Test
ais_spiking_test_result = ais_spiking_test(
cell.template_params, rheobase, out_dir, spike_threshold_voltage
)

# Validation 7: Rin Test
rin_result_future = pool.apply_async(
rin_test,
(rin,)
)
# Validation 6: Hyperpolarization Test
hyperpolarization_result = hyperpolarization_test(cell.template_params, rheobase, out_dir)

# # Validation 8: IV Test
iv_test_result_future = pool.apply_async(
iv_test,
(cell.template_params, rheobase, out_dir, spike_threshold_voltage)
)
# Validation 7: Rin Test
rin_result = rin_test(rin)

# # Validation 9: FI Test
fi_test_result_future = pool.apply_async(
fi_test,
(cell.template_params, rheobase, out_dir, spike_threshold_voltage)
)
# Validation 8: IV Test
iv_test_result = iv_test(cell.template_params, rheobase, out_dir, spike_threshold_voltage)

# Wait for all validations to complete
spiking_test_result = spiking_test_result_future.get()
depolarization_block_result = depolarization_block_result_future.get()
bpap_result = bpap_result_future.get()
ais_spiking_test_result = ais_spiking_test_result_future.get()
hyperpolarization_result = hyperpolarization_result_future.get()
rin_result = rin_result_future.get()
iv_test_result = iv_test_result_future.get()
fi_test_result = fi_test_result_future.get()
# Validation 9: FI Test
fi_test_result = fi_test(cell.template_params, rheobase, out_dir, spike_threshold_voltage)

return {
"memodel_properties": {
Expand Down