Can't save Python classes : it.wall.Wall and it.ball.Ball objects

I tired to save ball and wall objects into the PFC3D save file but failed

get_ipython().magic('reset -sf') #command to initialize iPython environment

import itasca as it

it.command("python-reset-state false") #the model new command will not affect python environment

it.command("""
model new
model domain extent -0.1 0.1
ball create id 1 position (0,0,0) radius 0.01
wall generate id 1 name 'test' polygon (-0.1, -0.1, -0.05), (0.1, -0.1, -0.05), (0.1, 0.1, -0.05), (-0.1, 0.1, -0.05)
""")

wall_id_1 = it.wall.find(1)
ball_id_1 = it.ball.find(1)

it.add_save_variable("wall_id_1")
it.add_save_variable("ball_id_1")

it.get_save_variables()

it.command(f"""
model save 'test_220529.sav'
""")

The error message is

ValueError: Error while trying to save the Python object: wall_id_1. Either this object itself or something contained in the object cannot be serialized. Itasca uses the dill Python module for serialization. A description of what can and cannot be serialized can be found here: https://pypi.python.org/pypi/dill The error message follows:

Internal error while calling Python function pickle_dump from module _itasca_internal. The error message was "<class 'TypeError'>"
"can't pickle itasca.wall.Wall objects"
  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\_itasca_internal.py", line 28, in pickle_dump
    _pickler.dump(obj)

  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\pickle.py", line 409, in dump
    self.save(obj)

  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\pickle.py", line 496, in save
    rv = reduce(self.proto)


    While processing line 0 of source Python interpreter.

How can I save it?

Hi @ppk!

As the error message details, Itasca softwares use the dill library to serialize objects.
Citing the documentation:

dill extends python’s pickle module for serializing and de-serializing python objects to the majority of the built-in python types

I guess that Python objects are APIs to native Itasca objects (C++?) and no pure Python objects, I am afraid you cannot save these.
The workaround would be to store your objects through their IDs:

wall_1 = 1
it.add_save_variable("wall_id_1")

Then, restore them in your later sessions:

wall_id_1 = it.wall.find(wall_1)

NB : serialization is the process of storing high-level data into simpler, transmittable datastructures, such as bytes or byte code in Python.