Skip to content
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
7 changes: 7 additions & 0 deletions bionetgen/core/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@ def __init__(
self.model = model
self.message = message
super().__init__(self.message)

class BNGSimulatorError(BNGError):
"""Error related to BNG simulators."""

def __init__(self, message="There was an issue with the BNG simulator"):
self.message = message
super().__init__(self.message)
20 changes: 15 additions & 5 deletions bionetgen/simulator/csimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from distutils import ccompiler
from .bngsimulator import BNGSimulator
from bionetgen.main import BioNetGen
from bionetgen.core.exc import BNGCompileError
from bionetgen.core.exc import BNGCompileError, BNGSimulatorError
from bionetgen.core.utils.logging import BNGLogger

# This allows access to the CLIs config setup
app = BioNetGen()
Expand Down Expand Up @@ -39,6 +40,7 @@ class CSimWrapper:
"""

def __init__(self, lib_path, num_params=None, num_spec_init=None):
self.logger = BNGLogger()
# we need the result struct to reconstruct the object
self.return_struct = RESULT
# load the shared library
Expand All @@ -55,16 +57,24 @@ def set_species_init(self, arr):
"""
Set the initial species values array
"""
# TODO: Transition to BNGErrors and logging
assert len(arr) == self.num_spec_init
if len(arr) != self.num_spec_init:
self.logger.error(
f"Length of species initialization array ({len(arr)}) does not match expected length ({self.num_spec_init})",
loc=f"{__file__} : CSimWrapper.set_species_init()"
)
raise BNGSimulatorError(f"Expected {self.num_spec_init} initial species, but got {len(arr)}")
self.species_init = np.array(arr, dtype=np.float64)

def set_parameters(self, arr):
"""
Set the parameter values array
"""
# TODO: Transition to BNGErrors and logging
assert len(arr) == self.num_params
if len(arr) != self.num_params:
self.logger.error(
f"Length of parameter array ({len(arr)}) does not match expected length ({self.num_params})",
loc=f"{__file__} : CSimWrapper.set_parameters()"
)
raise BNGSimulatorError(f"Expected {self.num_params} parameters, but got {len(arr)}")
self.parameters = np.array(arr, dtype=np.float64)

def simulate(self, t_start=0, t_end=100, n_steps=100):
Expand Down
Loading