Skip to content

ODE stress test #1956

Open
Open
@bob-carpenter

Description

@bob-carpenter

Moved here from stan-dev/math wiki page "ODE stress test", which has since been deleted.

(DL: 3/15/2018. There wasn't a good place to put this, so I'm stashing it as a wiki page for now.)

@wds15 provided a good test that shows difference in speed without differences in behavior. We should include this in performance monitoring at some point in the future. It was also used to find a bug in the implementation.

test/unit/math/rev/mat/functor/integrate_ode_bdf_stress_test.cpp

#include <stan/math/rev/mat.hpp>
#include <boost/random.hpp>
#include <stan/math/prim/scal/prob/lognormal_rng.hpp>
#include <gtest/gtest.h>
// very small michaelis menten example
#include <test/unit/math/rev/arr/functor/coupled_mm.hpp>
#include <test/unit/util.hpp>
#include <vector>

// test which triggers the too much work exception from odeint
TEST(StanOde_tooMuchWork_test, cvodes_coupled_mm) {
  coupled_mm_ode_fun f_;

  boost::ecuyer1988 rng;

  // initial value and parameters from model definition

  double t0 = 0;

  std::vector<double> ts_long;
  ts_long.push_back(1E10);

  std::vector<double> ts_short;
  ts_short.push_back(1);

  std::vector<double> data;

  std::vector<int> data_int;

  typedef stan::math::var scalar_type;

  for (std::size_t i = 0; i < 1000; i++) {
    stan::math::start_nested();

    std::vector<scalar_type> theta_v(4);

    theta_v[0] = stan::math::lognormal_rng(1, 2, rng);
    theta_v[1] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[2] = stan::math::lognormal_rng(-1, 2, rng);
    theta_v[3] = stan::math::lognormal_rng(-2, 2, rng);

    std::vector<scalar_type> y0_v(2);
    y0_v[0] = stan::math::lognormal_rng(5, 2, rng);
    y0_v[1] = stan::math::lognormal_rng(-1, 2, rng);

    std::vector<std::vector<scalar_type> > res = stan::math::integrate_ode_bdf(
        f_, y0_v, t0, ts_long, theta_v, data, data_int, 0, 1E-10, 1E-10, 10000);

    stan::math::grad(res[0][0].vi_);

    stan::math::recover_memory_nested();
  }

  stan::math::print_stack(std::cout);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions