Skip to content

Feat: Add graceful import handling for QML frameworks #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KaranSinghDev
Copy link

@KaranSinghDev KaranSinghDev commented May 1, 2025

Hi,
When setting up the environment, especially with potential conflicts between base libraries like PyTorch and TensorFlow, installing and importing all required QML frameworks (PennyLane, TFQ, TorchQuantum) can be challenging. Currently, if one framework needed by a specific model fails to import, the benchmark script might crash unexpectedly.

This PR makes the main benchmark script (scripts/run_hyperparameter_search.py) more robust by:

  1. Wrapping the dynamic model loading in try...except blocks to specifically catch ImportErrors.
  2. Checking the error message to identify if a known QML framework (PennyLane, TFQ, TQ) is missing.
  3. Printing an informative error message and exiting gracefully if the required framework for the selected model is not installed or fails to import.
  4. Adding informational checks at the start of the script to log which QML frameworks are detected in the environment.
  5. Cleaning requirements.txt to remove QML frameworks, reinforcing that they require separate, careful installation based on user needs and environment compatibility.

The aim while making the changes was to assist users to run benchmarks more reliably, receiving clear feedback if a specific model cannot run due to a missing framework, rather than encountering an unexpected crash. It makes the tool more resilient to the complexities of multi-framework environments.

Amazing work by the way.

@mariaschuld
Copy link
Collaborator

Hey @KaranSinghDev,

Sorry for the delay, and thanks for contributing - that's very much appreciated! You also caught a duplicate pandas dependency, which I removed.

As for import errors, let me understand the issue a bit better! As far as I see, the two ML libraries we depend on are PennyLane and Scikit-Learn, which are in the requirements. There is one script to generate MNIST data with a dependency on Keras and Pytorch (which is not an optimal design choice, and should better only use one of them, but it was convenient to get the dataset from keras and manipulate it with PyTorch). These libraries would have to be installed if a user needs to run this particular script, but it is not crucial to the library itself.

Since PennyLane is a core dependency, should it not assumed to be installed? And if a user builds models in other frameworks, like TFQ (TensorFlow Quantum?) and PQ (?), would we not expect them to install these libraries?

I guess I am a bit confused what your use case is for the import errors, and would love to hear some more details...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants