Skip to content

Commit

Permalink
Upgrade TF version from 2.7 to 2.11 (tensorflow#749)
Browse files Browse the repository at this point in the history
* Upgrade bazel version to 5.1.0 for building with TFv2.11.0

* Upgrade to TF v2.11

* Bump up the version of numpy to v1.24.2

* Format

* Fix tf.Variable inside tf.while_loop issues inside optimizers

* Format optimizers

* Upgrade the latest gym for notebook tutorial.

* Fix tutorial error

* Fix tutorial errors

* Upgrade seaborn version to 0.12.0

* Fix typo

* Remove debug print

* Update ci_install bazel version, removed duplicated code lines.
  • Loading branch information
jaeyoo authored Mar 20, 2023
1 parent f46056d commit 20cfde5
Show file tree
Hide file tree
Showing 62 changed files with 1,278 additions and 944 deletions.
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.2
5.1.0
10 changes: 5 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

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

EIGEN_COMMIT = "12e8d57108c50d8a63605c6eb0144c838c128337"
EIGEN_SHA256 = "f689246e342c3955af48d26ce74ac34d21b579a00675c341721a735937919b02"
EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3"


http_archive(
Expand Down Expand Up @@ -33,10 +33,10 @@ http_archive(

http_archive(
name = "org_tensorflow",
sha256 = "249b48ddee927801c7a4f8e5442cf1a3c860f6f46b85a2ff7a78b501507dd561",
strip_prefix = "tensorflow-2.7.0",
sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff",
strip_prefix = "tensorflow-2.11.0",
urls = [
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.7.0.zip",
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.zip",
],
)

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Some notes on benchmark configuration:

For example, to benchmark a dense depth-10 Clifford circuit over 5 qubits call:
```
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \
--cxxopt="-msse3" --cxxopt="-msse4" \
benchmarks/scripts:benchmark_clifford_circuit -- \
--n_moments 5 --n_qubits 4 \
Expand All @@ -39,7 +39,7 @@ benchmarks/scripts/reports/CliffordBenchmarks.benchmark_clifford_circuit_4_5_1
To benchmark the parameter shift differentiation method on a random depth-10 4-qubit circuit with 10 parameters call, where the circuit will be differentiated
over 50 trials, each time over a batch of 10 circuits.
```
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \
--cxxopt="-msse3" --cxxopt="-msse4" \
benchmarks/scripts:benchmark_op_gradients -- \
--n_moments 10 --n_qubits 4 --n_symbols 10 \
Expand Down
7 changes: 3 additions & 4 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ if [[ "$PIP_MANYLINUX2010" == "0" ]]; then
write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain"
fi


write_to_bazelrc "build --experimental_repo_remote_exec"
write_to_bazelrc "build --spawn_strategy=standalone"
write_to_bazelrc "build --strategy=Genrule=standalone"
write_to_bazelrc "build --experimental_repo_remote_exec"
write_to_bazelrc "build -c opt"
write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=0\""
write_to_bazelrc "build --cxxopt=\"-std=c++14\""
write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\""
write_to_bazelrc "build --cxxopt=\"-std=c++17\""


if is_windows; then
Expand Down
21 changes: 11 additions & 10 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ 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.7.0. To ensure compatibility we use `bazel` version 3.7.2. To remove any existing version of Bazel:
Our latest source builds use TensorFlow 2.11.0. To ensure compatibility we use `bazel` version 5.1.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 3.7.2:
Download and install `bazel` version 5.1.0:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/3.7.2/bazel_3.7.2-linux-x86_64.deb
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/5.1.0/bazel_5.1.0-linux-x86_64.deb
</code>
<code class="devsite-terminal">sudo dpkg -i bazel_3.7.2-linux-x86_64.deb</code>
<code class="devsite-terminal">sudo dpkg -i bazel_5.1.0-linux-x86_64.deb</code>
</pre>
<!-- common_typos_enable -->

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

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

Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
Expand All @@ -141,7 +141,8 @@ 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.19.5</code>
<code class="devsite-terminal">pip install numpy==1.24.2</code>
<code class="devsite-terminal">pip install packaging requests</code>
</pre>
<!-- common_typos_enable -->

Expand All @@ -153,11 +154,11 @@ Configure the TensorFlow build. When asked for the Python interpreter and librar
</pre>
<!-- common_typos_enable -->

Build the TensorFlow package:
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`):

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
<code class="devsite-terminal">bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package</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" //tensorflow/tools/pip_package:build_pip_package</code>
</pre>
<!-- common_typos_enable -->

Expand Down Expand Up @@ -193,7 +194,7 @@ Build the TensorFlow Quantum pip package and install:
<!-- 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="-D_GLIBCXX_USE_CXX11_ABI=0" release:build_pip_package</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>
</pre>
Expand Down
29 changes: 19 additions & 10 deletions docs/tutorials/barren_plateaus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"cellView": "form",
"colab": {},
Expand Down Expand Up @@ -89,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -112,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -125,7 +125,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand All @@ -150,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -202,7 +202,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -278,7 +278,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -327,7 +327,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -399,7 +399,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -455,7 +455,7 @@
},
{
"cell_type": "code",
"execution_count": 0,
"execution_count": null,
"metadata": {
"colab": {},
"colab_type": "code",
Expand Down Expand Up @@ -511,6 +511,15 @@
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]"
},
"vscode": {
"interpreter": {
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
}
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 20cfde5

Please sign in to comment.