exp(op, coeff=1, num_steps=None, id=None)¶
Take the exponential of an Operator times a coefficient.
base (Operator) – The Operator to be exponentiated
coeff (float) – a scalar coefficient of the operator
num_steps (int) – The number of steps used in the decomposition of the exponential operator, also known as the Trotter number. If this value is None and the Suzuki-Trotter decomposition is needed, an error will be raised.
id (str) – id for the Exp operator. Default is None.
Operatorrepresenting an operator exponential.
- Return type
This operator supports a batched base, a batched coefficient and a combination of both:
>>> op = qml.exp(qml.RX([1, 2, 3], wires=0), coeff=4) >>> qml.matrix(op).shape (3, 2, 2) >>> op = qml.exp(qml.RX(1, wires=0), coeff=[1, 2, 3]) >>> qml.matrix(op).shape (3, 2, 2) >>> op = qml.exp(qml.RX([1, 2, 3], wires=0), coeff=[4, 5, 6]) >>> qml.matrix(op).shape (3, 2, 2)
But it doesn’t support batching of operators:
>>> op = qml.exp([qml.RX(1, wires=0), qml.RX(2, wires=0)], coeff=4) AttributeError: 'list' object has no attribute 'batch_size'
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
Expoperator 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)
- What is PennyLane?
- Quantum circuits
- Gradients and training
- Quantum operators
- Inspecting circuits
- Compiling circuits
- Quantum Chemistry
- Quantum Datasets
- QNode returns