Skip to content

Commit aca87e1

Browse files
committed
Update tutorials for release 0.7.4
This provides information about how to install TFQ in Colab, and also how to get Keras 2.
1 parent a3b69e8 commit aca87e1

File tree

9 files changed

+367
-264
lines changed

9 files changed

+367
-264
lines changed

docs/tutorials/barren_plateaus.ipynb

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,6 @@
8787
"## Setup"
8888
]
8989
},
90-
{
91-
"cell_type": "code",
92-
"execution_count": null,
93-
"metadata": {
94-
"colab": {},
95-
"colab_type": "code",
96-
"id": "TorxE5tnkvb2"
97-
},
98-
"outputs": [],
99-
"source": [
100-
"!pip install tensorflow==2.15.0"
101-
]
102-
},
10390
{
10491
"cell_type": "markdown",
10592
"metadata": {
@@ -113,40 +100,46 @@
113100
{
114101
"cell_type": "code",
115102
"execution_count": null,
116-
"metadata": {
117-
"colab": {},
118-
"colab_type": "code",
119-
"id": "saFHsRDpkvkH"
120-
},
103+
"metadata": {},
121104
"outputs": [],
122105
"source": [
123-
"!pip install tensorflow-quantum==0.7.3"
106+
"# When running in Colab, some preinstalled packages must\n",
107+
"# be uninstalled before installing TensorFlow Quantum 0.7.4.\n",
108+
"# Make sure to click \"Restart session\" when prompted.\n",
109+
"import sys, os\n",
110+
"if 'google.colab' in sys.modules:\n",
111+
" !pip uninstall -y albucore albumentations chex dopamine-rl flax google-adk google-ai-generativelanguage google-generativeai grpcio-status jax jaxlib keras-hub opencv-contrib-python opencv-python opencv-python-headless opentelemetry-proto opentelemetry-exporter-otlp-proto-http optax orbax-checkpoint protobuf pymc pytensor shap tensorflow-decision-forests tensorflow-hub tensorflow-text tensorstore tf-keras tsfresh ydf\n",
112+
"!pip install tensorflow-quantum[and-tensorflow]"
113+
]
114+
},
115+
{
116+
"cell_type": "markdown",
117+
"metadata": {},
118+
"source": [
119+
"Configure the use of Keras 2:"
124120
]
125121
},
126122
{
127123
"cell_type": "code",
128124
"execution_count": null,
129-
"metadata": {
130-
"colab": {},
131-
"colab_type": "code",
132-
"id": "4Ql5PW-ACO0J"
133-
},
125+
"metadata": {},
134126
"outputs": [],
135127
"source": [
136-
"# Update package resources to account for version changes.\n",
137-
"import importlib, pkg_resources\n",
128+
"import sys\n",
129+
"import tf_keras\n",
138130
"\n",
139-
"importlib.reload(pkg_resources)"
131+
"%env TF_USE_LEGACY_KERAS=1\n",
132+
"sys.modules[\"keras\"] = tf_keras"
140133
]
141134
},
142135
{
143136
"cell_type": "markdown",
144137
"metadata": {
145138
"colab_type": "text",
146-
"id": "1PaclXeSrrMW"
139+
"id": "F1L8h1YKUvIO"
147140
},
148141
"source": [
149-
"Now import TensorFlow and the module dependencies:"
142+
"Now import TensorFlow, TensorFlow Quantum, and other modules needed:"
150143
]
151144
},
152145
{
@@ -509,13 +502,21 @@
509502
"toc_visible": true
510503
},
511504
"kernelspec": {
512-
"display_name": "Python 3",
505+
"display_name": "Python 3 (ipykernel)",
513506
"language": "python",
514507
"name": "python3"
515508
},
516509
"language_info": {
510+
"codemirror_mode": {
511+
"name": "ipython",
512+
"version": 3
513+
},
514+
"file_extension": ".py",
515+
"mimetype": "text/x-python",
517516
"name": "python",
518-
"version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]"
517+
"nbconvert_exporter": "python",
518+
"pygments_lexer": "ipython3",
519+
"version": "3.12.11"
519520
},
520521
"vscode": {
521522
"interpreter": {
@@ -524,5 +525,5 @@
524525
}
525526
},
526527
"nbformat": 4,
527-
"nbformat_minor": 0
528+
"nbformat_minor": 4
528529
}

docs/tutorials/gradients.ipynb

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,11 @@
8989
"## Setup"
9090
]
9191
},
92-
{
93-
"cell_type": "code",
94-
"execution_count": null,
95-
"metadata": {
96-
"colab": {},
97-
"colab_type": "code",
98-
"id": "TorxE5tnkvb2"
99-
},
100-
"outputs": [],
101-
"source": [
102-
"!pip install tensorflow==2.15.0"
103-
]
104-
},
10592
{
10693
"cell_type": "markdown",
10794
"metadata": {
10895
"colab_type": "text",
109-
"id": "OIbP5hklC338"
96+
"id": "FxkQA6oblNqI"
11097
},
11198
"source": [
11299
"Install TensorFlow Quantum:"
@@ -115,40 +102,46 @@
115102
{
116103
"cell_type": "code",
117104
"execution_count": null,
118-
"metadata": {
119-
"colab": {},
120-
"colab_type": "code",
121-
"id": "saFHsRDpkvkH"
122-
},
105+
"metadata": {},
123106
"outputs": [],
124107
"source": [
125-
"!pip install tensorflow-quantum==0.7.3"
108+
"# When running in Colab, some preinstalled packages must\n",
109+
"# be uninstalled before installing TensorFlow Quantum 0.7.4.\n",
110+
"# Make sure to click \"Restart session\" when prompted.\n",
111+
"import sys, os\n",
112+
"if 'google.colab' in sys.modules:\n",
113+
" !pip uninstall -y albucore albumentations chex dopamine-rl flax google-adk google-ai-generativelanguage google-generativeai grpcio-status jax jaxlib keras-hub opencv-contrib-python opencv-python opencv-python-headless opentelemetry-proto opentelemetry-exporter-otlp-proto-http optax orbax-checkpoint protobuf pymc pytensor shap tensorflow-decision-forests tensorflow-hub tensorflow-text tensorstore tf-keras tsfresh ydf\n",
114+
"!pip install tensorflow-quantum[and-tensorflow]"
115+
]
116+
},
117+
{
118+
"cell_type": "markdown",
119+
"metadata": {},
120+
"source": [
121+
"Configure the use of Keras 2:"
126122
]
127123
},
128124
{
129125
"cell_type": "code",
130126
"execution_count": null,
131-
"metadata": {
132-
"colab": {},
133-
"colab_type": "code",
134-
"id": "4Ql5PW-ACO0J"
135-
},
127+
"metadata": {},
136128
"outputs": [],
137129
"source": [
138-
"# Update package resources to account for version changes.\n",
139-
"import importlib, pkg_resources\n",
130+
"import sys\n",
131+
"import tf_keras\n",
140132
"\n",
141-
"importlib.reload(pkg_resources)"
133+
"%env TF_USE_LEGACY_KERAS=1\n",
134+
"sys.modules[\"keras\"] = tf_keras"
142135
]
143136
},
144137
{
145138
"cell_type": "markdown",
146139
"metadata": {
147140
"colab_type": "text",
148-
"id": "MkTqyoSxGUfB"
141+
"id": "F1L8h1YKUvIO"
149142
},
150143
"source": [
151-
"Now import TensorFlow and the module dependencies:"
144+
"Now import TensorFlow, TensorFlow Quantum, and other modules needed:"
152145
]
153146
},
154147
{
@@ -810,13 +803,21 @@
810803
"toc_visible": true
811804
},
812805
"kernelspec": {
813-
"display_name": "Python 3",
806+
"display_name": "Python 3 (ipykernel)",
814807
"language": "python",
815808
"name": "python3"
816809
},
817810
"language_info": {
811+
"codemirror_mode": {
812+
"name": "ipython",
813+
"version": 3
814+
},
815+
"file_extension": ".py",
816+
"mimetype": "text/x-python",
818817
"name": "python",
819-
"version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]"
818+
"nbconvert_exporter": "python",
819+
"pygments_lexer": "ipython3",
820+
"version": "3.12.11"
820821
},
821822
"vscode": {
822823
"interpreter": {
@@ -825,5 +826,5 @@
825826
}
826827
},
827828
"nbformat": 4,
828-
"nbformat_minor": 0
829+
"nbformat_minor": 4
829830
}

docs/tutorials/hello_many_worlds.ipynb

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,6 @@
9090
"## Setup"
9191
]
9292
},
93-
{
94-
"cell_type": "code",
95-
"execution_count": null,
96-
"metadata": {
97-
"colab": {},
98-
"colab_type": "code",
99-
"id": "TorxE5tnkvb2",
100-
"vscode": {
101-
"languageId": "python"
102-
}
103-
},
104-
"outputs": [],
105-
"source": [
106-
"!pip install tensorflow==2.15.0"
107-
]
108-
},
10993
{
11094
"cell_type": "markdown",
11195
"metadata": {
@@ -119,36 +103,36 @@
119103
{
120104
"cell_type": "code",
121105
"execution_count": null,
122-
"metadata": {
123-
"colab": {},
124-
"colab_type": "code",
125-
"id": "saFHsRDpkvkH",
126-
"vscode": {
127-
"languageId": "python"
128-
}
129-
},
106+
"metadata": {},
130107
"outputs": [],
131108
"source": [
132-
"!pip install tensorflow-quantum==0.7.3"
109+
"# When running in Colab, some preinstalled packages must\n",
110+
"# be uninstalled before installing TensorFlow Quantum 0.7.4.\n",
111+
"# Make sure to click \"Restart session\" when prompted.\n",
112+
"import sys, os\n",
113+
"if 'google.colab' in sys.modules:\n",
114+
" !pip uninstall -y albucore albumentations chex dopamine-rl flax google-adk google-ai-generativelanguage google-generativeai grpcio-status jax jaxlib keras-hub opencv-contrib-python opencv-python opencv-python-headless opentelemetry-proto opentelemetry-exporter-otlp-proto-http optax orbax-checkpoint protobuf pymc pytensor shap tensorflow-decision-forests tensorflow-hub tensorflow-text tensorstore tf-keras tsfresh ydf\n",
115+
"!pip install tensorflow-quantum[and-tensorflow]"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {},
121+
"source": [
122+
"Configure the use of Keras 2:"
133123
]
134124
},
135125
{
136126
"cell_type": "code",
137127
"execution_count": null,
138-
"metadata": {
139-
"colab": {},
140-
"colab_type": "code",
141-
"id": "4Ql5PW-ACO0J",
142-
"vscode": {
143-
"languageId": "python"
144-
}
145-
},
128+
"metadata": {},
146129
"outputs": [],
147130
"source": [
148-
"# Update package resources to account for version changes.\n",
149-
"import importlib, pkg_resources\n",
131+
"import sys\n",
132+
"import tf_keras\n",
150133
"\n",
151-
"importlib.reload(pkg_resources)"
134+
"%env TF_USE_LEGACY_KERAS=1\n",
135+
"sys.modules[\"keras\"] = tf_keras"
152136
]
153137
},
154138
{
@@ -158,7 +142,7 @@
158142
"id": "F1L8h1YKUvIO"
159143
},
160144
"source": [
161-
"Now import TensorFlow and the module dependencies:"
145+
"Now import TensorFlow, TensorFlow Quantum, and other modules needed:"
162146
]
163147
},
164148
{
@@ -794,7 +778,7 @@
794778
"id": "yJSC9qH76pJA"
795779
},
796780
"source": [
797-
"The model attempts to output the correct correct measurement value of $\\hat{Z}$ for each command. The commands and correct values are defined below."
781+
"The model attempts to output the correct measurement value of $\\hat{Z}$ for each command. The commands and correct values are defined below."
798782
]
799783
},
800784
{
@@ -1333,11 +1317,23 @@
13331317
"toc_visible": true
13341318
},
13351319
"kernelspec": {
1336-
"display_name": "Python 3",
1320+
"display_name": "Python 3 (ipykernel)",
13371321
"language": "python",
13381322
"name": "python3"
1323+
},
1324+
"language_info": {
1325+
"codemirror_mode": {
1326+
"name": "ipython",
1327+
"version": 3
1328+
},
1329+
"file_extension": ".py",
1330+
"mimetype": "text/x-python",
1331+
"name": "python",
1332+
"nbconvert_exporter": "python",
1333+
"pygments_lexer": "ipython3",
1334+
"version": "3.12.11"
13391335
}
13401336
},
13411337
"nbformat": 4,
1342-
"nbformat_minor": 0
1338+
"nbformat_minor": 4
13431339
}

0 commit comments

Comments
 (0)