pennylane icon indicating copy to clipboard operation
pennylane copied to clipboard

Supporting time-dependent Hamiltonian for time-evolution

Open yulunwang opened this issue 3 years ago • 2 comments

Feature details

Hi all,

I am trying to use Pennylane to solve time evolution problems, where the Hamiltonian is time-dependent. With the ApproxTimeEvolution(H, t, n) method, I am able to prepare the circuit by inputing the Hamiltonian H and time t (and order of Trotter n). But the Hamiltonian is only allowed to be defined with fixed coeffs and Pauli terms.

For example: H = qml.Hamiltonian( [1, 1, 0.5], [qml.PauliX(0), qml.PauliZ(1), qml.PauliX(0) @ qml.PauliX(1)] )

I hope the qml.Hamiltonian can allow time-dependent coeffs so that I don't need to define a new H in every time-step, which is time consuming.

For example: H = qml.Hamiltonian( [2*t, 3*t, 0.5*t-5], [qml.PauliX(0), qml.PauliZ(1), qml.PauliX(0) @ qml.PauliX(1)] )

And then this can be used in ApproxTimeEvolution() method

Thanks

Implementation

No response

How important would you say this feature is?

2: Somewhat important. Needed this quarter.

Additional information

No response

yulunwang avatar Feb 07 '22 00:02 yulunwang

Hi @yulunwang! This is a great feature request.

Perhaps we could add something like the following:

obs = [qml.PauliX(0), qml.PauliZ(1), qml.PauliX(0) @ qml.PauliX(1)]
H = lambda t: qml.Hamiltonian([2 * t, 3 * t, 0.5 * t - 5], obs)

@qml.qnode(dev)
def circuit(t):
    qml.TimeEvolution(H)
    return qml.expval(qml.PauliZ(0))

where H is a function that takes a single parameter (t) and returns the Hamiltonian at that time value.

We could then support some approximate decomposition in order to support this on hardware, perhaps via discretization?

josh146 avatar Feb 07 '22 06:02 josh146

Hi @yulunwang, perhaps this is a bit late now, but there is an even more performant option, based on so-called commutator-free quasi-Magnus operators. Check this repo for an example of how to use Pennylane to simulate time-dependent Hamiltonians https://github.com/XanaduAI/CFQMagnus/blob/main/CFQMagnus/pennylane_simulation.py

PabloAMC avatar Apr 29 '24 08:04 PabloAMC