Skip to content

Commit

Permalink
Catch error in steady state calculation (#614)
Browse files Browse the repository at this point in the history
* Fix steady state calculation

Raise ValueError when `beta` and `gamma` are not positive.

* Update `TestSplicingDynamics`

Add unit test to verify ValueError is raised when calculating steady
states with inadmissible parameter values.
  • Loading branch information
WeilerP authored Aug 4, 2021
1 parent 0673498 commit 13d0d3c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scvelo/core/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def get_steady_states(
Steady state of system.
"""

if (self.beta > 0) and (self.gamma > 0):
if (self.beta <= 0) or (self.gamma <= 0):
raise ValueError("Both `beta` and `gamma` need to be strictly positive.")
else:
unspliced = self.alpha / self.beta
spliced = self.alpha / self.gamma

Expand Down
32 changes: 32 additions & 0 deletions tests/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,35 @@ def model(y, t, alpha, beta, gamma):
)

assert np.allclose(numerical_solution, exact_solution)

@given(
alpha=st.floats(),
beta=st.floats(max_value=0, allow_infinity=False, allow_nan=False),
gamma=st.floats(max_value=0, allow_infinity=False, allow_nan=False),
initial_state=arrays(
float,
shape=st.integers(min_value=2, max_value=2),
elements=st.floats(
min_value=-1e3, max_value=1e3, allow_infinity=False, allow_nan=False
),
),
with_keys=st.booleans(),
stacked=st.booleans(),
)
def test_steady_state_not_defined(
self,
alpha: float,
beta: float,
gamma: float,
initial_state: ndarray,
with_keys: bool,
stacked: bool,
):
dm = SplicingDynamics(
alpha=alpha, beta=beta, gamma=gamma, initial_state=initial_state
)

with pytest.raises(
ValueError, match=("Both `beta` and `gamma` need to be strictly positive.")
):
_ = dm.get_steady_states(stacked=stacked, with_keys=with_keys)

0 comments on commit 13d0d3c

Please sign in to comment.