Skip to content

Commit 14270d5

Browse files
docs
1 parent d49b613 commit 14270d5

File tree

1 file changed

+103
-7
lines changed

1 file changed

+103
-7
lines changed

docs/google/pyle_gates.ipynb

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,123 @@
5151
" <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",
5252
" </td>\n",
5353
" <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",
5555
" </td>\n",
5656
" <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",
5858
" </td>\n",
5959
" <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",
6161
" </td>\n",
6262
"</table>"
6363
]
6464
},
6565
{
6666
"cell_type": "code",
67-
"execution_count": null,
67+
"execution_count": 1,
6868
"metadata": {
6969
"id": "bd9529db1c0b"
7070
},
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+
],
7281
"source": [
7382
"try:\n",
7483
" import cirq\n",
7584
"except ImportError:\n",
7685
" print(\"installing cirq...\")\n",
7786
" !pip install --quiet cirq\n",
7887
" print(\"installed cirq.\")\n",
79-
" import cirq"
88+
" import cirq\n",
89+
" import cirq_google"
8090
]
8191
},
8292
{
8393
"cell_type": "markdown",
8494
"metadata": {},
8595
"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`). "
87171
]
88172
}
89173
],
@@ -95,6 +179,18 @@
95179
"kernelspec": {
96180
"display_name": "Python 3",
97181
"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"
98194
}
99195
},
100196
"nbformat": 4,

0 commit comments

Comments
 (0)