{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example 1: Entanglement\n", "For this first example, we will create a Bell State -- an entangled state which as an equal superposition of |00> and |11>." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, import the Qiskit stuff. Then create registers and a circuit." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit\n", "from qiskit import Aer, execute\n", "from qiskit.tools.visualization import plot_histogram\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Bell State is created using a Hadamard gate and a CNOT (controlled-X). We insert these gates into the circuit, and then draw the circuit." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "qc.draw(output='mpl')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We add some measurements, so that we can see how the circuit behaves." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qc.measure(q,c) # measures all qubits in the register\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The circuit is done, and we are ready to simulate it. We use the **qasm_simulator** from the Aer provider. We display the results in two ways: (1) as a list of counts, and (2) as a histogram." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "backend = Aer.get_backend('qasm_simulator')\n", "job = execute(qc, backend, shots=512) # shots default = 1024\n", "result = job.result()\n", "print(result.get_counts())\n", "plot_histogram(result.get_counts())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.7" } }, "nbformat": 4, "nbformat_minor": 2 }