pasqal-io / Pulser

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

Define max_step from minimum variations of samples #666

Closed a-corni closed 3 months ago

a-corni commented 3 months ago

Currently, the max_step is defined automotically from the Sequence if the user don't provide it. This definition was determined in this PR three years ago https://github.com/pasqal-io/Pulser/pull/225 However, it fails if a user provides one Pulse composed of a waveform (Composite) that would be equal to 0 during a long period and then has a short variation before going back to 0. This is a typical issue of qutip (and adams solver) as can be seen in the issues related to the previous PR and on this forum https://groups.google.com/g/qutip/c/slz4MCnkolw I think it's best to define the max_step from the shortest variation of the waveforms that compose a Pulse.

example of a code that fails:

import pulser
import pulser_simulation
seq = pulser.Sequence(pulser.Register.square(2, 5), pulser.AnalogDevice)
seq.declare_channel("ryd_glob", "rydberg_global")
seq.add(
    pulser.Pulse.ConstantDetuning(
        pulser.CompositeWaveform(
            pulser.ConstantWaveform(2500, 0.0),
            pulser.BlackmanWaveform(1000, np.pi),
            pulser.ConstantWaveform(500, 0.0),
            ),
        0,
        0,
        ),
    channel="ryd_glob",
)
seq.draw()
sim = pulser_simulation.QutipEmulator.from_sequence(seq)
sim.run().get_final_state()

image

To be discussed: With the new implementation, this will surely increase the number of time steps for any InterpolatedWaveform, CustomWaveform, BlackmanWaveform. I think it will make the computation more robust, which is what we want for this package.

a-corni commented 3 months ago

test_perf_sim.pdf Conclusion: no major changes on the computation time. I think that the RampWaveform is the worst case scenario for this condition on the max_step

a-corni commented 3 months ago

Should I add the "false positive" simulation in the tests ? In tests/test_simresults.py ? Basically just checking that the final state is not equal to the ground state.

HGSilveri commented 3 months ago

Should I add the "false positive" simulation in the tests ? In tests/test_simresults.py ? Basically just checking that the final state is not equal to the ground state.

Hahaha you read my mind

a-corni commented 3 months ago

Should I add the "false positive" simulation in the tests ? In tests/test_simresults.py ? Basically just checking that the final state is not equal to the ground state.

Hahaha you read my mind

mind-blown