Open karalekas opened 5 years ago
I vote for .inst()
or anything else but not +=
. I am also not super-happy with p.inst("X 0")
.
I had difficulties with this while writing pyquil parser.
IMO +=
feels natural because a Program
object is like a list in others ways (e.g. can be subscripted).
I have a preference for +=
as it is a lot less typing and (IMHO) easier to read.
In the pyQuil documentation for "Programs and Gates", we see snippets like this:
Which seem to imply that we are pushing the
+= <PYQUIL_OBJECT>
method of building outProgram
objects as the recommended way. However, there are other spots in the source, docs, and examples, where other forms of program construction are used. These include:p.inst(X(0))
p.inst("X 0")
p = Program(X(0))
p = Program("X 0")
p += "X 0"
p += Program(X(0))
etc.We as pyQuil developers / maintainers feel that this is simply too many ways to do the same thing, and is a source of confusion. We would like to funnel all program construction toward one canonical/supported way of doing so.
My vote would be for the
+= <PYQUIL_OBJECT>
method, but there are some caveats to this. There are specialized methods on theProgram
object, and some can easily be replaced by the+=
approach. Others, like thedeclare
method or ones that add control flow, are not as easily swapped out.For example, the declare method returns a
MemoryReference
that we use when addingMEASURE
instructions:In addition, the control flow methods like
if_then
are convenient, as they handle the different jump statements for you. However, there is probably a way unify everything into the+=
approach, so we are looking for input / suggestions based off of what people prefer to use, before we settle on one!