PennyLaneAI / pulse-benchmarks

Some basic benchmarks for `pennylane.pulse`
2 stars 0 forks source link

More efficient way to define the drive coefficient for qutip simulation #1

Closed BoxiLi closed 10 months ago

BoxiLi commented 10 months ago

Dear PennyLane developers,

I came across this repo during a talk a few days ago. It is really excellent to see PennyLane including the pulse feature. This benchmarking compares the efficiency of simulating the time evolution using PennyLane with qiskit-dynamics and qutip.

I was following the notebook orward-pass_PL_QUTIP_QISKIT_i7-1260P.ipynb to reproduce it when I noticed that there might be a problem when defining the drive coefficient for the qutip simulation. In the notebook, the time-dependent coefficient is defined as follows:

def wrapped(t, args):
    v = args[f"v{i}"]
    return qml.pulse.pwc((t_span[0], t_span[-1]))(v, t) * np.sin(omega[0]*t)

This function creates a pwc function in every single time step in the ODE solver, which is very inefficient. In fact, most of the time is spent computing this coefficient rather than doing matrix multiplication.

If I replace it with the NumPy pulse function defined in that notebook.

def wrapped(t, args):
    v = args[f"v{i}"]
    sigma = 2.
    return v * np.exp(-0.5 * ((t - 10.)/sigma)**2) /sigma/np.sqrt(2*np.pi) * np.sin(omega0*t)

I got a very different plot. The simulation results are consistent with each other.

image

I am not completely sure what the pwc function does here, but it severely reduced the efficiency of the simulation.

In any case, I totally agree that JIT-compiled code would be faster than the default qutip for small system sizes, let alone the GPU support and audodiff features. But just on the efficiency of the simulation, the difference is probably not as big as shown in the benchmarking here :) We are also introducing the new alpha version of qutip 5.0.0a2, which allows more convenient switching between the dense and sparse matrix. You are also very welcome to try out the new features.

Qottmann commented 10 months ago

Thank you @BoxiLi for taking the time to go through the benchmark and for pointing this out! This actually looks like a remnant of an older version using piece-wise-constant functions that I forgot to update when going to the modulated Gaussian curve. I will update the repo accordingly!

Qottmann commented 10 months ago

Thanks again!