quil-rs
quil-rs copied to clipboard
Support Hash on Program
In pyQuil, users sometimes use Programs as keys to hash maps. It would be helpful to have this capability in quil-rs as well. In pyQuil a programs __hash__ is defined from the Quil it would generate. There may be faster ways to do it in Rust, but as a starting point, this strategy should work. It's important to note that when placeholders lands, converting a Program to a string will be fallible, which would limit our ability to properly Hash them. However, pyQuil also has this limitation, so we could still achieve feature parity.
If we could Hash all instruction types, we could also derive the Hash implementation ofor Program. However, as we learned in #216, this is challenging for Instructions types that have a HashMap field. If we come up with a workaround for that, we don't have to manually define hash. Still, I suspect we may run into an issue with Hashing placeholders.
Another important note is to define the equality of two Programs, as two equal programs should also have the same hash. Right now, PartialEq is derived on Program. If we rely on serialization of the Program, this would have to change.
An alternative way to define equality is to match global instructions (DEFCAL, DEFFRAME, DEFWAVEFORM) as unordered sets, and the ordered list of the rest of the instructions. This may be the most flexible way of determining equality of programs in terms of their functionality.