[CQT-235] Add support for gate modifiers #367
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Notes
test_gate_modifiers
andtest_named_gates
, attest_libqasm.py
.Goal
The semantic AST that is now passed onto OpenSquirrel has this form:
X
), or combinations of gate modifiers acting on a (named) gate (such asctrl.pow(2).inv.X
).measure
orreset
.Gate
and a list of operands. The operands are ofQubit
type.Gate
can have, optionally, anotherGate
, and also optionally, a parameter.Examples:
inv.X
,inv
is a gate (modifier) that has anX
gate and no parameter.pow(2).Y
,pow
is a gate (modifier) that has aY
gate and a2
parameter (an exponenent of type float).X
has neither gate nor parameter, andRx
has no gate but a parameter (an angle of type float).Changes
In order to address the 2 main changes mentioned above, the current implementation of this PR has experimented with the following changes:
default_gate_modifiers.py
. They are called{Inverse,Power,Control}GateModifier
.The idea behind this change from functions to functors is, basically, not to treat parameters as arguments but as members of a given instruction.
For example, for
Rx
, we won't be calling anymoreRx(qubit: Qubit, theta: Float)
. Instead, we will have anRx(theta: Float)
object and we will callRx(qubit)
.The same for
PowerGateModifier
.TODO
As commented in the Notes above, the current PR has only been tested with a couple of parameterized tests.
It could be that, in many parts of the code, we are just using a simple syntax such as
X(q0)
, and this needs now a syntaxX()(q0)
, i.e., instantiate theX
functor and then invokeX.__call__(q0)
.In case it does, we should investigate if the current implementation can be improved so that a syntax such as
X(q0)
still works with functors.Or, even, we may rethink the reimplementation to not use functors.