Skip to content
Closed
96 changes: 50 additions & 46 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ There are a few ways to set up your environment to use TensorFlow Quantum (TFQ):
Python's pip package manager.
* Or build TensorFlow Quantum from source.

TensorFlow Quantum is supported on Python 3.9, 3.10, and 3.11 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).
TensorFlow Quantum is supported on Python 3.10, 3.11, and 3.12 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).

## Pip package

### Requirements

* pip 19.0 or later (requires `manylinux2014` support)
* [TensorFlow == 2.15.0](https://www.tensorflow.org/install/pip)
* [TensorFlow == 2.16.2](https://www.tensorflow.org/install/pip)

See the [TensorFlow install guide](https://www.tensorflow.org/install/pip) to
set up your Python development environment and an (optional) virtual environment.

Upgrade `pip` and install TensorFlow

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">pip3 install --upgrade pip</code>
<code class="devsite-terminal">pip3 install tensorflow==2.15.0</code>
<code class="devsite-terminal">pip3 install tensorflow==2.16.2</code>
</pre>
<!-- common_typos_enable -->

Expand All @@ -43,13 +42,13 @@ Install the latest stable release of TensorFlow Quantum:

Success: TensorFlow Quantum is now installed.

Nightly builds which might depend on newer version of TensorFlow can be installed with:
<!-- Nightly builds which might depend on newer version of TensorFlow can be installed with: -->

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">pip3 install -U tfq-nightly</code>
</pre>
<!-- common_typos_enable -->
<!-- <\!-- common_typos_disable -\-> -->
<!-- <pre class="devsite-click-to-copy"> -->
<!-- <code class="devsite-terminal">pip3 install -U tfq-nightly</code> -->
<!-- </pre> -->
<!-- <\!-- common_typos_enable -\-> -->

## Build from source

Expand Down Expand Up @@ -77,14 +76,18 @@ Go to your workspace directory and make a virtual environment for TFQ developmen
</pre>
<!-- common_typos_enable -->

Make sure that the virtual environment is activated for the rest of the steps
below, and every time you want to use TFQ in the future.

### 3. Install Bazel

As noted in the TensorFlow
[build from source](https://www.tensorflow.org/install/source#install_bazel)
guide, the <a href="https://bazel.build/" class="external">Bazel</a>
build system will be required.

Our latest source builds use TensorFlow 2.15.0. To ensure compatibility we use `bazel` version 6.5.0. To remove any existing version of Bazel:
Our latest source builds use TensorFlow 2.16.2. To ensure compatibility we use
`bazel` version 6.5.0. To remove any existing version of Bazel:
<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">sudo apt-get remove bazel</code>
Expand Down Expand Up @@ -120,82 +123,83 @@ Finally, confirm installation of the correct `bazel` version:

### 4. Build TensorFlow from source

Here we adapt instructions from the TensorFlow [build from source](https://www.tensorflow.org/install/source)
guide, see the link for further details. TensorFlow Quantum is compatible with TensorFlow version&nbsp;2.15.0.

Download the
<a href="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/tensorflow/tensorflow" class="external">TensorFlow source code</a>:
TensorFlow Quantum is compatible with TensorFlow version&nbsp;2.16.2. To build
TensorFlow from sources, download the <a
href="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/tensorflow/tensorflow" class="external">TensorFlow
source code</a> by cloning the git repository, then switch to the `r2.16`
branch:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">git clone https://github.com/tensorflow/tensorflow.git</code>
<code class="devsite-terminal">cd tensorflow</code>
<code class="devsite-terminal">git checkout v2.15.0</code>
<code class="devsite-terminal">git checkout r2.16</code>
</pre>

Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
Be sure the virtual environment you created in step 2 is activated, then follow
the TensorFlow instructions for how to [build and install the pip
package](https://www.tensorflow.org/install/source#build_and_install_the_pip_package)
on your system.

Note: it may take over an hour to build TensorFlow.

After the build is complete, and you have installed the pip package, leave the
TensorFlow directory before moving on to step 5:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1'</code>
<code class="devsite-terminal">pip install -U keras_applications --no-deps</code>
<code class="devsite-terminal">pip install -U keras_preprocessing --no-deps</code>
<code class="devsite-terminal">pip install numpy==1.23.5</code>
<code class="devsite-terminal">pip install packaging requests</code>
<code class="devsite-terminal">cd ..</code>
</pre>
<!-- common_typos_enable -->

Configure the TensorFlow build. When asked for the Python interpreter and library locations, be sure to specify locations inside your virtual environment folder. The remaining options can be left at default values.
### 5. Download TensorFlow Quantum

We use the standard [fork and pull request workflow](https://guides.github.com/activities/forking/) for contributions. After forking from the [TensorFlow Quantum](https://github.com/tensorflow/quantum) GitHub page, download the source of your fork and install the requirements:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">./configure</code>
<code class="devsite-terminal">git clone https://github.com/<var>username</var>/quantum.git</code>
<code class="devsite-terminal">cd quantum</code>
<code class="devsite-terminal">pip install -r requirements.txt</code>
</pre>
<!-- common_typos_enable -->

Build the TensorFlow package (Since TF v2.8, `_GLIBCXX_USE_CXX11_ABI` is set to 1, and the c++ codes are all compiled with `-std=c++17`):
### 6. Build and install TensorFlow Quantum

Be sure the virtual environment you created in step 2 is activated. Then, run
the command below to install the TensorFlow Quantum dependencies:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" //tensorflow/tools/pip_package:build_pip_package</code>
<code class="devsite-terminal">pip install -r requirements.txt</code>
</pre>
<!-- common_typos_enable -->

Note: It may take over an hour to build the package.

After the build is complete, install the package and leave the TensorFlow directory:
Next, use TensorFlow Quantum's `configure.sh` script to configure the TFQ
build:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg</code>
<code class="devsite-terminal">pip install /tmp/tensorflow_pkg/<var>name_of_generated_wheel</var>.whl</code>
<code class="devsite-terminal">cd ..</code>
<code class="devsite-terminal">./configure.sh</code>
</pre>
<!-- common_typos_enable -->

### 5. Download TensorFlow Quantum

We use the standard [fork and pull request workflow](https://guides.github.com/activities/forking/) for contributions. After forking from the [TensorFlow Quantum](https://github.com/tensorflow/quantum) GitHub page, download the source of your fork and install the requirements:
Now build TensorFlow Quantum:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">git clone https://github.com/<var>username</var>/quantum.git</code>
<code class="devsite-terminal">cd quantum</code>
<code class="devsite-terminal">pip install -r requirements.txt</code>
<code class="devsite-terminal">bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" release:build_pip_package</code>
</pre>
<!-- common_typos_enable -->


### 6. Build the TensorFlow Quantum pip package

Build the TensorFlow Quantum pip package and install:
After the build is complete, run the next two commands to create a Python
package for TensorFlow Quantum and write it to a temporary directory (we use
`/tmp/tfquantum/` in this example), then install it using pip:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">./configure.sh</code>
<code class="devsite-terminal">bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" release:build_pip_package</code>
<code class="devsite-terminal">bazel-bin/release/build_pip_package /tmp/tfquantum/</code>
<code class="devsite-terminal">python3 -m pip install /tmp/tfquantum/<var>name_of_generated_wheel</var>.whl</code>
<code class="devsite-terminal">pip install /tmp/tfquantum/<var>name_of_generated_wheel</var>.whl</code>
</pre>
<!-- common_typos_enable -->

Expand Down
75 changes: 43 additions & 32 deletions docs/tutorials/barren_plateaus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,65 +88,68 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "TorxE5tnkvb2"
},
"outputs": [],
"cell_type": "markdown",
"metadata": {},
"source": [
"!pip install tensorflow==2.15.0"
"Install TensorFlow and TensorFlow Quantum:"
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "FxkQA6oblNqI"
},
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Install TensorFlow Quantum:"
"# In Colab, you will be asked to restart the session after this finishes.\n",
"!pip install tensorflow==2.16.2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "saFHsRDpkvkH"
},
"metadata": {},
"outputs": [],
"source": [
"!pip install tensorflow-quantum==0.7.3"
"!pip install tensorflow-quantum==0.7.4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
"id": "4Ql5PW-ACO0J"
},
"metadata": {},
"outputs": [],
"source": [
"# Update package resources to account for version changes.\n",
"import importlib, pkg_resources\n",
"\n",
"importlib.reload(pkg_resources)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Configure the use of Keras 2:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Keras 2 must be selected before importing TensorFlow or TensorFlow Quantum:\n",
"import os\n",
"os.environ[\"TF_USE_LEGACY_KERAS\"] = \"1\""
]
},
{
"cell_type": "markdown",
"metadata": {
"colab_type": "text",
"id": "1PaclXeSrrMW"
"id": "F1L8h1YKUvIO"
},
"source": [
"Now import TensorFlow and the module dependencies:"
"Now import TensorFlow, TensorFlow Quantum, and other modules needed:"
]
},
{
Expand Down Expand Up @@ -509,13 +512,21 @@
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
},
"vscode": {
"interpreter": {
Expand All @@ -524,5 +535,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 4
}
Loading
Loading