Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update TF version check to check Keras (#5488)
**Context:** If you `pip install tensorflow` (or update) following their most recent Tensorflow release, you get Keras 3 instead of Keras 2. Currently the `KerasLayer` in the `qnn` module isn't compatible with Keras 3. **Description of the Change:** We add a check to make sure that users have the correct version of Keras. If we find they are using Keras 3, the error message directs to the official documentation for running Keras 2 instead, see [here](https://keras.io/getting_started/#tensorflow--keras-2-backwards-compatibility). **Testing:** The unit-testing for this behaviour isn't great, because it just mocks the result of checking the versions (i.e. changes the value of `CORRECT_TF_VERSION` and `CORRECT_KERAS_VERSION`) and checks that the error is raised, rather than checking that the version checks themselves work as expected. The behaviour occurs on import, so a workaround to test the behaviour isn't, to my knowledge, straightforward. I've tested locally by modifying my testing environment, and confirmed that: 1. With only `Keras 2` installed, the code runs 2. With only `Keras 3` installed, an error directs to the Keras official documentation on using Keras 2 instead 3. With `tf_keras` and `Keras 3`, but without the correct variable set to use legacy Keras, an error directs to the Keras official documentation on using `Keras 2` instead (which includes info about setting the correct global variable) 4. With `tf_keras` and `Keras 3`, and the variable to use legacy Keras set as instructed in the docs, the code runs **Benefits:** People won't get weird errors if they install/upgrade TensorFlow and try to use the QNN module. Instead, a clear error will tell them that the problem is their environment setup and how to fix it. **Possible Drawbacks:** This is short-time solution and doesn't fix the underlying problem that we aren't currently compatible with Keras 3. That is tracked in a story [here](https://app.shortcut.com/xanaduai/story/59479/update-keraslayer-to-support-keras3) for later.
- Loading branch information