Is there any operator in Pennylane similar to qiskit's HamiltonianGate?

Hello! I want to use qiskit’s HamiltonianGate in Pennylane, is there any way of using it or any gate in pennylane similar to this?
qiskit.extensions.HamiltonianGate(data, time, label=None)
[data (matrix or Operator) – a hermitian operator, time (float) – time evolution parameter.] (HamiltonianGate | IBM Quantum Documentation)

Hi,

Have you taken a look at qml.Hamiltonian ?

1 Like

Hi @sakhujasaiyam, and thanks for the suggestion @Christophe_Pere!

Aside from Christophe’s suggestion maybe some of the following also work for you:

If you want to see some examples of these being used you can check out some of our PennyLane demos. Let me know if you have trouble finding the examples. I hope this helps!

Actually, I have made a function using numpy library, which returns a Hermitian matrix after doing some tensor product calculation. And so, I was looking for a function which takes in input a Hermitian matrix and time value, and returns the evolved matrix like we have a class HamiltonianGate in qiskit.
qml.Hamiltonian needs coefficients and observables, while qml.ApproxTimeEvolution needs linear combination of Pauli Operators.

Actually, I have made a function using numpy library, which returns a Hermitian matrix after doing some tensor product calculation. And so, I was looking for a function which takes in input a Hermitian matrix and time value, and returns the evolved matrix like we have a class HamiltonianGate in qiskit.
qml.Hamiltonian needs coefficients and observables, while qml.ApproxTimeEvolution needs linear combination of Pauli Operators.

Hi @sakhujasaiyam ,

I’m not sure that this will work for any case but for what you’re describing it looks like qml.evolve should be enough.

import pennylane as qml
import numpy as np

num_qubits = 2
H = np.zeros((2 ** num_qubits, 2 ** num_qubits))
H[0, 0] = 1
wirelist = [i for i in range(num_qubits)]
Herm = qml.Hermitian(H, wirelist)
op = qml.evolve(Herm, coeff=2)

print('Herm: \n',Herm)
print('op: \n', op)
print('matrix(op): \n', qml.matrix(op))

Note that coeff is the ‘x’ that you see in the exponent in the documentation so you can change this to get the evolution for different time values.

Let me know if this is what you were looking for!

Hey @sakhujasaiyam,

HamiltonianGate in Qiskit functions similarly to evolve in PennyLane, but evolve needs to see an operator instead of a hermitian matrix. That can be accomplished with Hermitian (like in @CatalinaAlbornoz’s post) or just with qml.Hamiltonian.

qml.Hamiltonian needs coefficients and observables, while qml.ApproxTimeEvolution needs linear combination of Pauli Operators.

Indeed, ApproxTimeEvolution does require a linear combination of Pauli ops, but you can use pauli_decompose on a matrix to get this (docs).