|
51 | 51 | " <a target=\"_blank\" href=\"https://quantumai.google/cirq/$$$REPLACE_WITH_SITE_URL$$$>\"><img src=\"https://quantumai.google/site-assets/images/buttons/quantumai_logo_1x.png\" />View on QuantumAI</a>\n",
|
52 | 52 | " </td>\n",
|
53 | 53 | " <td>\n",
|
54 |
| - " <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/master/docs/$$$REPLACE_WITH_NOTEBOOK_PATH$$$\"><img src=\"https://quantumai.google/site-assets/images/buttons/colab_logo_1x.png\" />Run in Google Colab</a>\n", |
| 54 | + " <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/master/docs/google/pyle_gates.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/colab_logo_1x.png\" />Run in Google Colab</a>\n", |
55 | 55 | " </td>\n",
|
56 | 56 | " <td>\n",
|
57 |
| - " <a target=\"_blank\" href=\"https://github.com/quantumlib/Cirq/blob/master/docs/$$$REPLACE_WITH_NOTEBOOK_PATH$$$\"><img src=\"https://quantumai.google/site-assets/images/buttons/github_logo_1x.png\" />View source on GitHub</a>\n", |
| 57 | + " <a target=\"_blank\" href=\"https://github.com/quantumlib/Cirq/blob/master/docs/google/pyle_gates.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/github_logo_1x.png\" />View source on GitHub</a>\n", |
58 | 58 | " </td>\n",
|
59 | 59 | " <td>\n",
|
60 |
| - " <a href=\"https://storage.googleapis.com/tensorflow_docs/Cirq/docs/$$$REPLACE_WITH_NOTEBOOK_PATH$$$\"><img src=\"https://quantumai.google/site-assets/images/buttons/download_icon_1x.png\" />Download notebook</a>\n", |
| 60 | + " <a href=\"https://storage.googleapis.com/tensorflow_docs/Cirq/docs/google/pyle_gates.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/download_icon_1x.png\" />Download notebook</a>\n", |
61 | 61 | " </td>\n",
|
62 | 62 | "</table>"
|
63 | 63 | ]
|
64 | 64 | },
|
65 | 65 | {
|
66 | 66 | "cell_type": "code",
|
67 |
| - "execution_count": null, |
| 67 | + "execution_count": 1, |
68 | 68 | "metadata": {
|
69 | 69 | "id": "bd9529db1c0b"
|
70 | 70 | },
|
71 |
| - "outputs": [], |
| 71 | + "outputs": [ |
| 72 | + { |
| 73 | + "name": "stdout", |
| 74 | + "output_type": "stream", |
| 75 | + "text": [ |
| 76 | + "installing cirq...\n", |
| 77 | + "installed cirq.\n" |
| 78 | + ] |
| 79 | + } |
| 80 | + ], |
72 | 81 | "source": [
|
73 | 82 | "try:\n",
|
74 | 83 | " import cirq\n",
|
75 | 84 | "except ImportError:\n",
|
76 | 85 | " print(\"installing cirq...\")\n",
|
77 | 86 | " !pip install --quiet cirq\n",
|
78 | 87 | " print(\"installed cirq.\")\n",
|
79 |
| - " import cirq" |
| 88 | + " import cirq\n", |
| 89 | + " import cirq_google" |
80 | 90 | ]
|
81 | 91 | },
|
82 | 92 | {
|
83 | 93 | "cell_type": "markdown",
|
84 | 94 | "metadata": {},
|
85 | 95 | "source": [
|
86 |
| - "Pyle has a wealth of gates that don't exist or have equivalents in " |
| 96 | + "Pyle has a wealth of gates 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 Pyle gate during the Cirq $\n", |
| 97 | + "rightarrow$ Pyle conversion." |
| 98 | + ] |
| 99 | + }, |
| 100 | + { |
| 101 | + "cell_type": "markdown", |
| 102 | + "metadata": {}, |
| 103 | + "source": [ |
| 104 | + "## InternalGate to PyleGate\n", |
| 105 | + "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 pyle gates. During translation, the correct pyle 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.\n", |
| 106 | + "\n", |
| 107 | + "**Note:** Currently translation is supported into subclasses of `PyleGate` only. " |
| 108 | + ] |
| 109 | + }, |
| 110 | + { |
| 111 | + "cell_type": "code", |
| 112 | + "execution_count": 2, |
| 113 | + "metadata": {}, |
| 114 | + "outputs": [ |
| 115 | + { |
| 116 | + "data": { |
| 117 | + "text/plain": [ |
| 118 | + "cirq_google.InternalGate(gate_name=\"CouplerDelayZ\", gate_module=\"pyle.cirqtools.pyle_gates\", num_qubits=2, delay=4.0, zpa=0, zpl=0)" |
| 119 | + ] |
| 120 | + }, |
| 121 | + "execution_count": 2, |
| 122 | + "metadata": {}, |
| 123 | + "output_type": "execute_result" |
| 124 | + } |
| 125 | + ], |
| 126 | + "source": [ |
| 127 | + "coupler = cirq_google.InternalGate(\n", |
| 128 | + " gate_module='pyle.cirqtools.pyle_gates', # Module of class. \n", |
| 129 | + " gate_name='CouplerDelayZ', # Class name.\n", |
| 130 | + " num_qubits=2, # Number of qubits that the gate acts on.\n", |
| 131 | + " delay=4.0, zpa=0, zpl=0) # Arguments to pass to the constructor of pyle.cirqtools.pyle_gates.CouplerDelayZ\n", |
| 132 | + "coupler" |
| 133 | + ] |
| 134 | + }, |
| 135 | + { |
| 136 | + "cell_type": "code", |
| 137 | + "execution_count": 3, |
| 138 | + "metadata": {}, |
| 139 | + "outputs": [ |
| 140 | + { |
| 141 | + "data": { |
| 142 | + "text/html": [ |
| 143 | + "<pre style=\"overflow: auto; white-space: pre;\">0: ───pyle.cirqtools.pyle_gates.CouplerDelayZ(delay=4.0, zpa=0, zpl=0)───\n", |
| 144 | + " │\n", |
| 145 | + "1: ───#2─────────────────────────────────────────────────────────────────</pre>" |
| 146 | + ], |
| 147 | + "text/plain": [ |
| 148 | + "0: ───pyle.cirqtools.pyle_gates.CouplerDelayZ(delay=4.0, zpa=0, zpl=0)───\n", |
| 149 | + " │\n", |
| 150 | + "1: ───#2─────────────────────────────────────────────────────────────────" |
| 151 | + ] |
| 152 | + }, |
| 153 | + "execution_count": 3, |
| 154 | + "metadata": {}, |
| 155 | + "output_type": "execute_result" |
| 156 | + } |
| 157 | + ], |
| 158 | + "source": [ |
| 159 | + "cirq.Circuit(coupler(*cirq.LineQubit.range(2)))" |
| 160 | + ] |
| 161 | + }, |
| 162 | + { |
| 163 | + "cell_type": "markdown", |
| 164 | + "metadata": {}, |
| 165 | + "source": [ |
| 166 | + "## Notes\n", |
| 167 | + "1. InternalGate is serializable.\n", |
| 168 | + "1. Values of `kwargs` must be serializable as [api.v2.ArgValue](https://github.com/quantumlib/Cirq/blob/61d967112ba23cc839b0e922bd42878024a3e738/cirq-google/cirq_google/api/v2/program.proto#L281)\n", |
| 169 | + "1. If a value is not serializable as `api.v2.ArgValue` (e.g. a value with unit) then the translator will need to updated to know what to do for that gate. \n", |
| 170 | + " For example for the delay `delay` parameter of `CouplerDelayZ`, the translator will expect a float which it will convert into nanoseconds (i.e. the coupler created above has `delay=4ns`). " |
87 | 171 | ]
|
88 | 172 | }
|
89 | 173 | ],
|
|
95 | 179 | "kernelspec": {
|
96 | 180 | "display_name": "Python 3",
|
97 | 181 | "name": "python3"
|
| 182 | + }, |
| 183 | + "language_info": { |
| 184 | + "codemirror_mode": { |
| 185 | + "name": "ipython", |
| 186 | + "version": 3 |
| 187 | + }, |
| 188 | + "file_extension": ".py", |
| 189 | + "mimetype": "text/x-python", |
| 190 | + "name": "python", |
| 191 | + "nbconvert_exporter": "python", |
| 192 | + "pygments_lexer": "ipython3", |
| 193 | + "version": "3.10.13" |
98 | 194 | }
|
99 | 195 | },
|
100 | 196 | "nbformat": 4,
|
|
0 commit comments