Skip to content

Commit

Permalink
Upgrade to TF 2.7.0. (#650)
Browse files Browse the repository at this point in the history
* Upgrade to TF 2.7.0.

* fix install docs.

* fixed import format.

* add default to c++14.

* Add c++14 in src.

* try moving to bazelrc file.
  • Loading branch information
MichaelBroughton authored Jan 4, 2022
1 parent 05f51c7 commit 768ac15
Show file tree
Hide file tree
Showing 48 changed files with 366 additions and 18 deletions.
8 changes: 5 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ http_archive(

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


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

workspace()
Expand Down Expand Up @@ -50,3 +51,4 @@ bind(
name = "six",
actual = "@six_archive//:six",
)

1 change: 1 addition & 0 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ 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\""


if is_windows; then
Expand Down
12 changes: 6 additions & 6 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TensorFlow Quantum is supported on Python 3.6, 3.7, and 3.8 and depends directly
### Requirements

* pip 19.0 or later (requires `manylinux2010` support)
* [TensorFlow == 2.5.1](https://www.tensorflow.org/install/pip)
* [TensorFlow == 2.4.1](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.5.1</code>
<code class="devsite-terminal">pip3 install tensorflow==2.4.1</code>
</pre>
<!-- common_typos_enable -->

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

Success: TensorFlow Quantum is now installed.

Install the latest nightly version of TensorFlow Quantum:
Nightly builds which might depend on newer version of TensorFlow can be installed with:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
Expand Down Expand Up @@ -84,7 +84,7 @@ 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.5.1. To ensure compatibility we use `bazel` version 3.7.2. To remove any existing version of Bazel:
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:

<!-- common_typos_disable -->
<pre class="devsite-click-to-copy">
Expand Down Expand Up @@ -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.5.
guide, see the link for further details. TensorFlow Quantum is compatible with TensorFlow version&nbsp;2.7.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.5.1</code>
<code class="devsite-terminal">git checkout v2.7.0</code>
</pre>

Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
Expand Down
2 changes: 1 addition & 1 deletion release/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def finalize_options(self):

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


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nbconvert==5.6.1
nbformat==4.4.0
pylint==2.4.4
yapf==0.28.0
tensorflow==2.5.1
tensorflow==2.7.0
# Needed for compatibility with cirq program protos.
googleapis-common-protos==1.52.0
google-api-core==1.21.0
Expand Down
80 changes: 75 additions & 5 deletions tensorflow_quantum/core/ops/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down Expand Up @@ -132,7 +132,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down Expand Up @@ -190,7 +190,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down Expand Up @@ -256,7 +256,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down Expand Up @@ -284,6 +284,41 @@ cc_library(
name = "parse_context",
srcs = ["parse_context.cc"],
hdrs = ["parse_context.h"],
copts = select({
":windows": [
"/D__CLANG_SUPPORT_DYN_ANNOTATION__",
"/D_USE_MATH_DEFINES",
"/DEIGEN_MPL2_ONLY",
"/DEIGEN_MAX_ALIGN_BYTES=64",
"/DEIGEN_HAS_TYPE_TRAITS=0",
"/DTF_USE_SNAPPY",
"/showIncludes",
"/MD",
"/O2",
"/DNDEBUG",
"/w",
"-DWIN32_LEAN_AND_MEAN",
"-DNOGDI",
"/d2ReducedOptimizeHugeFunctions",
"/arch:AVX",
"/std:c++14",
"-DTENSORFLOW_MONOLITHIC_BUILD",
"/DPLATFORM_WINDOWS",
"/DEIGEN_HAS_C99_MATH",
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
"/DEIGEN_AVOID_STL_ARRAY",
"/Iexternal/gemmlowp",
"/wd4018",
"/wd4577",
"/DNOGDI",
"/UTF_COMPILE_LIBRARY",
],
"//conditions:default": [
"-pthread",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
deps = [
":tfq_simulate_utils",
"//tensorflow_quantum/core/proto:pauli_sum_cc_proto",
Expand Down Expand Up @@ -333,7 +368,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down Expand Up @@ -364,6 +399,41 @@ cc_library(
name = "tfq_simulate_utils",
srcs = ["tfq_simulate_utils.cc"],
hdrs = ["tfq_simulate_utils.h"],
copts = select({
":windows": [
"/D__CLANG_SUPPORT_DYN_ANNOTATION__",
"/D_USE_MATH_DEFINES",
"/DEIGEN_MPL2_ONLY",
"/DEIGEN_MAX_ALIGN_BYTES=64",
"/DEIGEN_HAS_TYPE_TRAITS=0",
"/DTF_USE_SNAPPY",
"/showIncludes",
"/MD",
"/O2",
"/DNDEBUG",
"/w",
"-DWIN32_LEAN_AND_MEAN",
"-DNOGDI",
"/d2ReducedOptimizeHugeFunctions",
"/arch:AVX",
"/std:c++14",
"-DTENSORFLOW_MONOLITHIC_BUILD",
"/DPLATFORM_WINDOWS",
"/DEIGEN_HAS_C99_MATH",
"/DTENSORFLOW_USE_EIGEN_THREADPOOL",
"/DEIGEN_AVOID_STL_ARRAY",
"/Iexternal/gemmlowp",
"/wd4018",
"/wd4577",
"/DNOGDI",
"/UTF_COMPILE_LIBRARY",
],
"//conditions:default": [
"-pthread",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/batch_util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Test parallel Cirq simulations."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import numpy as np
import tensorflow as tf
from absl.testing import parameterized
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/circuit_execution_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Module to test consistency between Cirq and TFQ circuit execution ops."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

from unittest import mock
import numpy as np
import tensorflow as tf
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/cirq_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests for the cirq simulation ops."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

from unittest import mock
import numpy as np
import tensorflow as tf
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/math_ops/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target tfq_inner_product."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import copy
import numpy as np
from absl.testing import parameterized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target tfq_inner_product_grad."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import copy
import numpy as np
from absl.testing import parameterized
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target tfq_inner_product."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import copy
import numpy as np
from absl.testing import parameterized
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/noise/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cc_binary(
],
"//conditions:default": [
"-pthread",
"-std=c++11",
"-std=c++14",
"-D_GLIBCXX_USE_CXX11_ABI=0",
],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target noisy expectation calculation."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import numpy as np
from absl.testing import parameterized
import tensorflow as tf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target noisy expectation calculation."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import numpy as np
from absl.testing import parameterized
import tensorflow as tf
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target noisy sampling."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import numpy as np
from scipy import stats
from absl.testing import parameterized
Expand Down
7 changes: 7 additions & 0 deletions tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# limitations under the License.
# ==============================================================================
"""Tests that specifically target tfq_unitary_op."""
# Remove PYTHONPATH collisions for protobuf.
# pylint: disable=wrong-import-position
import sys
NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x]
sys.path = NEW_PATH
# pylint: enable=wrong-import-position

import numpy as np
from absl.testing import parameterized
import tensorflow as tf
Expand Down
Loading

0 comments on commit 768ac15

Please sign in to comment.