Skip to content

Commit

Permalink
Upgrade to TF v2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyoo committed Mar 15, 2023
1 parent e317872 commit 26fa2df
Show file tree
Hide file tree
Showing 53 changed files with 352 additions and 282 deletions.
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
19 changes: 10 additions & 9 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 @@ -142,6 +142,7 @@ Be sure the virtual environment you created in step 2 is activated. Then, instal
<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 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
2 changes: 1 addition & 1 deletion docs/tutorials/barren_plateaus.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@
" # Prep the inputs as tensors\n",
" circuit_tensor = tfq.convert_to_tensor(circuits)\n",
" values_tensor = tf.convert_to_tensor(\n",
" np.random.uniform(0, 2 * np.pi, (n_circuits, 1)).astype(np.float32))\n",
" np.random.uniform(0, 2 * np.pi, (n_circuits, 1)).astype(float))\n",
"\n",
" # Use TensorFlow GradientTape to track gradients.\n",
" with tf.GradientTape() as g:\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/gradients.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
"outputs": [],
"source": [
"# Make input_points = [batch_size, 1] array.\n",
"input_points = np.linspace(0, 5, 200)[:, np.newaxis].astype(np.float32)\n",
"input_points = np.linspace(0, 5, 200)[:, np.newaxis].astype(float)\n",
"exact_outputs = expectation_calculation(my_circuit,\n",
" operators=pauli_x,\n",
" symbol_names=['alpha'],\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/tutorials/hello_many_worlds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@
},
"outputs": [],
"source": [
"batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=np.float32)"
"batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=float)"
]
},
{
Expand Down Expand Up @@ -739,10 +739,10 @@
"outputs": [],
"source": [
"# The command input values to the classical NN.\n",
"commands = np.array([[0], [1]], dtype=np.float32)\n",
"commands = np.array([[0], [1]], dtype=float)\n",
"\n",
"# The desired Z expectation value at output of quantum circuit.\n",
"expected_outputs = np.array([[1], [-1]], dtype=np.float32)"
"expected_outputs = np.array([[1], [-1]], dtype=float)"
]
},
{
Expand Down Expand Up @@ -1108,10 +1108,10 @@
"operator_data = tfq.convert_to_tensor([[cirq.X(qubit)], [cirq.Z(qubit)]])\n",
"\n",
"# The command input values to the classical NN.\n",
"commands = np.array([[0], [1]], dtype=np.float32)\n",
"commands = np.array([[0], [1]], dtype=float)\n",
"\n",
"# The desired expectation value at output of quantum circuit.\n",
"expected_outputs = np.array([[1], [-1]], dtype=np.float32)"
"expected_outputs = np.array([[1], [-1]], dtype=float)"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@
"source": [
"THRESHOLD = 0.5\n",
"\n",
"x_train_bin = np.array(x_train_nocon > THRESHOLD, dtype=np.float32)\n",
"x_test_bin = np.array(x_test_small > THRESHOLD, dtype=np.float32)"
"x_train_bin = np.array(x_train_nocon > THRESHOLD, dtype=float)\n",
"x_test_bin = np.array(x_test_small > THRESHOLD, dtype=float)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials/quantum_reinforcement_learning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@
" actions = np.concatenate([ep['actions'] for ep in episodes])\n",
" rewards = [ep['rewards'] for ep in episodes]\n",
" returns = np.concatenate([compute_returns(ep_rwds, gamma) for ep_rwds in rewards])\n",
" returns = np.array(returns, dtype=np.float32)\n",
" returns = np.array(returns, dtype=float)\n",
"\n",
" id_action_pairs = np.array([[i, a] for i, a in enumerate(actions)])\n",
" \n",
Expand Down Expand Up @@ -1456,9 +1456,9 @@
" training_batch = np.random.choice(replay_memory, size=batch_size)\n",
" Q_learning_update(np.asarray([x['state'] for x in training_batch]),\n",
" np.asarray([x['action'] for x in training_batch]),\n",
" np.asarray([x['reward'] for x in training_batch], dtype=np.float32),\n",
" np.asarray([x['reward'] for x in training_batch], dtype=float),\n",
" np.asarray([x['next_state'] for x in training_batch]),\n",
" np.asarray([x['done'] for x in training_batch], dtype=np.float32),\n",
" np.asarray([x['done'] for x in training_batch], dtype=float),\n",
" model, gamma, n_actions)\n",
" \n",
" # Update target model\n",
Expand Down
6 changes: 3 additions & 3 deletions release/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ def finalize_options(self):
REQUIRED_PACKAGES = [
'cirq-core==0.13.1', 'cirq-google>=0.13.1', 'sympy == 1.8',
'googleapis-common-protos==1.52.0', 'google-api-core==1.21.0',
'google-auth==1.18.0', 'protobuf==3.17.3'
'google-auth==1.18.0', 'protobuf==3.19.4'
]

# placed as extra to not have required overwrite existing nightly installs if
# they exist.
EXTRA_PACKAGES = ['tensorflow == 2.7.0']
CUR_VERSION = '0.7.2'
EXTRA_PACKAGES = ['tensorflow == 2.11.0']
CUR_VERSION = '0.7.3'


class BinaryDistribution(Distribution):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ numpy==1.19.5 # TensorFlow can detect if it was built against other versions.
nbformat==4.4.0
pylint==2.4.4
yapf==0.28.0
tensorflow==2.7.0
tensorflow==2.11.0
# Needed for compatibility with cirq program protos.
googleapis-common-protos==1.52.0
google-api-core==1.21.0
google-auth==1.18.0
google-api-python-client==1.8.0
grpcio==1.34.1
protobuf==3.17.3
protobuf==3.19.4
4 changes: 2 additions & 2 deletions scripts/benchmark_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ==============================================================================
echo "Testing benchmarks.";
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...))
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...))
exit_code=$?

