Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from Quantum-TII/checkversion
Browse files Browse the repository at this point in the history
allowing tensorflow version flexibility when installing from source
  • Loading branch information
scarrazza authored May 17, 2021
2 parents 2e5e6ac + f81f045 commit f6ac02d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Patch requirements
run: |
TFSTRING=`grep "tensorflow" requirements.txt`
TFVERSION=`echo $TFSTRING | cut -f2 -d "<" | cut -f2 -d "="`
# ugly sed because macos does not accept -i
sed "s/$TFSTRING/tensorflow==$TFVERSION/" requirements.txt > new_requirements.txt
mv new_requirements.txt requirements.txt
- name: Install OS requirements
uses: mstksg/get-package@v1
with:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ The qibotf backend documentation is available at [qibo.readthedocs.io](https://q

Here a compatibility matrix for the qibotf versions:

| qibotf | tensorflow | OS Hardware |
|--------|------------|----------------------------|
| 0.0.2 | 2.5.0 | linux (cpu/gpu), mac (cpu) |
| 0.0.1 | 2.4.1 | linux (cpu/gpu), mac (cpu) |
| qibotf | tensorflow | OS Hardware |
|--------|----------------------------------|----------------------------|
| 0.0.2 | 2.5.0 for pip (>=2.2 for source) | linux (cpu/gpu), mac (cpu) |
| 0.0.1 | 2.4.1 for pip (>=2.2 for source) | linux (cpu/gpu), mac (cpu) |

## Citation policy

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Runtime requirements for qibotf

tensorflow==2.5.0
tensorflow>=2.2,<=2.5.0
20 changes: 18 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@
PACKAGE = "qibotf"


# extract tensorflow version
try:
import tensorflow as tf
TF_VERSION = tf.__version__
except:
raise ModuleNotFoundError('Please install TensorFlow before qibotf.')


# replace tensorflow placehold version in __init__.py
PLACEHOLDER = os.path.join("src", PACKAGE, "__init__.py.in")
VERSIONFILE = os.path.join("src", PACKAGE, "__init__.py")
with open(PLACEHOLDER, 'r') as f:
content = f.read()
content = content.replace('TF_VERSION', TF_VERSION)
with open(VERSIONFILE, 'w') as f:
f.write(content)


# Returns the version
def get_version():
""" Gets the version from the package's __init__ file
if there is some problem, let it happily fail """
VERSIONFILE = os.path.join("src", PACKAGE, "__init__.py")
initfile_lines = open(VERSIONFILE, "rt").readlines()
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
for line in initfile_lines:
Expand All @@ -24,7 +41,6 @@ def get_version():
return mo.group(1)



# Custom compilation step
class Build(_build_py):
def run(self):
Expand Down
2 changes: 1 addition & 1 deletion src/qibotf/__init__.py → src/qibotf/__init__.py.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.2-dev"

# tf version used during the compilation of custom operators
__target_tf_version__ = '2.5.0'
__target_tf_version__ = 'TF_VERSION'
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
"""Use ops in python."""
import tensorflow as tf
from qibotf import __target_tf_version__, __version__
if tf.__version__ < __target_tf_version__: # pragma: no cover
if tf.__version__ != __target_tf_version__: # pragma: no cover
raise RuntimeError(
f"qibotf {__version__} requires TensorFlow {__target_tf_version__}."
"Please upgrade TensorFlow or downgrade qibotf.")
elif tf.__version__ > __target_tf_version__: # pragma: no cover
raise RuntimeError(
f"qibotf {__version__} requires TensorFlow {__target_tf_version__}."
"Please upgrade qibotf or downgrade TensorFlow.")
f"qibotf and TensorFlow versions do not match. "
"Please check the qibotf documentation.")

from tensorflow.python.framework import load_library # pylint: disable=no-name-in-module
from tensorflow.python.platform import resource_loader # pylint: disable=no-name-in-module
Expand Down

0 comments on commit f6ac02d

Please sign in to comment.