Skip to content

Commit

Permalink
Checked if the recodings are empty (#460)
Browse files Browse the repository at this point in the history
* Checked if the recodings are empty, if so raise an  error.

---------

Co-authored-by: deezer257 <florian@Florian>
  • Loading branch information
2 people authored and michaeldeistler committed Nov 13, 2024
1 parent be1e350 commit dc5bce6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions jaxley/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def integrate(
for key in externals.keys():
externals[key] = externals[key].T # Shape `(time, num_stimuli)`.

if module.recordings.empty:
raise ValueError("No recordings are set. Please set them.")
rec_inds = module.recordings.rec_index.to_numpy()
rec_states = module.recordings.state.to_numpy()

Expand Down
10 changes: 10 additions & 0 deletions tests/test_record_and_stimulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# licensed under the Apache License Version 2.0, see <https://www.apache.org/licenses/>

import jax
import pytest

jax.config.update("jax_enable_x64", True)
jax.config.update("jax_platform_name", "cpu")
Expand Down Expand Up @@ -121,3 +122,12 @@ def test_record_synaptic_and_membrane_states():
# On average the membrane trace spikes around 0 steps after voltage.
offset_mem = 0
assert np.all(np.abs(maxima_3 - maxima_1 - offset_mem)) < 5.0


def test_empty_recordings():
# Create an empty compartment
comp = jx.Compartment()

# Check if a ValueError is raised when integrating an empty compartment
with pytest.raises(ValueError):
v = jx.integrate(comp, delta_t=0.025, t_max=10.0)

0 comments on commit dc5bce6

Please sign in to comment.