quil-rs
quil-rs copied to clipboard
Support clone that lets you configure what parts of a `Program` to copy.
pyQuil's Program
has a copy_everything_except_instructions
method, which makes sense if you know the structure of that Program
class, but can also be confusing since everything in a Quil program can be considered an instruction. Mirroring this method exactly in quil-rs
would be even more misleading, since all the properties of quil-rs
make up the instructions you get when calling the to_instructions()
method. quil-rs
also doesn't separate things into the same buckets as pyQuil
, for example, DEFGATE
s get lumped into body instructions, but pyQuil maintains a separate property for them.
Going back to pyQuil's copy_everything_except_instructions
method, it turns out that the primary utility of this method has been to separate Quil-T instructions from Quil instructions. However, there are other edge cases where getting just things like DEFGATE
s is also helpful. Instead of trying to account for all these edge cases, it seems better to create an easy way to copy a program, but only with instructions matching a certain criteria. This is already theoretically possible by just iterating over a program with to_instructions
and using match statements to only collect certain types of instructions. Maybe this is the best way to do it, but since copying a program seems like a helpful utility, but since we already are providing methods of this nature (clone_without_body_instructions
), maybe we can offer a method with a builder or some other type that lets you configure what to clone. This would provide a consistent way of creating clones of programs with specific sets of instructions to reduce repetition in our repo as well as boilerplate in downstream code.