Skip to content
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

Catch error in steady state calculation #614

Merged
merged 2 commits into from
Aug 4, 2021
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
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)