Skip to content

Latest commit

 

History

History
203 lines (151 loc) · 7.19 KB

install.md

File metadata and controls

203 lines (151 loc) · 7.19 KB

Install TensorFlow Quantum

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 package

Requirements

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 package

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

Build from source

The following steps are tested for Ubuntu-like systems.

1. Set up a Python 3 development environment

  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

2. Create a virtual environment

  python3 -m venv tfq_env
  source tfq_env/bin/activate

3. Install Bazel

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

4. Build TensorFlow from source

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

5. Download TensorFlow Quantum

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

6. Build the TensorFlow Quantum pip package

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.