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

Fix bug with carrier_freq being a JAX tracer if envelope is constant in Signal #247

Closed DanPuzzuoli closed 1 year ago

DanPuzzuoli commented 1 year ago

Summary

Closes #245

Details and comments

I ended up putting the carrier_freq == 0.0 check into a try block to solve this. It's not the prettiest solution, but it seemed to be the simplest and most concise. I originally had checks for JAX types, then checked if carrier_freq was a tracer, but it was actually awkward to implement this.

The current code is essentially equivalent to:

The awkwardness with directly implementing this is that the code also needs to work if JAX isn't installed, so the "if carrier_freq is not a JAX tracer object" is itself an awkward thing to check.

I've also added tests verifying the original issue is resolved: