Yes, if I consider simple Hamiltonians, no issues occour. But if I consider in the Hamiltonian even a little more complicated term like qml.X(0) @ qml.X(1), and I try to decompose the relative qDRIFT in terms of gate_set={“CZ”, “RX”, “RZ”, “X”, “SX”, “IsingZZ”}(the gate RZZ of qiskit should be IsingZZ in PennyLane, right?), the code still works, but with some problems.
Indeed, in the decomposition I should expect (from decomposition rules) 4 RZ, 2 RX and an IsingZZ, but in the figure I obtain 1 RX and 2 IsingZZ, with a warning indicates that CNOT does not define a decomposition and was not found in the target gate set (but CNOTs in this code should not be present in principle).
To clarify, I copied here your code with a change in the Hamiltonian and the warning ad.
import matplotlib.pyplot as plt
import pennylane as qml
coeffs = [1.0, 0.1]
ops = [qml.X(0) @ qml.X(1), qml.Z(0)]
H = qml.dot(coeffs, ops)
dev = qml.device("default.qubit", wires=2)
from functools import partial
@partial(qml.transforms.decompose, gate_set={"CZ", "RX", "RZ", "X", "SX", "IsingZZ"})
@qml.qnode(dev)
def my_circ():
# Prepare some state
#qml.Hadamard(0)
# Evolve according to H
qml.QDrift(H, time=1.2, n=1, seed=100)
# Measure some quantity
return qml.probs()
qml.draw_mpl(my_circ)()
fig, ax = qml.draw_mpl(my_circ)()
plt.show()
/home/neo-ale-pc/qenv/lib/python3.12/site-packages/pennylane/transforms/decompose.py:767: UserWarning: Operator CNOT does not define a decomposition and was not found in the target gate set. To remove this warning, add the operator name (CNOT) or type (<class ‘pennylane.ops.op_math.controlled_ops.CNOT’>) to the gate set.
warnings.warn(
/home/neo-ale-pc/qenv/lib/python3.12/site-packages/pennylane/transforms/decompose.py:767: UserWarning: Operator CNOT does not define a decomposition and was not found in the target gate set. To remove this warning, add the operator name (CNOT) or type (<class ‘pennylane.ops.op_math.controlled_ops.CNOT’>) to the gate set.
warnings.warn(
PS:In any case, the Hamiltonian I need to evolve in time and decompose (to add noise models to these elementary gates) is way more complicate, there are 180 terms, and each term is a Pauli string of 5/6 X,Y,Z gates, and the results in that case are completely wrong.