Phase
The phase statement is used to compute and encode the result of some arithmetic computation in the phase of the respective quantum states. It applies a relative phase to computational-basis states of quantum variables proportional to the value of a specified expression over these variables. The phase statement can also specify a fixed rotation angle, i.e., a “global” phase, using an expression with no quantum variables. When a fixed phase rotation occurs under a controlled context, it affects only the controlling states. Otherwise, a fixed phase statement is undetectable. phase statements with a quantum expression are often used to compute the cost of an optimization problem. Applying a fixed phase is useful in expressing phase oracles and reflections.Syntax
- Python
- Native
Semantics
- phase-expression may consist of quantum scalar variables, numeric constant literals, and classical scalar variables, composed using arithmetic operators. See below the set of supported operators.
- The coefficient expression is optional, and may include an execution parameter. Note that an execution parameter cannot occur in phase-expression if it contains quantum variables. If not provided, the default coefficient value is 1.0.
- The operation rotates each computational basis state about the Z axis by an angle equal to the value of phase-expression, multiplied by coefficient if specified.
- For phase-expression over quantum variable that computes the function and coefficient , the operation performed by the statement is .
- For phase-expression without quantum variables that evaluates to , the operation performed by the statement is .
- The expression must be a polynomial in the quantum variables. It is compiled into an Ising-model Hamiltonian, which is evolved per the specified coefficient.
- Add:
+ - Subtract:
-(binary) - Negate:
-(unary) - Multiply:
* - Divide:
/(by a classical value) - Power:
**(quantum base, positive classical integer exponent)
QBit, QNum[1],
and the classical integers 0 and 1:
- Bitwise Or:
| - Bitwise And:
& - Bitwise Xor:
^ - Bitwise Not:
~
PHASE().
Examples
Example 1
In the following model phase is applied to variable with the coefficient . is initialized to a superposition of the values 0, 1, 2, and 3. After the phase statement, state 1 is in phase relative to state 0, state 2 is rotated relative to state 0. State 3 is rotated , which is a full + rotation, that is, the same phase as state 1.- Python
- Native


Example 2
The following example demonstrates the use of phase statement to encode the cost of a max-cut problem, as the implementation of the cost-layer in a QAOA ansatz. The qubit arrayv represents the partition of the set of vertices in a graph into two, and
the expression inside the phase statement computes the number of edges that cross the
partition. Executing this model with the right set of parameter values will yield with
high probability an optimal solution.
- Python
- Native
Example 3
The following model appliesphase with an angle specified as a classical
expression, thus inserting a fixed phase under controlled contexts. In each
case, the states that satisfy the control condition rotate by
relative to those that do not.
- Python
- Native