Skip to content

Commit

Permalink
Bug fixes in integrator
Browse files Browse the repository at this point in the history
- Revert `SimulationState` enum properties to not use bit packing
- Fix incorrect computation of standard deviation, which caused unexpected output
- Fix CVODE error caused by uninitialized time value
  • Loading branch information
jtcooper10 committed Jul 14, 2021
1 parent a86935b commit 9487a45
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ namespace Gillespy::TauHybrid
if (spec_dx < 0) {
// Selected species is a reactant.
means[spec_i] -= (tau_step * propensity_values[rxn_i] * spec_dx);
sd[spec_i] += std::pow((tau_step * propensity_values[rxn_i] * spec_dx), 2);
sd[spec_i] += (tau_step * propensity_values[rxn_i] * std::pow(spec_dx, 2));
}
else if (spec_dx > 0) {
// Selected species is a product.
HybridSpecies &product = species[spec_i];
means[spec_i] += (tau_step * propensity_values[rxn_i] * spec_dx);
sd[spec_i] += std::pow((tau_step * propensity_values[rxn_i] * spec_dx), 2);
sd[spec_i] += (tau_step * propensity_values[rxn_i] * std::pow(spec_dx, 2));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ namespace Gillespy::TauHybrid
// CONTINUOUS or DISCRETE
// otherwise, mode will be determined by the program (DYNAMIC)
// if no choice is made, DYNAMIC will be assumed
SimulationState user_mode : 2;
SimulationState user_mode;

// during simulation execution, a species will fall into either of the two categories, CONTINUOUS or DISCRETE
// this is pre-determined only if the user_mode specifies CONTINUOUS or DISCRETE.
// otherwise, if DYNAMIC is specified, partition_mode will be continually calculated throughout the simulation
// according to standard deviation and coefficient of variance.
SimulationState partition_mode : 1;
SimulationState partition_mode;

// Tolerance level for considering a dynamic species deterministically, value is compared
// to an estimated sd/mean population of a species after a given time step.
Expand All @@ -85,7 +85,7 @@ namespace Gillespy::TauHybrid
struct HybridReaction
{
Reaction *base_reaction;
SimulationState mode : 1;
SimulationState mode;

HybridReaction();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ namespace Gillespy::TauHybrid
current_populations[spec_i] = species[spec_i].initial_population;
}

// Represents the largest valid index of the output vector(s), y (and y0).
int rxn_offset_boundary = num_species + num_reactions;

// SIMULATION STEP LOOP
int save_idx = 1;
double next_time;
Expand Down Expand Up @@ -250,7 +247,7 @@ namespace Gillespy::TauHybrid
// "Permanently" update the rxn_state and populations.
for (int p_i = 0; p_i < num_species; ++p_i) {
current_state[p_i] += population_changes[p_i];
current_populations[p_i] = current_state[p_i];
current_populations[p_i] = (int) current_state[p_i];
result.concentrations[p_i] = current_state[p_i];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ IntegratorData::IntegratorData(HybridSimulation *simulation)

Integrator::Integrator(HybridSimulation *simulation, N_Vector y0, double reltol, double abstol)
: y0(y0),
t(0.0f),
t0(0.0f),
y(N_VClone_Serial(y0)),
data(simulation),
num_reactions(simulation->model->number_reactions),
Expand Down Expand Up @@ -140,7 +142,7 @@ IntegrationResults Integrator::integrate(double *t)
URNGenerator::URNGenerator()
: uniform(0, 1) {}

URNGenerator::URNGenerator(double seed)
URNGenerator::URNGenerator(unsigned long long seed)
: uniform(0, 1),
rng(seed) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ namespace Gillespy::TauHybrid
public:
double next();
URNGenerator();
URNGenerator(double seed);
explicit URNGenerator(unsigned long long seed);
};

N_Vector init_model_vector(Model<double> &model, URNGenerator urn);
Expand Down

0 comments on commit 9487a45

Please sign in to comment.