There are a few ways to set up your environment to use TensorFlow Quantum (TFQ):
- The easiest way to learn and use TFQ requires no installation—run the TensorFlow Quantum tutorials directly in your browser using Google Colab.
- To use TensorFlow Quantum on a local machine, install the TFQ package using Python's pip package manager.
- Or build TensorFlow Quantum from source.
TensorFlow Quantum is supported on Python 3.6 and 3.7.
- pip 19.0 or later (requires
manylinux2010
support) - TensorFlow == 2.1
- Cirq 0.7
See the TensorFlow install guide to set up your Python development environment and an (optional) virtual environment.
Upgrade pip
and install TensorFlow and Cirq (these are not included as
dependencies):
pip3 install --upgrade pip
pip3 install tensorflow==2.1.0
pip3 install cirq==0.7.0
Install the latest stable release of TensorFlow Quantum:
pip3 install -U tensorflow-quantum
Success: TensorFlow Quantum is now installed.
Install the latest nightly version of TensorFlow Quantum:
pip3 install -U tfq-nightly
The following steps are tested for Ubuntu-like systems.
sudo apt update
sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3
sudo apt install python3 python3-dev python3-venv python3-pip
python3 -m pip install --upgrade pip
python3 -m venv tfq_env
source tfq_env/bin/activate
See the TensorFlow build from source guide to install the Bazel build system.
To ensure compatibility with TensorFlow, bazel
version 0.26.1 or lower is
required. To remove any existing version of Bazel:
sudo apt-get remove bazel
Then install Bazel version 0.26.0:
wget https://github.com/bazelbuild/bazel/releases/download/0.26.0/bazel_0.26.0-linux-x86_64.deb
sudo dpkg -i bazel_0.26.0-linux-x86_64.deb
Read the TensorFlow build from source guide for details. TensorFlow Quantum is compatible with TensorFlow version 2.1.
Download the TensorFlow source code:
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v2.1.0
Install the TensorFlow dependencies:
python3 -m pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1'
python3 -m pip install -U keras_applications --no-deps
python3 -m pip install -U keras_preprocessing --no-deps
Configure the TensorFlow build. The default Python location and Python library paths should point inside the virtual environment. The default options are recommended:
./configure
Verify that your Bazel version is correct:
bazel version
Build the TensorFlow package:
bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
Note: It may take over an hour to build the package.
After the build is complete, install the package:
./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
pip install /tmp/tensorflow_pkg/name_of_generated_wheel.whl
Download the TensorFlow Quantum source code and install the requirements:
cd ..
git clone https://github.com/tensorflow/quantum.git
cd quantum
python3 -m pip install -r requirements.txt
Verify your Bazel version (since it can auto-update):
bazel version
Build the TensorFlow Quantum pip package and install:
./configure.sh
bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" release:build_pip_package
bazel-bin/release/build_pip_package /tmp/tfquantum/
python3 -m pip install /tmp/tfquantum/name_of_generated_wheel.whl
Success: TensorFlow Quantum is now installed.