title: Streaming / saving / serializing internal state of Boost.Numeric.Odeint steppers
body: <p>I have an application where I need to interrupt ODE evolution after a certain time (or, number of steps), save the state of the system + the ODE engine with binary precision, so that the evolution can be resumed later. It is a requirement that evolution so interrupted cannot differ from uninterrupted evolution.</p>
  <p>Saving usually occurs at the end of fairly long trajectories, so it should be assumed that time and disc usage of the serialization stage is not an issue.</p>
  <p>So far, I used <a href="https://www.gnu.org/software/gsl/doc/html/ode-initval.html" rel="nofollow noreferrer">GSL odeiv</a>, wrapped the necessary C objects into a high-level C++ object, and used the <a href="https://www.boost.org/doc/libs/1_75_0/libs/serialization/doc/index.html" rel="nofollow noreferrer">Boost.Serialization</a> library for this latter.</p>
  <p>I want to switch to <a href="https://www.boost.org/doc/libs/1_75_0/libs/numeric/odeint/doc/html/index.html" rel="nofollow noreferrer">Boost.Numeric.Odeint</a>, and I hoped that I wouldn’t need to do any wrapping myself. Steppers in this library can have internal state in general (e.g. <a href="https://www.boost.org/doc/libs/1_75_0/libs/numeric/odeint/doc/html/boost_numeric_odeint/odeint_in_detail/steppers.html#boost_numeric_odeint.odeint_in_detail.steppers.multistep_methods" rel="nofollow noreferrer">multistep methods</a> store internally part of their history), yet, they do not seem to implement either streaming operators or (de)serialization.</p>
  <pre><code>#include &lt;boost/array.hpp&gt;
  #include &lt;boost/numeric/odeint.hpp&gt;
  #include &lt;boost/serialization/array.hpp&gt;
  #include &lt;boost/serialization/serialization.hpp&gt;
  #include &lt;iostream&gt;
  
  namespace O = boost::numeric::odeint;
  
  const bool doContinue = true; // this can be a command-line parameter
  const size_t N = 3;
  typedef boost::array&lt;double, N&gt; state_type;
  
  static void sys(const state_type&amp; /*x*/, state_type&amp; /*dxdt*/, double /*t*/) {
    // ...
  }
  
  int main() {
    // adams_bashforth_moulton stepper example
    double t = 0.0, dt = 0.1;
    state_type inout;
    
    O::adams_bashforth_moulton&lt;5, state_type&gt; abm;
    
    if (!doContinue) {
      abm.initialize(sys, inout, t, dt);
      // integrate for some pretty long time
      for( ; t&lt;10.0 ; t+= dt )
        abm.do_step( sys , inout , t , dt );
      // ...
      // ... save t, inout, and current state of abm to archive ...
      // ...
    }
    else {
      // ...
      // ... retrieve t, inout, and previous state of abm from archive ...
      // ...
      double tEnd=t+10.;
      // continue integration for another pretty long stretch
      for( ; t&lt;tEnd ; t+= dt )
        abm.do_step( sys , inout , t , dt );    
    }
  }
  </code></pre>
  <p>What is the approved way to save the state of steppers in Boost.Numeric.Odeint with full precision?</p>
  <p>I understand that these classes are heavily templated, and the type of the internal state can depend on template parameters, but there might still be some mechanism of retrieving the full internal state. A model might be the pseudo-random-generator engines in STL (e.g. <a href="https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine" rel="nofollow noreferrer">Mersenne twister</a>): they are also pretty heavily templated, yet they provide streaming operators to save/retrieve their internals.</p>