diff --git a/hls4ml/__init__.py b/hls4ml/__init__.py index 81b285955..e3a7247b0 100644 --- a/hls4ml/__init__.py +++ b/hls4ml/__init__.py @@ -1,4 +1,34 @@ -from hls4ml import converters, report, utils # noqa: F401 +# Temporary workaround for QKeras installation requirement, will be removed after 1.0.0 +def maybe_install_qkeras(): + import subprocess + import sys + + QKERAS_PKG_NAME = 'QKeras' + # QKERAS_PKG_SOURCE = QKERAS_PKG_NAME + QKERAS_PKG_SOURCE = 'qkeras@git+https://github.com/fastmachinelearning/qkeras.git' + + def pip_list(): + p = subprocess.run([sys.executable, '-m', 'pip', 'list'], check=True, capture_output=True) + return p.stdout.decode() + + def pip_install(package): + subprocess.check_call([sys.executable, '-m', 'pip', 'install', package]) + + all_pkgs = pip_list() + if QKERAS_PKG_NAME not in all_pkgs: + print('QKeras installation not found, installing one...') + pip_install(QKERAS_PKG_SOURCE) + print('QKeras installed.') + + +try: + maybe_install_qkeras() +except Exception: + print('Could not find QKeras installation, make sure you have QKeras installed.') + +# End of workaround + +from hls4ml import converters, report, utils # noqa: F401, E402 try: from ._version import version as __version__ diff --git a/setup.cfg b/setup.cfg index dc1075d9f..0b81e7b59 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,7 +29,6 @@ install_requires = pydigitalwavetools==1.1 pyparsing pyyaml - qkeras@git+https://github.com/google/qkeras.git tabulate tensorflow>=2.8.0,<=2.14.1 tensorflow-model-optimization<=0.7.5