-
Notifications
You must be signed in to change notification settings - Fork 343
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
Cannot pickle 'DefFrame' object #1791
Comments
@bramathon I've been looking into implementing this, and the more I fight against pickling, the more I dislike it for our use case. Essentially, the code flow Python enforces to implement it is inefficient and clunky to implement consistently across our instruction types. I think it would be better to lean directly on serialization and deserialization from a Quil string. The API doesn't have a way to initialize a particular instruction from a string, but I could add that, and I think that would be a better solution to this problem. Would you agree? |
Not being able to picke pyquil objects prevents users from pickling any object which contains a pyquil programs or objects. Pickling is also required from some uses of multi-processing. Most pyquil users do not have a deep knowledge of object serialization and will expect to be pickle things, especially for experimental code that might be fairly ephemeral. So this is a common use case a regression from pyquil 3. |
To clarify, a pyQuil Program does support pickling, so it can be pickled as a member of any other pickleable object. I do wonder how common the pickling use case is, given that this is the first time it's popping up for instructions. I am not a fan of Python's pickle module for a number of reasons (it's an vector for ACE, not platform-agnostic, slow). While I think it might be okay for simple use cases, if your Python object already supports its own serialization format, especially when it's backed by a fast parser, I don't think it's pros outweigh the cons. Relying on quil serialization is more direct and performant (and it's exactly what pickling would do behind the scenes, with wasted work). For your use case specifically, would deserializing an instruction from a string work? I think it's a feature we should consider any way, and instruction pickling is an issue we can come back to later if necessary. |
This is available as of pyQuil 4.14.1 |
Code Snippet
TypeError Traceback (most recent call last)
Cell In[33], line 17
5 def_frame = DefFrame(
6 frame=Frame([9], "Transmon-9_flux_tx_c"),
7 direction="tx",
(...)
12 channel_delay=0,
13 )
16 with open("blarg-frame.pickle", "wb") as f:
---> 17 pickle.dump(def_frame, f)
TypeError: cannot pickle 'DefFrame' object
The text was updated successfully, but these errors were encountered: