{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "_R7892gXeIRp" }, "source": [ "##### Copyright 2020 The Cirq Developers" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "sgdsF4xZeIkk" }, "outputs": [], "source": [ "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": { "id": "GS4t2kCkeFL_" }, "source": [ "# Import/export circuits" ] }, { "cell_type": "markdown", "metadata": { "id": "NzJrFbMweHx5" }, "source": [ "
\n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
"
|0>
|`reset q[0];`| \n",
"|`gatename(params) qargs;`| supported for ONLY the supported subset of standard gates defined in \"qelib1.inc\"|Apply a user-defined unitary gate|`rz(pi/2) q[0];`|\n",
"|`if(creg==int) qop;`| NOT supported| Conditionally apply quantum operation|`if(c==5) CX q[0],q[1];`|\n",
"|`barrier qargs;`| NOT supported| Prevent transformations across this source line|`barrier q[0],q[1];`|\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "3JUIezc4vrA7"
},
"source": [
"#### Gate conversion rules \n",
"\n",
"Note: The standard Quantum Experience gates (defined in [qelib.inc](https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/qasm/libs/qelib1.inc)) are \n",
"based on the `U` and `CX` built-in instructions, and we could generate them dynamically. Instead, we chose to map them to native Cirq gates explicitly, which results in a more user-friendly circuit. \n",
"\n",
"| QE gates| Cirq translation| Notes|\n",
"| --------| --------| --------|\n",
"|`U(θ,φ,λ)` |`QasmUGate(θ/π,φ/π,λ/π)`|cirq gate takes angles in half turns| \n",
"|`CX` |`cirq.CX`|| \n",
"|`u3(θ,φ,λ)`|`QasmUGate(θ/π,φ/π,λ/π)`|cirq gate takes angles in half turns|\n",
"|`u2(φ,λ) = u3(π/2,φ,λ)`|`QasmUGate(1/2,φ/π,λ/π)`|cirq gate takes angles in half turns| \n",
"|`u1(λ) = u3(0,0,λ)`| NOT supported || \n",
"|`id`|`cirq.Identity`| one single-qubit Identity gate is created for each qubit if applied on a register| \n",
"|`u0(γ)`| NOT supported| this is the \"WAIT gate\" for length γ in QE| \n",
"|`x`|`cirq.X`|| \n",
"|`y`|`cirq.Y`|| \n",
"|`z`|`cirq.Z`|| \n",
"|`h`|`cirq.H`|| \n",
"|`s`|`cirq.S`|| \n",
"|`sdg`|``cirq.S**-1``|| \n",
"|`t`|`cirq.T`|| \n",
"|`tdg`|``cirq.T**-1``||\n",
"|`rx(θ)`|`cirq.Rx(θ)`|| \n",
"|`ry(θ)`|`cirq.Ry(θ)`|| \n",
"|`rz(θ)`|`cirq.Rz(θ)`|| \n",
"|`cx`|`cirq.CX`|| \n",
"|`cy`|`cirq.ControlledGate(cirq.Y)`|| \n",
"|`cz`|`cirq.CZ`|| \n",
"|`ch`|`cirq.ControlledGate(cirq.H)`|| \n",
"|`swap`|`cirq.SWAP`|| \n",
"|`ccx`|`cirq.CCX`|| \n",
"|`cswap`|`cirq.CSWAP`|| \n",
"|`crz`| NOT supported || \n",
"|`cu1`| NOT supported|| \n",
"|`cu3`| NOT supported|| \n",
"|`rzz`| NOT supported|| "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "_o3T5f6Lvv7L"
},
"source": [
"#### Mapping quantum registers to qubits \n",
"\n",
"For a quantum register `qreg qfoo[n];` the QASM importer will create `cirq.NamedQubit`s named `qfoo_0`..`qfoo_