Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

cloudpickle cannot pickle '_jpype._JField' objects

Đang mở
#489 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
20/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
java, python
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện lỗi tại các lệnh gọi cloudpickle.dumps() và cloudpickle.loads() của supersuit, sử dụng môi trường JPype được cung cấp. Đọc cloudpickle_fast.py cùng với phần triển khai JPype trong jpype/pickle.py và theo dõi cách đối tượng JField được tuần tự hóa và khôi phục. Hoàn thành khi phương pháp được hỗ trợ đã được ghi lại hoặc triển khai và round trip của môi trường không còn gây ra lỗi memo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

So, I've been working on a project which involves implementing reinforcement learning in a server-client app. The server is written in Java and the client is in Python, which is why I use JPype to import some server classes.

After importing the necessary packages and creating the environment using PettingZoo, it is time to create the model and train it using Stable-Baselines3, but the problem is that when I use Supersuit, it needs to pickle and unpickle the environment, and because the environment contains many Java objects, an error is thrown: TypeError: cannot pickle '_jpype._JField' object.

The normal Pickle package does not support JField objects, but in the JPype library, there is a JPickle version that supports JField objects. I tried to modify the cloudpickle_fast.py to add the JPickle package but I end up having a problem with the cloudpickle.loads()

Here is what I modified in cloudpickle_fast.py:

from jpype.pickle import JPickler, JUnpickler
    def dump(self, obj):
        try:
            return Pickler.dump(self, obj)
        except RuntimeError as e:
            if "recursion" in e.args[0]:
                msg = (
                    "Could not pickle object as excessively deep recursion "
                    "required."
                )
                raise pickle.PicklingError(msg) from e
            else:
                raise
        except TypeError as e:
            return JPickler.dump(self, obj)

And here is the full stacktrace I get:

---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
Input In [11], in <cell line: 6>()
      1 env = MARL_Env_Parallel(4)
      5 env = ss.pettingzoo_env_to_vec_env_v1(env)
----> 6 env = ss.concat_vec_envs_v1(env, 1, num_cpus=1, base_class='stable_baselines3')

File ~\anaconda3\envs\gym\lib\site-packages\supersuit\vector\vector_constructors.py:61, in concat_vec_envs_v1(vec_env, num_vec_envs, num_cpus, base_class)
     59 def concat_vec_envs_v1(vec_env, num_vec_envs, num_cpus=0, base_class="gymnasium"):
     60     num_cpus = min(num_cpus, num_vec_envs)
---> 61     vec_env = MakeCPUAsyncConstructor(num_cpus)(*vec_env_args(vec_env, num_vec_envs))
     63     if base_class == "gymnasium":
     64         return vec_env

File ~\anaconda3\envs\gym\lib\site-packages\supersuit\vector\concat_vec_env.py:22, in ConcatVecEnv.__init__(self, vec_env_fns, obs_space, act_space)
     21 def __init__(self, vec_env_fns, obs_space=None, act_space=None):
---> 22     self.vec_envs = vec_envs = [vec_env_fn() for vec_env_fn in vec_env_fns]
     23     for i in range(len(vec_envs)):
     24         if not hasattr(vec_envs[i], "num_envs"):

File ~\anaconda3\envs\gym\lib\site-packages\supersuit\vector\concat_vec_env.py:22, in <listcomp>(.0)
     21 def __init__(self, vec_env_fns, obs_space=None, act_space=None):
---> 22     self.vec_envs = vec_envs = [vec_env_fn() for vec_env_fn in vec_env_fns]
     23     for i in range(len(vec_envs)):
     24         if not hasattr(vec_envs[i], "num_envs"):

File ~\anaconda3\envs\gym\lib\site-packages\supersuit\vector\vector_constructors.py:11, in vec_env_args.<locals>.env_fn()
     10 def env_fn():
---> 11     env_copy = cloudpickle.loads(cloudpickle.dumps(env))
     12     return env_copy

UnpicklingError: Memo value not found at index 3

I don't have a lot of experience with Pickle, so any advice would be welcome, thanks.

Ngôn ngữ chính
Python
Star
1.9k
Fork
197
Merge trung bình
1 ngày 10 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cloudpipe/cloudpickle

Tất cả issue của cloudpipe/cloudpickle

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.