qml.exp

exp(op, coeff=1, id=None)[source]

Take the exponential of an Operator times a coefficient.

Parameters
  • base (Operator) – The Operator to be exponentiated

  • coeff=1 (Number) – A scalar coefficient of the operator.

Returns

A :class`~.operation.Operator` representing an operator exponential.

Return type

Exp

Example

This symbolic operator can be used to make general rotation operators:

>>> x = np.array(1.23)
>>> op = qml.exp( qml.PauliX(0), -0.5j * x)
>>> qml.math.allclose(op.matrix(), qml.RX(x, wires=0).matrix())
True

This can even be used for more complicated generators:

>>> t = qml.PauliX(0) @ qml.PauliX(1) + qml.PauliY(0) @ qml.PauliY(1)
>>> isingxy = qml.exp(t, 0.25j * x)
>>> qml.math.allclose(isingxy.matrix(), qml.IsingXY(x, wires=(0,1)).matrix())
True

If the coefficient is purely imaginary and the base operator is Hermitian, then the gate can be used in a circuit, though it may not be supported by the device and may not be differentiable.

>>> @qml.qnode(qml.device('default.qubit', wires=1))
... def circuit(x):
...     qml.exp(qml.PauliX(0), -0.5j * x)
...     return qml.expval(qml.PauliZ(0))
>>> print(qml.draw(circuit)(1.23))
0: ──Exp─┤  <Z>

If the base operator is Hermitian and the coefficient is real, then the Exp operator can be measured as an observable:

>>> obs = qml.exp(qml.PauliZ(0), 3)
>>> @qml.qnode(qml.device('default.qubit', wires=1))
... def circuit():
...     return qml.expval(obs)
>>> circuit()
tensor(20.08553692, requires_grad=True)