Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision detection not able to checkpoint #1943

Closed
KaiSzuttor opened this issue Apr 10, 2018 · 4 comments
Closed

Collision detection not able to checkpoint #1943

KaiSzuttor opened this issue Apr 10, 2018 · 4 comments
Assignees
Labels

Comments

@KaiSzuttor
Copy link
Member

see https://travis-ci.org/espressomd/espresso/jobs/364132063

@fweik
Copy link
Contributor

fweik commented Apr 10, 2018 via email

@hmenke
Copy link
Member

hmenke commented Apr 10, 2018

It might not be the case, but it is possible that you run into this problem at some point, so I wanted to make you aware of it.

Python 3 strings are not compatible with C++ std::string which leads to a loss of data when passing a string from Python to C++. This used to blow up our serialization in the pairinteraction project and here is how we fixed it (not Cython but SWIG). Also note our zero-copy approach to setstate.

// Make pickle work
// https://stackoverflow.com/questions/9310053/how-to-make-my-swig-extension-module-work-with-pickle
// remark: passing as std::stringstream does not work because swig calls the implicitly-deleted copy constructor of std::stringstream instead of the move constructor
%define %boost_picklable(cls...)
  %extend cls {
    PyObject* __getstate__() {
      std::stringstream ss;
      boost::archive::binary_oarchive ar(ss);
      ar << *($self);
      return PyBytes_FromStringAndSize(ss.str().data(), ss.str().length());
    }

    void __setstate_internal(PyObject* const sState) {
      char *buffer;
      Py_ssize_t len;
      PyBytes_AsStringAndSize(sState, &buffer, &len);
      boost::iostreams::array_source asource(buffer, static_cast<size_t>(len)); // prevents from copying
      boost::iostreams::stream<boost::iostreams::array_source> ss(asource);
      boost::archive::binary_iarchive ar(ss);
      ar >> *($self);
    }
  }
%enddef

@fweik
Copy link
Contributor

fweik commented Apr 10, 2018

Wouldn't you use bytes anyway in python 3? In my understanding the standard string class implies unicode. According to the cython docs std::string is convertible to and from bytes (== a char array), but not from str.

@RudolfWeeber
Copy link
Contributor

This also depends on being able to control the order of restoring stuff, because the bonds used in the collision deteciton have to be present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants