sbiosimulate crashes during ssa simulation of larger sbml models

2 views (last 30 days)
I have an .sbml model I want to simulate using ssa. It works for small timespans, and when using ode simulations. However, in this example matlab simply crashes. Why is this? is there a way of preventing this?
% Load model.
model_egfr_net = sbmlimport('egfr_net.xml');
% Prepare model for SSA simulations.
clean_ssa_sbml_model(model_egfr_net)
cs = getconfigset(model_egfr_net);
cs.SolverType = 'ssa';
cs.StopTime = 100.0;
% Simulate model.
[t, x, names] = sbiosimulate(model_egfr_net);
I have attached the model. Also, per https://uk.mathworks.com/matlabcentral/answers/1582584-simbio-running-stochastic-ssa-simulation-of-sbml-imported-model the model has to be modified to enable ssa simulations. The attached function (used in the script) is provided here:
function [] = clean_ssa_sbml_model(model)
parameters = sbioselect(model, 'Type', 'parameter');
for paramIndex = 1:numel(parameters)
parameter = parameters(paramIndex);
[~, usageTable] = findUsages(parameter);
% Update any reaction that uses this parameter in its rate.
if isempty(usageTable) % if check added by Torkel.
continue
end
reactions = usageTable.Component(usageTable.Property == "ReactionRate");
for reactionIndex = 1:numel(reactions)
reaction = reactions(reactionIndex);
oldRate = reaction.ReactionRate;
kineticLaw = reaction.KineticLaw;
if isempty(kineticLaw)
% Add a kinetic law
kineticLaw = addkineticlaw(reaction, 'MassAction');
else
% Update the existing kinetic law to mass action
kineticLaw.KineticLawName = 'MassAction';
end
kineticLaw.ParameterVariableNames = parameter.Name;
newRate = reaction.ReactionRate;
if ~strcmp(oldRate, newRate)
warning("Reaction rate for reaction %s changed from %s to %s.", ...
reaction.Name, oldRate, newRate);
end
end
end
end

Answers (1)

Jeremy Huard
Jeremy Huard on 4 Aug 2022
It is a memory usage issue. Every state variable of this fairly large model is logged at every step when default simulation settings are used.
To reduce memory footprint, you could:
  • only log specific states if applicable by setting StatesToLog in the RuntimeOptions category of the configset.
  • set the LogDecimation property of the SolverOptions category of the configset to say, 10 (default is 1) to log every 10th simulation step only.
In general I also recommend to:
  1. use a SimFunction to run multiple simulations. It creates a well defined interface to specify some parameters and get some output back.
  2. use Model Acceleration. SimFunction are accelerated by default the first time they are used. One can also accelerate them manually or deactivate automatic acceleration. If you use sbiosimulate, you can call sbioaccelerate to accelerate a model before calling sbiosimulate. That said, SSA will not benefit much from model acceleration because the reaction calculations in SimBiology are already written in C++.

Communities

More Answers in the  SimBiology Community

Categories

Find more on Scan Parameter Ranges in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by