pasqal-io / Pulser

Library for pulse-level/analog control of neutral atom devices. Emulator with QuTiP.
Apache License 2.0
172 stars 60 forks source link

Classical simulation does not allow simulation time equal to the duration of the pulse #249

Closed Adrien-Kahn closed 2 years ago

Adrien-Kahn commented 3 years ago

When simulating a 4ns sequence, res.states only contains 4 states, including the initial state. However, since 4 values for the Hamiltonian were provided, the initial state could be updated 4 times, so that we would have a total of 5 states in res.states with the initial state.

Manually setting the evaluation_times of the simulation does not help because the setter checks that the largest time is smaller than self.times[-1] which is equal to the duration of the sequence minus 1.

Adrien-Kahn commented 3 years ago

Here is a minimal working example:

from pulser import Pulse, Register, Sequence
from pulser.simulation import Simulation
from pulser.devices import MockDevice
import qutip

reg = Register.rectangle(1,2)
p = Pulse.ConstantPulse(4, 40, 80, 0)
seq = Sequence(reg, MockDevice)
seq.declare_channel('ryd','rydberg_local', 0)
seq.add(p, 'ryd')

simtest = Simulation(seq)
restest = simtest.run()

# Overlap with |gg>
print([abs(state.overlap(qutip.basis(4,3)))**2 for state in restest.states])

[Edited for self-containment]

Output:

[1.0, 0.9996002665950946, 0.998404263138335, 0.9964215525372951]

The first value corresponds to the initial state, so we are only given 3 updated states, while 4 values for the Hamiltonian were provided.

sebgrijalva commented 3 years ago

While implementing these changes, there appeared some issues related to the interpolation of the call method of the QobjEvo. I'm still working on this, but it will take longer than expected.