{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction: Getting Started\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Building a circuit\n", "Creating a circuit is exactly similar to the qiskit. Almost exact same command can be used as shown in the [tutorial](https://github.com/Qiskit/qiskit-tutorials/blob/master/qiskit/terra/quantum_circuits.ipynb). Few examples are given below." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 1 : Qubits and Classical bits" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
         \n",
       "q1_0: |0>\n",
       "         \n",
       "q1_1: |0>\n",
       "         \n",
       " c1_0: 0 \n",
       "         \n",
       " c1_1: 0 \n",
       "         
" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q1 = QuantumRegister(2,'q1')\n", "c1 = ClassicalRegister(2,'c1')\n", "qc1 = QuantumCircuit(q1,c1)\n", "qc1.draw()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 2 : Simple Gates" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
         ┌───┐          \n",
       "q2_0: |0>┤ S ├──■───────\n",
       "         └───┘┌─┴─┐┌───┐\n",
       "q2_1: |0>─────┤ X ├┤ H ├\n",
       "              └───┘└───┘
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "q2 = QuantumRegister(2,'q2')\n", "qc2 = QuantumCircuit(q2)\n", "qc2.s(q2[0])\n", "qc2.cx(q2[0],q2[1])\n", "qc2.h(q2[1])\n", "qc2.draw()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 3 : " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
        ┌───┐          \n",
       "q_0: |0>┤ S ├──■───────\n",
       "        └───┘┌─┴─┐┌───┐\n",
       "q_1: |0>─────┤ X ├┤ H ├\n",
       "             └───┘└───┘
" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qc3 = QuantumCircuit(2)\n", "qc3.s(0)\n", "qc3.cx(0,1)\n", "qc3.h(1)\n", "qc3.draw()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 4 : More gates" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
        ┌───┐           ░ ┌──────────┐     ┌─┐   \n",
       "q_0: |0>┤ S ├──■────────░─┤ U1(3.14) ├──■──┤M├───\n",
       "        └───┘┌─┴─┐┌───┐ ░ └──────────┘┌─┴─┐└╥┘┌─┐\n",
       "q_1: |0>─────┤ X ├┤ H ├─░─────────────┤ X ├─╫─┤M├\n",
       "             └───┘└───┘ ░             └───┘ ║ └╥┘\n",
       " c_0: 0 ════════════════════════════════════╩══╬═\n",
       "                                               ║ \n",
       " c_1: 0 ═══════════════════════════════════════╩═\n",
       "                                                 
" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "qc4 = QuantumCircuit(2,2)\n", "qc4.s(0)\n", "qc4.cx(0,1)\n", "qc4.h(1)\n", "qc4.barrier()\n", "qc4.u1(3.14,0)\n", "qc4.cx(0,1)\n", "qc4.measure(0,0)\n", "qc4.measure(1,1)\n", "qc4.draw()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }