Skip to content

Commit 6ebc78b

Browse files
authored
Fix check/nbformat installation and execution (#7004)
* Improve the check/nbformat script - Fail early if tensorflow-docs installation is broken. - Use exit status from the nbfmt tool to decide if the format is good. * Bump up tensorflow-docs to be compatible with protobuf-4 * Format jupyter notebooks Executed check/nbformat --apply
1 parent 0e5df4e commit 6ebc78b

File tree

7 files changed

+722
-721
lines changed

7 files changed

+722
-721
lines changed

check/nbformat

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ thisdir="$(dirname "${BASH_SOURCE[0]}")" || exit $?
2929
topdir="$(git -C "${thisdir}" rev-parse --show-toplevel)" || exit $?
3030
cd "${topdir}" || exit $?
3131

32-
pip show tensorflow-docs > /dev/null || exit 1
32+
# check if the nbfmt tool in tensorflow-docs is installed and working
33+
if ! python3 -c "import tensorflow_docs.tools.nbfmt"; then
34+
echo -e "\033[31mInstallation of tensorflow-docs is broken, please correct.\033[0m"
35+
exit 2
36+
fi
3337

34-
FORMAT_CMD="python3 -m tensorflow_docs.tools.nbfmt --indent=1"
38+
my_nbfmt() {
39+
python3 -m tensorflow_docs.tools.nbfmt --indent=1 "$@"
40+
}
3541

36-
# Test the notebooks
37-
unformatted=$($FORMAT_CMD --test docs 2>&1 | grep "\- docs" || true)
38-
needed_changes=0
39-
if [ -n "${unformatted}" ]; then
40-
needed_changes=1
41-
if (( only_print == 0 )); then
42-
$FORMAT_CMD docs
43-
else
44-
echo -e "\033[31mThe following notebooks require formatting\033[0m."
45-
echo "${unformatted}"
46-
fi
47-
fi
42+
exit_code=0
4843

49-
if (( needed_changes == 0 )); then
44+
# Check if notebooks are already formatted and store output for later use
45+
if output=$(my_nbfmt --test docs 2>&1); then
5046
echo -e "\033[32mNotebooks are formatted\033[0m."
51-
elif (( only_print == 1 )); then
47+
elif (( only_print )); then
48+
echo -e "\033[31mThe following notebooks require formatting\033[0m."
49+
grep "^- docs" <<<"${output}"
5250
echo -e "\033[33mNotebooks are not formatted. Please run 'check/nbformat --apply'\033[0m"
53-
exit 1
51+
exit_code=1
5452
else
55-
echo -e "\033[33mReformatted changed notebooks\033[0m."
53+
my_nbfmt docs &&
54+
echo -e "\033[33mReformatted changed notebooks\033[0m." ||
55+
exit_code=$?
5656
fi
57+
58+
exit ${exit_code}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tensorflow-docs@https://github.com/tensorflow/docs/archive/3a6a7a3322de8620f0031ae3a0a4b62e40d1d7f2/master.tar.gz
1+
tensorflow-docs==2024.2.5.73858

docs/build/interop.ipynb

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -254,44 +254,44 @@
254254
},
255255
{
256256
"cell_type": "markdown",
257-
"source": [
258-
"OpenQASM 3.0 also has limited support, which can be seen by the following code:"
259-
],
260257
"metadata": {
261-
"id": "K_aS_FJxVoHI"
262-
}
258+
"id": "K_aS_FJxVoHI"
259+
},
260+
"source": [
261+
"OpenQASM 3.0 also has limited support, which can be seen by the following code:"
262+
]
263263
},
264264
{
265265
"cell_type": "code",
266266
"execution_count": null,
267-
"source": [
268-
"from cirq.contrib.qasm_import import circuit_from_qasm\n",
269-
"circuit = circuit_from_qasm(\"\"\"\n",
270-
"OPENQASM 3.0;\n",
271-
"include \"stdgates.inc\";\n",
272-
"\n",
273-
"// Qubits: [q0]\n",
274-
"qubit[2] q;\n",
275-
"bit[2] m_mmm;\n",
276-
"\n",
277-
"x q;\n",
278-
"m_mmm = measure q;\n",
279-
"\"\"\")\n",
280-
"print(circuit)"
281-
],
282267
"metadata": {
283-
"id": "LHFjG9trvhla"
268+
"id": "LHFjG9trvhla"
284269
},
285270
"outputs": [
286-
{
287-
"output_type": "stream",
288-
"name": "stdout",
289-
"text": [
290-
"q_0: ───X───M('m_mmm_0')───\n",
291-
"\n",
292-
"q_1: ───X───M('m_mmm_1')───\n"
293-
]
294-
}
271+
{
272+
"name": "stdout",
273+
"output_type": "stream",
274+
"text": [
275+
"q_0: ───X───M('m_mmm_0')───\n",
276+
"\n",
277+
"q_1: ───X───M('m_mmm_1')───\n"
278+
]
279+
}
280+
],
281+
"source": [
282+
"from cirq.contrib.qasm_import import circuit_from_qasm\n",
283+
"circuit = circuit_from_qasm(\"\"\"\n",
284+
"OPENQASM 3.0;\n",
285+
"include \"stdgates.inc\";\n",
286+
"\n",
287+
"// Qubits: [q0]\n",
288+
"qubit[2] q;\n",
289+
"bit[2] m_mmm;\n",
290+
"\n",
291+
"x q;\n",
292+
"m_mmm = measure q;\n",
293+
"\"\"\")\n",
294+
"print(circuit)"
295295
]
296296
},
297297
{
@@ -382,61 +382,61 @@
382382
},
383383
{
384384
"cell_type": "markdown",
385-
"source": [
386-
"### Exporting cirq.Circuit to QASM format\n",
387-
"\n",
388-
"Cirq also has the ability to export circuits in OpenQASM format using either OpenQasm 2.0 or 3.0 formats. This can be done using the `circuit.to_qasm()` function, such as\n",
389-
"`circuit.to_qasm(version=\"3.0\")` or by using the `cirq.qasm` protocol, as follows:\n"
390-
],
391385
"metadata": {
392-
"id": "fyyz_GGdY5uZ"
393-
}
386+
"id": "fyyz_GGdY5uZ"
387+
},
388+
"source": [
389+
"### Exporting cirq.Circuit to QASM format\n",
390+
"\n",
391+
"Cirq also has the ability to export circuits in OpenQASM format using either OpenQasm 2.0 or 3.0 formats. This can be done using the `circuit.to_qasm()` function, such as\n",
392+
"`circuit.to_qasm(version=\"3.0\")` or by using the `cirq.qasm` protocol, as follows:\n"
393+
]
394394
},
395395
{
396396
"cell_type": "code",
397397
"execution_count": null,
398-
"source": [
399-
"q0 = cirq.NamedQubit('q0')\n",
400-
"circuit = cirq.Circuit(cirq.X(q0), cirq.measure(q0, key='mmm'))\n",
401-
"qasm_str = cirq.qasm(circuit, args=cirq.QasmArgs(version=\"3.0\"))\n",
402-
"print(qasm_str)"
403-
],
404398
"metadata": {
405-
"id": "w62L_PMeVvYl"
399+
"id": "w62L_PMeVvYl"
406400
},
407401
"outputs": [
408-
{
409-
"output_type": "stream",
410-
"name": "stdout",
411-
"text": [
412-
"// Generated from Cirq v1.5.0.dev20241221000556\n",
413-
"\n",
414-
"OPENQASM 3.0;\n",
415-
"include \"stdgates.inc\";\n",
416-
"\n",
417-
"\n",
418-
"// Qubits: [q0]\n",
419-
"qubit[1] q;\n",
420-
"bit[1] m_mmm;\n",
421-
"\n",
422-
"\n",
423-
"x q[0];\n",
424-
"m_mmm[0] = measure q[0];\n",
425-
"\n"
426-
]
427-
}
402+
{
403+
"name": "stdout",
404+
"output_type": "stream",
405+
"text": [
406+
"// Generated from Cirq v1.5.0.dev20241221000556\n",
407+
"\n",
408+
"OPENQASM 3.0;\n",
409+
"include \"stdgates.inc\";\n",
410+
"\n",
411+
"\n",
412+
"// Qubits: [q0]\n",
413+
"qubit[1] q;\n",
414+
"bit[1] m_mmm;\n",
415+
"\n",
416+
"\n",
417+
"x q[0];\n",
418+
"m_mmm[0] = measure q[0];\n",
419+
"\n"
420+
]
421+
}
422+
],
423+
"source": [
424+
"q0 = cirq.NamedQubit('q0')\n",
425+
"circuit = cirq.Circuit(cirq.X(q0), cirq.measure(q0, key='mmm'))\n",
426+
"qasm_str = cirq.qasm(circuit, args=cirq.QasmArgs(version=\"3.0\"))\n",
427+
"print(qasm_str)"
428428
]
429429
},
430430
{
431431
"cell_type": "markdown",
432-
"source": [
433-
" Currently supported version strings are \"2.0\" and \"3.0\".\n",
434-
"\n",
435-
" By default, if no version is specified, circuits are currently exported in OpenQasm 2.0 format. This default behavior may change in the future so be sure to specify the argument if a specific version of OpenQASM is desired.\n"
436-
],
437432
"metadata": {
438-
"id": "E496hCqZZZUt"
439-
}
433+
"id": "E496hCqZZZUt"
434+
},
435+
"source": [
436+
" Currently supported version strings are \"2.0\" and \"3.0\".\n",
437+
"\n",
438+
" By default, if no version is specified, circuits are currently exported in OpenQasm 2.0 format. This default behavior may change in the future so be sure to specify the argument if a specific version of OpenQASM is desired.\n"
439+
]
440440
},
441441
{
442442
"cell_type": "markdown",

docs/google/internal_gates.ipynb

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@
8383
},
8484
{
8585
"cell_type": "markdown",
86-
"metadata": {},
86+
"metadata": {
87+
"id": "4783c659ce5d"
88+
},
8789
"source": [
8890
"Google has a wealth of gates implemented internally that don't exist or have equivalents in Cirq. `cirq_google.InternalGate` allows the creation of Cirq circuits that contain place holder operations that will get translated to the correct internal gate."
8991
]
9092
},
9193
{
9294
"cell_type": "markdown",
93-
"metadata": {},
95+
"metadata": {
96+
"id": "9bdd7b2ebcbc"
97+
},
9498
"source": [
9599
"## InternalGate\n",
96100
"Instances of [cirq_google.InternalGate](https://github.com/quantumlib/Cirq/blob/61d967112ba23cc839b0e922bd42878024a3e738/cirq-google/cirq_google/ops/internal_gate.py#L20) act as placeholder objects for google internal gates. During translation, the correct gate is identified through the `gate_module` and `gate_name` properties. Then an instance of that gate is created using the `kwargs` arguments passed to the `InternalGate` constructor."
@@ -99,7 +103,9 @@
99103
{
100104
"cell_type": "code",
101105
"execution_count": 6,
102-
"metadata": {},
106+
"metadata": {
107+
"id": "aecb9afa09a0"
108+
},
103109
"outputs": [
104110
{
105111
"data": {
@@ -127,7 +133,9 @@
127133
{
128134
"cell_type": "code",
129135
"execution_count": 7,
130-
"metadata": {},
136+
"metadata": {
137+
"id": "f28062274ada"
138+
},
131139
"outputs": [
132140
{
133141
"data": {
@@ -153,7 +161,9 @@
153161
},
154162
{
155163
"cell_type": "markdown",
156-
"metadata": {},
164+
"metadata": {
165+
"id": "db0cf657ffea"
166+
},
157167
"source": [
158168
"## Notes\n",
159169
"1. InternalGate is serializable.\n",
@@ -164,24 +174,12 @@
164174
],
165175
"metadata": {
166176
"colab": {
167-
"name": "_template.ipynb",
177+
"name": "internal_gates.ipynb",
168178
"toc_visible": true
169179
},
170180
"kernelspec": {
171181
"display_name": "Python 3",
172182
"name": "python3"
173-
},
174-
"language_info": {
175-
"codemirror_mode": {
176-
"name": "ipython",
177-
"version": 3
178-
},
179-
"file_extension": ".py",
180-
"mimetype": "text/x-python",
181-
"name": "python",
182-
"nbconvert_exporter": "python",
183-
"pygments_lexer": "ipython3",
184-
"version": "3.10.13"
185183
}
186184
},
187185
"nbformat": 4,

docs/hardware/aqt/getting_started.ipynb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,19 @@
117117
{
118118
"cell_type": "code",
119119
"execution_count": null,
120-
"metadata": {},
120+
"metadata": {
121+
"id": "29a2d83f816f"
122+
},
121123
"outputs": [],
122124
"source": [
123125
"AQTSampler.fetch_resources(access_token)"
124126
]
125127
},
126128
{
127129
"cell_type": "markdown",
128-
"metadata": {},
130+
"metadata": {
131+
"id": "322966c20c47"
132+
},
129133
"source": [
130134
"Then you can specify the workspace and resource you want to send your quantum circuits to."
131135
]
@@ -280,15 +284,19 @@
280284
},
281285
{
282286
"cell_type": "markdown",
283-
"metadata": {},
287+
"metadata": {
288+
"id": "5108669495f5"
289+
},
284290
"source": [
285291
"Then you can use the Sampler Simulator as you would the regular one, for example:"
286292
]
287293
},
288294
{
289295
"cell_type": "code",
290296
"execution_count": null,
291-
"metadata": {},
297+
"metadata": {
298+
"id": "4ac3e6439e13"
299+
},
292300
"outputs": [],
293301
"source": [
294302
"aqt_sweep = aqt_sampler.run(circuit, repetitions=100)\n",

0 commit comments

Comments
 (0)