feat(quil-py): Add an immutable FrozenProgram class#384
feat(quil-py): Add an immutable FrozenProgram class#384
Conversation
|
| pub struct FrozenProgram { | ||
| program: PyProgram, | ||
| } | ||
| impl_eq!(FrozenProgram); |
There was a problem hiding this comment.
Question: The __richcmp__ implementation this macro generates will only compare two FrozenPrograms with equivalent inner Programs as equal.
What about the case where a FrozenProgram is compared to a Program. If the inner program of a FrozenProgram instance is equivalent to an instance of Program, should they evaluate as equivalent?
There was a problem hiding this comment.
I'm flexible. If converting a Program to a FrozenProgram is a light operation (it encapsulates the Program and exposes a limited immutable interface but does not deeply copy the program) then at the level of quil-py I would adhere to its Rust heritage and force the user to write "if frozen_program == FrozenProgram(program):".
How this is net exposed in pyquil is a separate question.
There was a problem hiding this comment.
Strike that ill-informed comment of mine.
I can see it takes the clone. Of course it needs to as the user has a mutable reference to it already.
Let me think about the performance implications of typical workflows here and get back to you.
This is a proposal for #251
The API is very simple, and only supports serialization at the moment.