quil-lang / quilc

The optimizing Quil compiler.
Apache License 2.0
460 stars 72 forks source link

Prototype `DEFGATE .. AS GATE-SEQUENCE` or similar #762

Open stylewarning opened 3 years ago

stylewarning commented 3 years ago

There is currently no way to define a gate based off of a sequence of other gates. Let's prototype syntax and semantics for something like this:

DEFGATE HADAMARD q AS GATE-SEQUENCE:
    RZ(pi/2) q
    RX(pi/2) q
    RZ(pi/2) q

Parameters could also be specified. The AS GATE-SEQUENCE is just a suggestion. Perhaps AS GATES instead?

The point of this feature is to define a gate, and not to define a circuit. While the compiler might decide to expand the given gates, it doesn't need to, and can treat it completely opaquely.

There are a couple questions that arise in implementing such a feature:

  1. What about mutually dependent definitions? (Non-self) recursive definitions?
  2. Should gate sequences be a more first-class definable concept? At some point we will want user-installable gate sequence expansions in QUILC, and maybe there's overlap here.

Note: This would require a change to the Quil spec.

Note: For prototyping, the syntax is pretty close to AS PAULI-SUM in terms of the declaration, and so that code path may be able to be used.