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

Pickling of "pinocchio.pinocchio_pywrap_casadi.Model" instances is not enabled #2471

Open
TexnoMann opened this issue Oct 31, 2024 · 3 comments

Comments

@TexnoMann
Copy link

TexnoMann commented Oct 31, 2024

Bug description

Python bindings for the casadi model cannot be serialized via pickle.

Expected behavior

pinocchio.casadi.Model must also be serializable

Reproduction steps

Install pinocchio==3.2.0 from conda-forge channel and run provided bellow code

Code

import unittest
import sys
import os
import pickle

import pinocchio as pin
from pinocchio import casadi as cpin

import casadi
from casadi import SX
import numpy as np


class TestMainAlgos(unittest.TestCase):
    def setUp(self):
        self.model = pin.buildSampleModelHumanoidRandom()
        self.data = self.model.createData()

        self.cmodel = cpin.Model(self.model)
        self.cdata = self.cmodel.createData()

    def test_pickle(self):
        cmodel = self.cmodel
        cdata = self.cdata
        with open("cmodel.pkl", "wb") as f:
            pickle.dump(cmodel, f)
        with open("cdata.pkl", "wb") as f:
            pickle.dump(cdata, f)


if __name__ == "__main__":
    unittest.main()

System

  • OS: Ubuntu 20.04
  • Pinocchio version: 3.2.0
@jcarpent
Copy link
Contributor

jcarpent commented Nov 1, 2024

Why do yo want to serialize casadi Models? The idea is to have only standard scalar to be serializable

@TexnoMann
Copy link
Author

TexnoMann commented Nov 1, 2024

Why do yo want to serialize casadi Models? The idea is to have only standard scalar to be serializable

I'm using casadi Models as a backend to calculate filtered dynamics, and my wrapper model that I want to serialize includes cpin.Model. I can write high-level serialization with casadi Model exception if this is expected behavior and you don't plan to implement it.

@jcarpent
Copy link
Contributor

jcarpent commented Nov 1, 2024

The shortest way to do it would be to go through a pin.Model and to cast it to a casadi model using

cmodel = cpin.Model(model)

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

No branches or pull requests

2 participants