qml.simplify

simplify(op: pennylane.operation.Operator)[source]

Simplifies the operator by reducing arithmetic depth or number of rotation parameters.

Parameters

op (Operator) – an operator

Returns

simplified operator

Return type

Operator

Example

Given an instantiated operator, qml.simplify reduces the operator’s arithmetic depth:

>>> op = qml.adjoint(qml.RX(0.54, wires=0) + qml.PauliX(0) + qml.PauliZ(1))
>>> op.arithmetic_depth
3
>>> sim_op = qml.simplify(op)
>>> sim_op.arithmetic_depth
2
>>> type(sim_op)
pennylane.ops.op_math.sum.Sum
>>> sim_op.summands
(Adjoint(RX)(0.54, wires=[0]),
Adjoint(PauliX)(wires=[0]),
Adjoint(PauliZ)(wires=[1]))

This function also can simplify the number of rotation gate parameters:

>>> qml.simplify(qml.Rot(np.pi / 2, 0.1, -np.pi / 2, wires=0))
RX(0.1, wires=[0])

Both types of simplification occur together:

>>> op = qml.adjoint(qml.U2(-np.pi/2, np.pi/2, wires=0) + qml.PauliX(0))
>>> op
Adjoint(Sum)([-1.5707963267948966, 1.5707963267948966], [], wires=[0])
>>> qml.simplify(op)
Adjoint(RX)(1.5707963267948966, wires=[0]) + Adjoint(PauliX)(wires=[0])

Contents

Using PennyLane

Development

API