Skip to content

Commit f9a015a

Browse files
Antonio MartinezMichaelBroughton
Antonio Martinez
andauthored
Updated install instructions for new TF and Bazel versions (#343)
* Updated install instructions for new TF and Bazel versions * updated pip instruction too * updated tutorial installs to tf 2.3.0 * updated pip install docstring * update to 2.3.1 Co-authored-by: MichaelBroughton <[email protected]>
1 parent 3c2e509 commit f9a015a

File tree

7 files changed

+62
-51
lines changed

7 files changed

+62
-51
lines changed

docs/install.md

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ There are a few ways to set up your environment to use TensorFlow Quantum (TFQ):
1010
Python's pip package manager.
1111
* Or build TensorFlow Quantum from source.
1212

13-
TensorFlow Quantum is supported on Python 3.6 and 3.7 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).
13+
TensorFlow Quantum is supported on Python 3.6, 3.7, and 3.8 and depends directly on [Cirq](https://github.com/quantumlib/Cirq).
1414

1515
## Pip package
1616

1717
### Requirements
1818

1919
* pip 19.0 or later (requires `manylinux2010` support)
20-
* [TensorFlow == 2.1](https://www.tensorflow.org/install/pip)
20+
* [TensorFlow == 2.3.1](https://www.tensorflow.org/install/pip)
2121

2222
See the [TensorFlow install guide](https://www.tensorflow.org/install/pip) to
2323
set up your Python development environment and an (optional) virtual environment.
@@ -27,7 +27,7 @@ Upgrade `pip` and install TensorFlow
2727
<!-- common_typos_disable -->
2828
<pre class="devsite-click-to-copy">
2929
<code class="devsite-terminal">pip3 install --upgrade pip</code>
30-
<code class="devsite-terminal">pip3 install tensorflow==2.1.0</code>
30+
<code class="devsite-terminal">pip3 install tensorflow==2.3.1</code>
3131
</pre>
3232
<!-- common_typos_enable -->
3333

@@ -57,54 +57,72 @@ The following steps are tested for Ubuntu-like systems.
5757

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

60+
First we need the Python 3.8 development tools.
6061
<!-- common_typos_disable -->
6162
<pre class="devsite-click-to-copy">
6263
<code class="devsite-terminal">sudo apt update</code>
63-
<code class="devsite-terminal">sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3</code>
64-
<code class="devsite-terminal">sudo apt install python3 python3-dev python3-venv python3-pip</code>
65-
<code class="devsite-terminal">python3 -m pip install --upgrade pip</code>
64+
<code class="devsite-terminal">sudo apt-get install pkg-config zip g++ zlib1g-dev unzip python3.8</code>
65+
<code class="devsite-terminal">sudo apt install python3.8 python3.8-dev python3.8-venv python3-pip</code>
66+
<code class="devsite-terminal">python3.8 -m pip install --upgrade pip</code>
6667
</pre>
6768
<!-- common_typos_enable -->
6869

6970
### 2. Create a virtual environment
7071

72+
Go to your workspace directory and make a virtual environment for TFQ development.
7173
<!-- common_typos_disable -->
7274
<pre class="devsite-click-to-copy">
73-
<code class="devsite-terminal">python3 -m venv tfq_env</code>
74-
<code class="devsite-terminal">source tfq_env/bin/activate</code>
75+
<code class="devsite-terminal">python3.8 -m venv quantum_env</code>
76+
<code class="devsite-terminal">source quantum_env/bin/activate</code>
7577
</pre>
7678
<!-- common_typos_enable -->
7779

7880
### 3. Install Bazel
7981

80-
See the TensorFlow
82+
As noted in the TensorFlow
8183
[build from source](https://www.tensorflow.org/install/source#install_bazel)
82-
guide to install the <a href="https://bazel.build/" class="external">Bazel</a>
83-
build system.
84+
guide, the <a href="https://bazel.build/" class="external">Bazel</a>
85+
build system will be required.
8486

85-
To ensure compatibility with TensorFlow, `bazel` version 0.26.1 or lower is
86-
required. To remove any existing version of Bazel:
87+
To ensure compatibility with TensorFlow 2.3.1, we use `bazel` version 3.1.0. To remove any existing version of Bazel:
8788

8889
<!-- common_typos_disable -->
8990
<pre class="devsite-click-to-copy">
9091
<code class="devsite-terminal">sudo apt-get remove bazel</code>
9192
</pre>
9293
<!-- common_typos_enable -->
9394

94-
Then install Bazel version 0.26.0:
95+
Download and install `bazel` version 3.1.0:
9596

9697
<!-- common_typos_disable -->
9798
<pre class="devsite-click-to-copy">
98-
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/0.26.0/bazel_0.26.0-linux-x86_64.deb</code>
99-
<code class="devsite-terminal">sudo dpkg -i bazel_0.26.0-linux-x86_64.deb</code>
99+
<code class="devsite-terminal">wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb
100+
</code>
101+
<code class="devsite-terminal">sudo dpkg -i bazel_3.1.0-linux-x86_64.deb</code>
102+
</pre>
103+
<!-- common_typos_enable -->
104+
105+
To prevent automatic updating of `bazel` to an incompatible version, run the following:
106+
107+
<!-- common_typos_disable -->
108+
<pre class="devsite-click-to-copy">
109+
<code class="devsite-terminal">sudo apt-mark hold bazel</code>
110+
</pre>
111+
<!-- common_typos_enable -->
112+
113+
Finally, confirm installation of the correct `bazel` version:
114+
115+
<!-- common_typos_disable -->
116+
<pre class="devsite-click-to-copy">
117+
<code class="devsite-terminal">bazel --version</code>
100118
</pre>
101119
<!-- common_typos_enable -->
102120

103121

104122
### 4. Build TensorFlow from source
105123

106-
Read the TensorFlow [build from source](https://www.tensorflow.org/install/source)
107-
guide for details. TensorFlow Quantum is compatible with TensorFlow version&nbsp;2.1.
124+
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.3.
108126

109127
Download the
110128
<a href="https://github.com/tensorflow/tensorflow" class="external">TensorFlow source code</a>:
@@ -113,37 +131,28 @@ Download the
113131
<pre class="devsite-click-to-copy">
114132
<code class="devsite-terminal">git clone https://github.com/tensorflow/tensorflow.git</code>
115133
<code class="devsite-terminal">cd tensorflow</code>
116-
<code class="devsite-terminal">git checkout v2.1.0</code>
134+
<code class="devsite-terminal">git checkout v2.3.1</code>
117135
</pre>
118136

119-
Install the TensorFlow dependencies:
137+
Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies:
120138

121139
<!-- common_typos_disable -->
122140
<pre class="devsite-click-to-copy">
123-
<code class="devsite-terminal">python3 -m pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1'</code>
124-
<code class="devsite-terminal">python3 -m pip install -U keras_applications --no-deps</code>
125-
<code class="devsite-terminal">python3 -m pip install -U keras_preprocessing --no-deps</code>
141+
<code class="devsite-terminal">pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1'</code>
142+
<code class="devsite-terminal">pip install -U keras_applications --no-deps</code>
143+
<code class="devsite-terminal">pip install -U keras_preprocessing --no-deps</code>
144+
<code class="devsite-terminal">pip install numpy==1.18.0</code>
126145
</pre>
127146
<!-- common_typos_enable -->
128147

129-
Configure the TensorFlow build. The default Python location and Python library
130-
paths should point inside the virtual environment. The default options are
131-
recommended:
148+
Configure the TensorFlow build. When asked for the Python interpreter and library locations, be sure to specify locations inside your virtual environment folder. The remaining options can be left at default values.
132149

133150
<!-- common_typos_disable -->
134151
<pre class="devsite-click-to-copy">
135152
<code class="devsite-terminal">./configure</code>
136153
</pre>
137154
<!-- common_typos_enable -->
138155

139-
Verify that your Bazel version is correct:
140-
141-
<!-- common_typos_disable -->
142-
<pre class="devsite-click-to-copy">
143-
<code class="devsite-terminal">bazel version</code>
144-
</pre>
145-
<!-- common_typos_enable -->
146-
147156
Build the TensorFlow package:
148157

149158
<!-- common_typos_disable -->
@@ -154,35 +163,28 @@ Build the TensorFlow package:
154163

155164
Note: It may take over an hour to build the package.
156165

157-
After the build is complete, install the package:
166+
After the build is complete, install the package and leave the TensorFlow directory:
158167

159168
<!-- common_typos_disable -->
160169
<pre class="devsite-click-to-copy">
161170
<code class="devsite-terminal">./bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg</code>
162171
<code class="devsite-terminal">pip install /tmp/tensorflow_pkg/<var>name_of_generated_wheel</var>.whl</code>
172+
<code class="devsite-terminal">cd ..</code>
163173
</pre>
164174
<!-- common_typos_enable -->
165175

166176
### 5. Download TensorFlow Quantum
167177

168-
Download the TensorFlow Quantum source code and install the requirements:
178+
We use the standard [fork and pull request workflow](https://guides.github.com/activities/forking/) for contributions. After forking from the [TensorFlow Quantum](https://github.com/tensorflow/quantum) GitHub page, download the source of your fork and install the requirements:
169179

170180
<!-- common_typos_disable -->
171181
<pre class="devsite-click-to-copy">
172-
<code class="devsite-terminal">cd ..</code>
173-
<code class="devsite-terminal">git clone https://github.com/tensorflow/quantum.git</code>
182+
<code class="devsite-terminal">git clone https://github.com/<var>username</var>/quantum.git</code>
174183
<code class="devsite-terminal">cd quantum</code>
175-
<code class="devsite-terminal">python3 -m pip install -r requirements.txt</code>
184+
<code class="devsite-terminal">pip install -r requirements.txt</code>
176185
</pre>
177186
<!-- common_typos_enable -->
178187

179-
Verify your Bazel version (since it can auto-update):
180-
181-
<!-- common_typos_disable -->
182-
<pre class="devsite-click-to-copy">
183-
<code class="devsite-terminal">bazel version</code>
184-
</pre>
185-
<!-- common_typos_enable -->
186188

187189
### 6. Build the TensorFlow Quantum pip package
188190

@@ -197,4 +199,12 @@ Build the TensorFlow Quantum pip package and install:
197199
</pre>
198200
<!-- common_typos_enable -->
199201

202+
To confirm that TensorFlow Quantum has successfully been installed, you can run the tests:
203+
<!-- common_typos_disable -->
204+
<pre class="devsite-click-to-copy">
205+
<code class="devsite-terminal">./scripts/test_all.sh</code>
206+
</pre>
207+
<!-- common_typos_enable -->
208+
209+
200210
Success: TensorFlow Quantum is now installed.

docs/tutorials/barren_plateaus.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
},
9898
"outputs": [],
9999
"source": [
100-
"!pip install tensorflow==2.1.0"
100+
"!pip install tensorflow==2.3.1"
101101
]
102102
},
103103
{

docs/tutorials/gradients.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
},
100100
"outputs": [],
101101
"source": [
102-
"!pip install tensorflow==2.1.0"
102+
"!pip install tensorflow==2.3.1"
103103
]
104104
},
105105
{

docs/tutorials/hello_many_worlds.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
},
9898
"outputs": [],
9999
"source": [
100-
"!pip install tensorflow==2.1.0"
100+
"!pip install tensorflow==2.3.1"
101101
]
102102
},
103103
{

docs/tutorials/mnist.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
},
9898
"outputs": [],
9999
"source": [
100-
"!pip install tensorflow==2.1.0"
100+
"!pip install tensorflow==2.3.1"
101101
]
102102
},
103103
{

docs/tutorials/qcnn.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
},
100100
"outputs": [],
101101
"source": [
102-
"!pip install tensorflow==2.1.0"
102+
"!pip install tensorflow==2.3.1"
103103
]
104104
},
105105
{

scripts/build_pip_package_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ==============================================================================
16+
1617
pip install -r requirements.txt
1718

1819
# cd tensorflow_quantum

0 commit comments

Comments
 (0)