qiskit-community / qiskit-dynamics

Tools for building and solving models of quantum systems in Qiskit
https://qiskit-community.github.io/qiskit-dynamics/
Apache License 2.0
105 stars 61 forks source link

Add warning if digital carrier exceeds Nyquist frequency in pulse -> signal conversion #242

Closed DanPuzzuoli closed 1 year ago

DanPuzzuoli commented 1 year ago

Summary

Closes #241

A warning is added to the pulse -> signal converter if the digital carrier frequency (resulting from SetFrequency and ShiftFrequency instructions) exceeds the Nyquist frequency set by the sample size dt.

Details and comments

The warning is suppressed if the conversion is called within JAX tracing, as in this case the boolean function np.abs(frequency_shift) > 0.5 / dt cannot be evaluated.

A test has been added, and @nkanazawa1989 I've verified that the warning is raised in your example that motivated this PR.

DanPuzzuoli commented 1 year ago

Thanks @DanPuzzuoli this is really helpful improvement. I was thinking shift and set frequency were directly applied to the analog carrier, and had trouble with interpretation of weird simulation results. I think I am not only person suffering this problem :)

The warning is suppressed if the conversion is called within JAX tracing, as in this case the boolean function np.abs(frequency_shift) > 0.5 / dt cannot be evaluated.

This means the warning is also raised at run time even with the JAX backend? Then this PR looks good to me.

The error will not be raised ever if the converter is called within a traced function. For now this probably won't impact any users; it will still be raised when using the DynamicsBackend using JAX as you are in your notebook.

As an aside: This is an unfortunate element of the way JAX works - you can't have warnings/errors that depend on the value of variables that are being traced. Branching logic that depends on the value of a variable will cause an error during tracing, and once compiled, the original code is no longer executed anyway, so no warnings can be raised there.