if [ "$exit_code" == "0" ]; then
Expand All @@ -26,5 +26,5 @@ else
fi

echo "Running preconfigured benchmarks.";
bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"}
bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"}
bazel_run benchmarks/scripts:benchmark_clifford_circuit -- --op_density 1 --n_moments 10 --n_qubits 4
2 changes: 1 addition & 1 deletion scripts/build_pip_package_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install -r requirements.txt
# cd tensorflow_quantum
echo "Y\n" | ./configure.sh

bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package
bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package
rm /tmp/tensorflow_quantum/* || echo ok
bazel-bin/release/build_pip_package /tmp/tensorflow_quantum/
pip install -U /tmp/tensorflow_quantum/*.whl
6 changes: 3 additions & 3 deletions scripts/msan_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
# limitations under the License.
# ==============================================================================
echo "Testing All Bazel cc_tests with msan.";
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
--cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" \
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
--cxxopt="-g" --cxxopt="-O0" \
--notest_keep_going --test_output=errors \
//tensorflow_quantum/core/src:all && \
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
--cxxopt="-mavx2" --cxxopt="-mavx" --cxxopt="-mfma" \
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
--cxxopt="-g" --cxxopt="-O0" \
--notest_keep_going --test_output=errors \
//tensorflow_quantum/core/src:all && \
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
--cxxopt="-g" --cxxopt="-O0" \
--notest_keep_going --test_output=errors \
Expand Down
4 changes: 2 additions & 2 deletions scripts/test_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
# ==============================================================================
echo "Testing All Bazel py_test and cc_tests.";
test_outputs=$(bazel test -c opt --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --notest_keep_going --test_output=errors //tensorflow_quantum/...)
test_outputs=$(bazel test -c opt --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --notest_keep_going --test_output=errors //tensorflow_quantum/...)
exit_code=$?
if [ "$exit_code" == "0" ]; then
echo "Testing Complete!";
Expand All @@ -23,4 +23,4 @@ else
echo "Testing failed, please correct errors before proceeding."
echo "{$test_outputs}"
exit 64;
fi
fi
6 changes: 3 additions & 3 deletions scripts/test_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# limitations under the License.
# ==============================================================================
echo "Testing all Benchmarks.";
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)
# test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all))
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)
# test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all))
bench_outputs=$()
# bench_outputs=$(bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //benchmarks/scripts:benchmark_clifford_circuit)
# bench_outputs=$(bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //benchmarks/scripts:benchmark_clifford_circuit)
exit_code=$?
if [ "$exit_code" == "0" ]; then
echo "Testing Complete!";
Expand Down
Loading

0 comments on commit 26fa2df

Please sign in to comment.