Skip to content

Commit

Permalink
[WIP] Upgrade to tf2.15. (#809)
Browse files Browse the repository at this point in the history
* [WIP] Upgrade to tf2.15.

* format and wheel test fixes.

* Version bump again for wheel test.

* Back to python3.10

* remove setup.py deps.

* more format fixes.

* yet more format.

* C++ code formats.

* Tutorial fix p1.

* Tutorial fix p2.

* Tutorials p3.

* Add updated install instructions and tutorial install versions.

* final cleanup

* add setup.py

---------

Co-authored-by: root <[email protected]>
  • Loading branch information
MichaelBroughton and zx-zx authored May 16, 2024
1 parent f56257b commit b98d142
Show file tree
Hide file tree
Showing 86 changed files with 824 additions and 640 deletions.
3 changes: 2 additions & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
5.3.0
6.5.0
# NOTE: Update Bazel version in tensorflow/tools/ci_build/release/common.sh.oss
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install Lint tools
run: pip install --upgrade pip setuptools; pip install -r requirements.txt;
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install Format tools
run: pip install --upgrade pip setuptools; pip install -r requirements.txt; sudo apt-get install -y clang-format-6.0
Expand All @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install Bazel on CI
run: ./scripts/ci_install.sh
Expand All @@ -61,7 +61,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install Bazel on CI
run: ./scripts/ci_install.sh
Expand All @@ -79,7 +79,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install Bazel on CI
run: ./scripts/ci_install.sh
Expand All @@ -97,7 +97,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.9'
python-version: '3.10'
architecture: 'x64'
- name: Install notebook dependencies
run: pip install --upgrade pip seaborn==0.10.0
Expand Down
37 changes: 22 additions & 15 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# This file includes external dependencies that are required to compile the
# TensorFlow op.



load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3"


EIGEN_COMMIT = "aa6964bf3a34fd607837dd8123bc42465185c4f8"


http_archive(
Expand All @@ -16,7 +19,6 @@ cc_library(
visibility = ["//visibility:public"],
)
""",
sha256 = EIGEN_SHA256,
strip_prefix = "eigen-{commit}".format(commit = EIGEN_COMMIT),
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/gitlab.com/libeigen/eigen/-/archive/{commit}/eigen-{commit}.tar.gz".format(commit = EIGEN_COMMIT),
Expand All @@ -27,35 +29,41 @@ cc_library(
http_archive(
name = "qsim",
sha256 = "b9c1eba09a885a938b5e73dfc2e02f5231cf3b01d899415caa24769346a731d5",
# patches = [
# "//third_party/tf:qsim.patch",
# ],
strip_prefix = "qsim-0.13.3",
urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.13.3.zip"],
)

http_archive(
name = "org_tensorflow",
sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff",
strip_prefix = "tensorflow-2.11.0",
patches = [
"//third_party/tf:tf.patch",
],
# sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff",
strip_prefix = "tensorflow-2.15.0",
urls = [
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.zip",
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.15.0.zip",
],
)


load("@org_tensorflow//tensorflow:workspace3.bzl", "workspace")
load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")

workspace()
tf_workspace3()

load("@org_tensorflow//tensorflow:workspace2.bzl", "workspace")
load("@org_tensorflow//tensorflow:workspace2.bzl", "tf_workspace2")

workspace()
tf_workspace2()

load("@org_tensorflow//tensorflow:workspace1.bzl", "workspace")
load("@org_tensorflow//tensorflow:workspace1.bzl", "tf_workspace1")

workspace()
tf_workspace1()

load("@org_tensorflow//tensorflow:workspace0.bzl", "workspace")
load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")

workspace()
tf_workspace0()

load("//third_party/tf:tf_configure.bzl", "tf_configure")

Expand All @@ -72,4 +80,3 @@ bind(
name = "six",
actual = "@six_archive//:six",
)

30 changes: 15 additions & 15 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ done


# Check if it's installed
if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]]; then
echo 'Using installed tensorflow'
else
# Uninstall CPU version if it is installed.
if [[ $(pip show tensorflow-cpu) == *tensorflow-cpu* ]]; then
echo 'Already have tensorflow non-gpu installed. Uninstalling......\n'
pip uninstall tensorflow
elif [[ $(pip show tf-nightly-cpu) == *tf-nightly-cpu* ]]; then
echo 'Already have tensorflow non-gpu installed. Uninstalling......\n'
pip uninstall tf-nightly
fi
# Install GPU version
echo 'Installing tensorflow .....\n'
pip install tensorflow
fi
# if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]]; then
# echo 'Using installed tensorflow'
# else
# # Uninstall CPU version if it is installed.
# if [[ $(pip show tensorflow-cpu) == *tensorflow-cpu* ]]; then
# echo 'Already have tensorflow non-gpu installed. Uninstalling......\n'
# pip uninstall tensorflow
# elif [[ $(pip show tf-nightly-cpu) == *tf-nightly-cpu* ]]; then
# echo 'Already have tensorflow non-gpu installed. Uninstalling......\n'
# pip uninstall tf-nightly
# fi
# # Install GPU version
# echo 'Installing tensorflow .....\n'
# pip install tensorflow
# fi



Expand Down
33 changes: 16 additions & 17 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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.7, 3.8, and 3.9 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).
TensorFlow Quantum is supported on Python 3.9, 3.10, and 3.11 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).

## Pip package

### Requirements

* pip 19.0 or later (requires `manylinux2010` support)
* [TensorFlow == 2.11.0](https://www.tensorflow.org/install/pip)
* pip 19.0 or later (requires `manylinux2014` support)
* [TensorFlow == 2.15.0](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.
Expand All @@ -27,7 +27,7 @@ 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.11.0</code>
<code class="devsite-terminal">pip3 install tensorflow==2.15.0</code>
</pre>
<!-- common_typos_enable -->

Expand Down Expand Up @@ -57,13 +57,13 @@ The following steps are tested for Ubuntu-like systems.

### 1. Set up a Python 3 development environment

First we need the Python 3.8 development tools.
First we need the Python 3.10 development tools.
<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">sudo apt update</code>
<code class="devsite-terminal">sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3.8</code>
<code class="devsite-terminal">sudo apt install python3.8 python3.8-dev python3.8-venv python3-pip</code>
<code class="devsite-terminal">python3.8 -m pip install --upgrade pip</code>
<code class="devsite-terminal">sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3.10</code>
<code class="devsite-terminal">sudo apt install python3.10 python3.10-dev python3.10-venv python3-pip</code>
<code class="devsite-terminal">python3.10 -m pip install --upgrade pip</code>
</pre>
<!-- common_typos_enable -->

Expand All @@ -72,7 +72,7 @@ First we need the Python 3.8 development tools.
Go to your workspace directory and make a virtual environment for TFQ development.
<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">python3.8 -m venv quantum_env</code>
<code class="devsite-terminal">python3.10 -m venv quantum_env</code>
<code class="devsite-terminal">source quantum_env/bin/activate</code>
</pre>
<!-- common_typos_enable -->
Expand All @@ -84,21 +84,20 @@ As noted in the TensorFlow
guide, the <a href="https://bazel.build/" class="external">Bazel</a>
build system will be required.

Our latest source builds use TensorFlow 2.11.0. To ensure compatibility we use `bazel` version 5.3.0. To remove any existing version of Bazel:

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:
<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">sudo apt-get remove bazel</code>
</pre>
<!-- common_typos_enable -->

Download and install `bazel` version 5.3.0:
Download and install `bazel` version 6.5.0:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/6.5.0/bazel_6.5.0-linux-x86_64.deb
</code>
<code class="devsite-terminal">sudo dpkg -i bazel_5.3.0-linux-x86_64.deb</code>
<code class="devsite-terminal">sudo dpkg -i bazel_6.5.0-linux-x86_64.deb</code>
</pre>
<!-- common_typos_enable -->

Expand All @@ -122,7 +121,7 @@ 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.11.0.
guide, see the link for further details. TensorFlow Quantum is compatible with TensorFlow version&nbsp;2.15.0.

Download the
<a href="https://github.com/tensorflow/tensorflow" class="external">TensorFlow source code</a>:
Expand All @@ -131,7 +130,7 @@ Download the
<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.11.0</code>
<code class="devsite-terminal">git checkout v2.15.0</code>
</pre>

Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
Expand All @@ -141,7 +140,7 @@ Be sure the virtual environment you created in step 2 is activated. Then, instal
<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.24.2</code>
<code class="devsite-terminal">pip install numpy==1.23.5</code>
<code class="devsite-terminal">pip install packaging requests</code>
</pre>
<!-- common_typos_enable -->
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/barren_plateaus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/gradients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/hello_many_worlds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down Expand Up @@ -255,7 +255,7 @@
"# Create a circuit on these qubits using the parameters you created above.\n",
"circuit = cirq.Circuit(\n",
" cirq.rx(a).on(q0),\n",
" cirq.ry(b).on(q1), cirq.CNOT(control=q0, target=q1))\n",
" cirq.ry(b).on(q1), cirq.CNOT(q0, q1))\n",
"\n",
"SVGCircuit(circuit)"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/noise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2"
"!pip install tensorflow==2.15.0 tensorflow-quantum==0.7.2"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/qcnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down Expand Up @@ -554,7 +554,7 @@
" source_basis_selector = one_qubit_unitary(source_qubit, symbols[3:6])\n",
" pool_circuit.append(sink_basis_selector)\n",
" pool_circuit.append(source_basis_selector)\n",
" pool_circuit.append(cirq.CNOT(control=source_qubit, target=sink_qubit))\n",
" pool_circuit.append(cirq.CNOT(source_qubit, sink_qubit))\n",
" pool_circuit.append(sink_basis_selector**-1)\n",
" return pool_circuit"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/quantum_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
}
],
"source": [
"!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2"
"!pip install tensorflow==2.15.0 tensorflow-quantum==0.7.2"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/quantum_reinforcement_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0"
"!pip install tensorflow==2.15.0"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/research_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"outputs": [],
"source": [
"!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2 tensorboard_plugin_profile==2.4.0"
"!pip install tensorflow==2.15.0 tensorflow-quantum==0.7.2 tensorboard_plugin_profile==2.4.0"
]
},
{
Expand Down Expand Up @@ -155,8 +155,8 @@
"source": [
"def generate_circuit(qubits):\n",
" \"\"\"Generate a random circuit on qubits.\"\"\"\n",
" random_circuit = cirq.generate_boixo_2018_supremacy_circuits_v2(\n",
" qubits, cz_depth=2, seed=1234)\n",
" random_circuit = cirq.experiments.random_rotations_between_grid_interaction_layers_circuit(\n",
" qubits, depth=2)\n",
" return random_circuit\n",
"\n",
"def generate_data(circuit, n_samples):\n",
Expand Down
Loading

0 comments on commit b98d142

Please sign in to comment.