|
37 | 37 | "id": "dVkNQc0WSIwk"
|
38 | 38 | },
|
39 | 39 | "source": [
|
40 |
| - "# Pyle Gates in Cirq" |
| 40 | + "# Google Internal Gates in Cirq" |
41 | 41 | ]
|
42 | 42 | },
|
43 | 43 | {
|
|
48 | 48 | "source": [
|
49 | 49 | "<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
|
50 | 50 | " <td>\n",
|
51 |
| - " <a target=\"_blank\" href=\"https://quantumai.google/cirq/google/pyle_gates>\"><img src=\"https://quantumai.google/site-assets/images/buttons/quantumai_logo_1x.png\" />View on QuantumAI</a>\n", |
| 51 | + " <a target=\"_blank\" href=\"https://quantumai.google/cirq/google/internal_gates>\"><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/google/pyle_gates.ipynb\"><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/internal_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/google/pyle_gates.ipynb\"><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/internal_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/google/pyle_gates.ipynb\"><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/internal_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": 1, |
| 67 | + "execution_count": 5, |
68 | 68 | "metadata": {
|
69 | 69 | "id": "bd9529db1c0b"
|
70 | 70 | },
|
71 |
| - "outputs": [ |
72 |
| - { |
73 |
| - "name": "stdout", |
74 |
| - "output_type": "stream", |
75 |
| - "text": [ |
76 |
| - "installing cirq...\n", |
77 |
| - "installed cirq.\n" |
78 |
| - ] |
79 |
| - } |
80 |
| - ], |
| 71 | + "outputs": [], |
81 | 72 | "source": [
|
82 | 73 | "try:\n",
|
83 | 74 | " import cirq\n",
|
| 75 | + " import cirq_google\n", |
84 | 76 | "except ImportError:\n",
|
85 | 77 | " print(\"installing cirq...\")\n",
|
86 | 78 | " !pip install --quiet cirq\n",
|
|
93 | 85 | "cell_type": "markdown",
|
94 | 86 | "metadata": {},
|
95 | 87 | "source": [
|
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." |
| 88 | + "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." |
98 | 89 | ]
|
99 | 90 | },
|
100 | 91 | {
|
101 | 92 | "cell_type": "markdown",
|
102 | 93 | "metadata": {},
|
103 | 94 | "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. " |
| 95 | + "## InternalGate\n", |
| 96 | + "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." |
108 | 97 | ]
|
109 | 98 | },
|
110 | 99 | {
|
111 | 100 | "cell_type": "code",
|
112 |
| - "execution_count": 2, |
| 101 | + "execution_count": 6, |
113 | 102 | "metadata": {},
|
114 | 103 | "outputs": [
|
115 | 104 | {
|
116 | 105 | "data": {
|
117 | 106 | "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)" |
| 107 | + "cirq_google.InternalGate(gate_name=\"GATE_NAMPE\", gate_module=\"GATE_MODULE\", num_qubits=2, )" |
119 | 108 | ]
|
120 | 109 | },
|
121 |
| - "execution_count": 2, |
| 110 | + "execution_count": 6, |
122 | 111 | "metadata": {},
|
123 | 112 | "output_type": "execute_result"
|
124 | 113 | }
|
125 | 114 | ],
|
126 | 115 | "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", |
| 116 | + "internal_gate_args = {\n", |
| 117 | + " # Arguments to be passed to the constructor of the internal gate.\n", |
| 118 | + "}\n", |
| 119 | + "internal_gate = cirq_google.InternalGate(\n", |
| 120 | + " gate_module='GATE_MODULE', # Module of class. \n", |
| 121 | + " gate_name='GATE_NAMPE', # Class name.\n", |
130 | 122 | " 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" |
| 123 | + " **internal_gate_args)\n", |
| 124 | + "internal_gate" |
133 | 125 | ]
|
134 | 126 | },
|
135 | 127 | {
|
136 | 128 | "cell_type": "code",
|
137 |
| - "execution_count": 3, |
| 129 | + "execution_count": 7, |
138 | 130 | "metadata": {},
|
139 | 131 | "outputs": [
|
140 | 132 | {
|
141 | 133 | "data": {
|
142 | 134 | "text/html": [
|
143 |
| - "<pre style=\"overflow: auto; white-space: pre;\">0: ───pyle.cirqtools.pyle_gates.CouplerDelayZ(delay=4.0, zpa=0, zpl=0)───\n", |
| 135 | + "<pre style=\"overflow: auto; white-space: pre;\">0: ───GATE_MODULE.GATE_NAMPE()───\n", |
144 | 136 | " │\n",
|
145 |
| - "1: ───#2─────────────────────────────────────────────────────────────────</pre>" |
| 137 | + "1: ───#2─────────────────────────</pre>" |
146 | 138 | ],
|
147 | 139 | "text/plain": [
|
148 |
| - "0: ───pyle.cirqtools.pyle_gates.CouplerDelayZ(delay=4.0, zpa=0, zpl=0)───\n", |
| 140 | + "0: ───GATE_MODULE.GATE_NAMPE()───\n", |
149 | 141 | " │\n",
|
150 |
| - "1: ───#2─────────────────────────────────────────────────────────────────" |
| 142 | + "1: ───#2─────────────────────────" |
151 | 143 | ]
|
152 | 144 | },
|
153 |
| - "execution_count": 3, |
| 145 | + "execution_count": 7, |
154 | 146 | "metadata": {},
|
155 | 147 | "output_type": "execute_result"
|
156 | 148 | }
|
157 | 149 | ],
|
158 | 150 | "source": [
|
159 |
| - "cirq.Circuit(coupler(*cirq.LineQubit.range(2)))" |
| 151 | + "cirq.Circuit(internal_gate(*cirq.LineQubit.range(2)))" |
160 | 152 | ]
|
161 | 153 | },
|
162 | 154 | {
|
|
166 | 158 | "## Notes\n",
|
167 | 159 | "1. InternalGate is serializable.\n",
|
168 | 160 | "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`). " |
| 161 | + "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." |
171 | 162 | ]
|
172 | 163 | }
|
173 | 164 | ],
|
|
0 commit comments