Storing and importing structure containing a PyObject

So I want to store a structure called Results which contains the following:
(:rgi_id, :H, :S, :B, :V, :Vx, :Vy, :Δx, :Δy, :gdir)

Where

  • :H, :S, :B, :V, :Vx, :Vy, are 2D matrices
  • :rgi_id, is a string
  • :Δx, :Δy, are floats
  • :gdir is a PyObject

The problem is if I save and load these results the PyObject becomes: PyObject NULL.
Code that i used:

using JLD2
@save "/home/jovyan/vivekag7/Huginn_env/glacier2D_test_temporal.jld2" results

@load "/home/jovyan/vivekag7/Huginn_env/glacier2D_test_temporal.jld2" results

Does anyone know how to properly save and load this structure? Also for more information on what is contained in the object, see the following:

PyObject <oggm.GlacierDirectory>
  RGI id: RGI60-11.01450
  Region: 11: Central Europe
  Subregion: 11-01: Alps                            
  Glacier type: Glacier
  Terminus type: Land-terminating
  Status: Glacier or ice cap
  Area: 82.206 km2
  Lon, Lat: (8.01919, 46.5028)
  Grid (nx, ny): (107, 154)
  Grid (dx, dy): (137.0, -137.0)

Yes, you need something that knows how to serialize Python objects.

One option is to call something like pickle manually before saving to JLD2. Another option is to use the Julia Serialization standard library, since PyCall supports the serialize interface (via pickle, actually).

You can also add custom serialisation to JLD2 so that a Python object gets serialised via it’s pickle representation (for example).