{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Deutsch-Joszja Algorithm\n" ] }, { "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" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create quantum/classical registers and a quantum circuit\n", "\n", "qin = QuantumRegister(2)\n", "qout = QuantumRegister(1)\n", "c = ClassicalRegister(2)\n", "qc = QuantumCircuit(qin,qout,c)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Copy the equal2 function from Example 3\n", "# This is balanced function\n", "\n", "def equal2(circ, input, output) :\n", " circ.cx(input[0],output)\n", " circ.cx(input[1],output)\n", " circ.x(output)\n", "\n", "# This is a constant function that doesn't change anything\n", "def constant2(circ, input, output) :\n", " circ.iden(output)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Build the Deutsh-Josza circuit\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qc.draw(output='mpl')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Simulate and show results\n", "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }