From ed8cf0f4453144eb67b3f7e9c755d52de5685064 Mon Sep 17 00:00:00 2001 From: Sharwari Palve Date: Tue, 3 Nov 2026 05:08:25 +0000 Subject: [PATCH] fix: validate ess parameter to prevent low ESS segmentation faults (#47) --- dingo/PolytopeSampler.py | 2 ++ tests/sampling.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/dingo/PolytopeSampler.py b/dingo/PolytopeSampler.py index 1e3676e6..7c50bbef 100644 --- a/dingo/PolytopeSampler.py +++ b/dingo/PolytopeSampler.py @@ -136,6 +136,8 @@ def generate_steady_states( parallel_mmcs -- a boolean flag to request the parallel mmcs num_threads -- the number of threads to use for parallel mmcs """ + if not isinstance(ess, int) or ess < 10: + raise ValueError("The effective sample size (ess) must be an integer greater than or equal to 10.") self.get_polytope() diff --git a/tests/sampling.py b/tests/sampling.py index a0827d68..d7fe4de7 100644 --- a/tests/sampling.py +++ b/tests/sampling.py @@ -51,6 +51,14 @@ def test_sample_sbml(self): self.assertTrue( steady_states.shape[0] == 95 ) self.assertTrue( abs( steady_states[12].mean() - 2.504 ) < 1e-02 ) + + def test_invalid_ess(self): + input_file_json = os.getcwd() + "/ext_data/e_coli_core.json" + model = MetabolicNetwork.from_json(input_file_json) + sampler = PolytopeSampler(model) + + with self.assertRaises(ValueError): + sampler.generate_steady_states(ess=5)