Skip to content

Commit 26fa2df

Browse files
committed
Upgrade to TF v2.11
1 parent e317872 commit 26fa2df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+352
-282
lines changed

WORKSPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

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

6-
EIGEN_COMMIT = "12e8d57108c50d8a63605c6eb0144c838c128337"
7-
EIGEN_SHA256 = "f689246e342c3955af48d26ce74ac34d21b579a00675c341721a735937919b02"
6+
EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e"
7+
EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3"
88

99

1010
http_archive(
@@ -33,10 +33,10 @@ http_archive(
3333

3434
http_archive(
3535
name = "org_tensorflow",
36-
sha256 = "249b48ddee927801c7a4f8e5442cf1a3c860f6f46b85a2ff7a78b501507dd561",
37-
strip_prefix = "tensorflow-2.7.0",
36+
sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff",
37+
strip_prefix = "tensorflow-2.11.0",
3838
urls = [
39-
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.7.0.zip",
39+
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.zip",
4040
],
4141
)
4242

benchmarks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Some notes on benchmark configuration:
2424

2525
For example, to benchmark a dense depth-10 Clifford circuit over 5 qubits call:
2626
```
27-
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \
27+
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \
2828
--cxxopt="-msse3" --cxxopt="-msse4" \
2929
benchmarks/scripts:benchmark_clifford_circuit -- \
3030
--n_moments 5 --n_qubits 4 \
@@ -39,7 +39,7 @@ benchmarks/scripts/reports/CliffordBenchmarks.benchmark_clifford_circuit_4_5_1
3939
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
4040
over 50 trials, each time over a batch of 10 circuits.
4141
```
42-
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \
42+
bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \
4343
--cxxopt="-msse3" --cxxopt="-msse4" \
4444
benchmarks/scripts:benchmark_op_gradients -- \
4545
--n_moments 10 --n_qubits 4 --n_symbols 10 \

configure.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ if [[ "$PIP_MANYLINUX2010" == "0" ]]; then
9999
write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain"
100100
fi
101101

102-
102+
write_to_bazelrc "build --experimental_repo_remote_exec"
103103
write_to_bazelrc "build --spawn_strategy=standalone"
104104
write_to_bazelrc "build --strategy=Genrule=standalone"
105-
write_to_bazelrc "build --experimental_repo_remote_exec"
106105
write_to_bazelrc "build -c opt"
107-
write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=0\""
108-
write_to_bazelrc "build --cxxopt=\"-std=c++14\""
106+
write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\""
107+
write_to_bazelrc "build --cxxopt=\"-std=c++17\""
109108

110109

111110
if is_windows; then

docs/install.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ As noted in the TensorFlow
8484
guide, the <a href="https://bazel.build/" class="external">Bazel</a>
8585
build system will be required.
8686

87-
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:
87+
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:
8888

8989
<!-- common_typos_disable -->
9090
<pre class="devsite-click-to-copy">
9191
<code class="devsite-terminal">sudo apt-get remove bazel</code>
9292
</pre>
9393
<!-- common_typos_enable -->
9494

95-
Download and install `bazel` version 3.7.2:
95+
Download and install `bazel` version 5.1.0:
9696

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

@@ -122,7 +122,7 @@ Finally, confirm installation of the correct `bazel` version:
122122
### 4. Build TensorFlow from source
123123

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

127127
Download the
128128
<a href="https://github.com/tensorflow/tensorflow" class="external">TensorFlow source code</a>:
@@ -131,7 +131,7 @@ Download the
131131
<pre class="devsite-click-to-copy">
132132
<code class="devsite-terminal">git clone https://github.com/tensorflow/tensorflow.git</code>
133133
<code class="devsite-terminal">cd tensorflow</code>
134-
<code class="devsite-terminal">git checkout v2.7.0</code>
134+
<code class="devsite-terminal">git checkout v2.11.0</code>
135135
</pre>
136136

137137
Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
@@ -142,6 +142,7 @@ Be sure the virtual environment you created in step 2 is activated. Then, instal
142142
<code class="devsite-terminal">pip install -U keras_applications --no-deps</code>
143143
<code class="devsite-terminal">pip install -U keras_preprocessing --no-deps</code>
144144
<code class="devsite-terminal">pip install numpy==1.19.5</code>
145+
<code class="devsite-terminal">pip install packaging requests</code>
145146
</pre>
146147
<!-- common_typos_enable -->
147148

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

156-
Build the TensorFlow package:
157+
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`):
157158

158159
<!-- common_typos_disable -->
159160
<pre class="devsite-click-to-copy">
160-
<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>
161+
<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>
161162
</pre>
162163
<!-- common_typos_enable -->
163164

@@ -193,7 +194,7 @@ Build the TensorFlow Quantum pip package and install:
193194
<!-- common_typos_disable -->
194195
<pre class="devsite-click-to-copy">
195196
<code class="devsite-terminal">./configure.sh</code>
196-
<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>
197+
<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>
197198
<code class="devsite-terminal">bazel-bin/release/build_pip_package /tmp/tfquantum/</code>
198199
<code class="devsite-terminal">python3 -m pip install /tmp/tfquantum/<var>name_of_generated_wheel</var>.whl</code>
199200
</pre>

docs/tutorials/barren_plateaus.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@
297297
" # Prep the inputs as tensors\n",
298298
" circuit_tensor = tfq.convert_to_tensor(circuits)\n",
299299
" values_tensor = tf.convert_to_tensor(\n",
300-
" np.random.uniform(0, 2 * np.pi, (n_circuits, 1)).astype(np.float32))\n",
300+
" np.random.uniform(0, 2 * np.pi, (n_circuits, 1)).astype(float))\n",
301301
"\n",
302302
" # Use TensorFlow GradientTape to track gradients.\n",
303303
" with tf.GradientTape() as g:\n",

docs/tutorials/gradients.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
"outputs": [],
371371
"source": [
372372
"# Make input_points = [batch_size, 1] array.\n",
373-
"input_points = np.linspace(0, 5, 200)[:, np.newaxis].astype(np.float32)\n",
373+
"input_points = np.linspace(0, 5, 200)[:, np.newaxis].astype(float)\n",
374374
"exact_outputs = expectation_calculation(my_circuit,\n",
375375
" operators=pauli_x,\n",
376376
" symbol_names=['alpha'],\n",

docs/tutorials/hello_many_worlds.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@
389389
},
390390
"outputs": [],
391391
"source": [
392-
"batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=np.float32)"
392+
"batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=float)"
393393
]
394394
},
395395
{
@@ -739,10 +739,10 @@
739739
"outputs": [],
740740
"source": [
741741
"# The command input values to the classical NN.\n",
742-
"commands = np.array([[0], [1]], dtype=np.float32)\n",
742+
"commands = np.array([[0], [1]], dtype=float)\n",
743743
"\n",
744744
"# The desired Z expectation value at output of quantum circuit.\n",
745-
"expected_outputs = np.array([[1], [-1]], dtype=np.float32)"
745+
"expected_outputs = np.array([[1], [-1]], dtype=float)"
746746
]
747747
},
748748
{
@@ -1108,10 +1108,10 @@
11081108
"operator_data = tfq.convert_to_tensor([[cirq.X(qubit)], [cirq.Z(qubit)]])\n",
11091109
"\n",
11101110
"# The command input values to the classical NN.\n",
1111-
"commands = np.array([[0], [1]], dtype=np.float32)\n",
1111+
"commands = np.array([[0], [1]], dtype=float)\n",
11121112
"\n",
11131113
"# The desired expectation value at output of quantum circuit.\n",
1114-
"expected_outputs = np.array([[1], [-1]], dtype=np.float32)"
1114+
"expected_outputs = np.array([[1], [-1]], dtype=float)"
11151115
]
11161116
},
11171117
{

docs/tutorials/mnist.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@
480480
"source": [
481481
"THRESHOLD = 0.5\n",
482482
"\n",
483-
"x_train_bin = np.array(x_train_nocon > THRESHOLD, dtype=np.float32)\n",
484-
"x_test_bin = np.array(x_test_small > THRESHOLD, dtype=np.float32)"
483+
"x_train_bin = np.array(x_train_nocon > THRESHOLD, dtype=float)\n",
484+
"x_test_bin = np.array(x_test_small > THRESHOLD, dtype=float)"
485485
]
486486
},
487487
{

docs/tutorials/quantum_reinforcement_learning.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@
864864
" actions = np.concatenate([ep['actions'] for ep in episodes])\n",
865865
" rewards = [ep['rewards'] for ep in episodes]\n",
866866
" returns = np.concatenate([compute_returns(ep_rwds, gamma) for ep_rwds in rewards])\n",
867-
" returns = np.array(returns, dtype=np.float32)\n",
867+
" returns = np.array(returns, dtype=float)\n",
868868
"\n",
869869
" id_action_pairs = np.array([[i, a] for i, a in enumerate(actions)])\n",
870870
" \n",
@@ -1456,9 +1456,9 @@
14561456
" training_batch = np.random.choice(replay_memory, size=batch_size)\n",
14571457
" Q_learning_update(np.asarray([x['state'] for x in training_batch]),\n",
14581458
" np.asarray([x['action'] for x in training_batch]),\n",
1459-
" np.asarray([x['reward'] for x in training_batch], dtype=np.float32),\n",
1459+
" np.asarray([x['reward'] for x in training_batch], dtype=float),\n",
14601460
" np.asarray([x['next_state'] for x in training_batch]),\n",
1461-
" np.asarray([x['done'] for x in training_batch], dtype=np.float32),\n",
1461+
" np.asarray([x['done'] for x in training_batch], dtype=float),\n",
14621462
" model, gamma, n_actions)\n",
14631463
" \n",
14641464
" # Update target model\n",

release/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ def finalize_options(self):
5353
REQUIRED_PACKAGES = [
5454
'cirq-core==0.13.1', 'cirq-google>=0.13.1', 'sympy == 1.8',
5555
'googleapis-common-protos==1.52.0', 'google-api-core==1.21.0',
56-
'google-auth==1.18.0', 'protobuf==3.17.3'
56+
'google-auth==1.18.0', 'protobuf==3.19.4'
5757
]
5858

5959
# placed as extra to not have required overwrite existing nightly installs if
6060
# they exist.
61-
EXTRA_PACKAGES = ['tensorflow == 2.7.0']
62-
CUR_VERSION = '0.7.2'
61+
EXTRA_PACKAGES = ['tensorflow == 2.11.0']
62+
CUR_VERSION = '0.7.3'
6363

6464

6565
class BinaryDistribution(Distribution):

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ numpy==1.19.5 # TensorFlow can detect if it was built against other versions.
55
nbformat==4.4.0
66
pylint==2.4.4
77
yapf==0.28.0
8-
tensorflow==2.7.0
8+
tensorflow==2.11.0
99
# Needed for compatibility with cirq program protos.
1010
googleapis-common-protos==1.52.0
1111
google-api-core==1.21.0
1212
google-auth==1.18.0
1313
google-api-python-client==1.8.0
1414
grpcio==1.34.1
15-
protobuf==3.17.3
15+
protobuf==3.19.4

scripts/benchmark_all.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Testing benchmarks.";
17-
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/...))
17+
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/...))
1818
exit_code=$?
1919

2020
if [ "$exit_code" == "0" ]; then
@@ -26,5 +26,5 @@ else
2626
fi
2727

2828
echo "Running preconfigured benchmarks.";
29-
bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"}
29+
bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"}
3030
bazel_run benchmarks/scripts:benchmark_clifford_circuit -- --op_density 1 --n_moments 10 --n_qubits 4

scripts/build_pip_package_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pip install -r requirements.txt
1919
# cd tensorflow_quantum
2020
echo "Y\n" | ./configure.sh
2121

22-
bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package
22+
bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package
2323
rm /tmp/tensorflow_quantum/* || echo ok
2424
bazel-bin/release/build_pip_package /tmp/tensorflow_quantum/
2525
pip install -U /tmp/tensorflow_quantum/*.whl

scripts/msan_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Testing All Bazel cc_tests with msan.";
17-
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
17+
test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
1818
--cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" \
1919
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
2020
--cxxopt="-g" --cxxopt="-O0" \
2121
--notest_keep_going --test_output=errors \
2222
//tensorflow_quantum/core/src:all && \
23-
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
23+
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
2424
--cxxopt="-mavx2" --cxxopt="-mavx" --cxxopt="-mfma" \
2525
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
2626
--cxxopt="-g" --cxxopt="-O0" \
2727
--notest_keep_going --test_output=errors \
2828
//tensorflow_quantum/core/src:all && \
29-
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \
29+
bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \
3030
--cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \
3131
--cxxopt="-g" --cxxopt="-O0" \
3232
--notest_keep_going --test_output=errors \

scripts/test_all.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Testing All Bazel py_test and cc_tests.";
17-
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/...)
17+
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/...)
1818
exit_code=$?
1919
if [ "$exit_code" == "0" ]; then
2020
echo "Testing Complete!";
@@ -23,4 +23,4 @@ else
2323
echo "Testing failed, please correct errors before proceeding."
2424
echo "{$test_outputs}"
2525
exit 64;
26-
fi
26+
fi

scripts/test_benchmarks.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
# limitations under the License.
1515
# ==============================================================================
1616
echo "Testing all Benchmarks.";
17-
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)
18-
# 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))
17+
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)
18+
# 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))
1919
bench_outputs=$()
20-
# 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)
20+
# 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)
2121
exit_code=$?
2222
if [ "$exit_code" == "0" ]; then
2323
echo "Testing Complete!";

0 commit comments

Comments
 (0)