{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Initialisation\n", "***\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Qiskit originally starts calculations with all the qubits in the zero states. Our dm_simulator provides the option for the user to initialise to some very common states (density matrix) used in quantum computations. If no options are set then states defaults to the zero states." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Available Options\n", "1. default\n", "2. binary string\n", "3. maximally mixed\n", "4. uniform superposition" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from qiskit import *\n", "backend = BasicAer.get_backend('dm_simulator')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 1 : Maximally Mixed State" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "No measurements in circuit \"circuit0\", classical register will remain all zeros.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Density Matrix: \n", " [[0.5+0.j 0. +0.j]\n", " [0. +0.j 0.5+0.j]]\n" ] } ], "source": [ "qc1 = QuantumCircuit(1)\n", "options1 = {\n", " 'custom_densitymatrix': 'max_mixed'\n", "}\n", "run1 = execute(qc1,backend,**options1)\n", "result1 = run1.result()\n", "print('Density Matrix: \\n',result1['results'][0]['data']['densitymatrix'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Simllarly, uniformly superposed state can be created by replacing 'max_mixed' with 'uniform_superpos'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Example 2 : Binary String" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "No measurements in circuit \"circuit0\", classical register will remain all zeros.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Density Matrix: \n", " [[0.+0.j 0.+0.j 0.+0.j 0.+0.j]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j]\n", " [0.+0.j 0.+0.j 1.+0.j 0.+0.j]\n", " [0.+0.j 0.+0.j 0.+0.j 0.+0.j]]\n" ] } ], "source": [ "qc2 = QuantumCircuit(2)\n", "options2 = {\n", " 'custom_densitymatrix': 'binary_string',\n", " 'initial_densitymatrix': '01'\n", "}\n", "backend = BasicAer.get_backend('dm_simulator')\n", "run2 = execute(qc2,backend,**options2)\n", "result2 = run2.result()\n", "print('Density Matrix: \\n',result2['results'][0]['data']['densitymatrix'])" ] } ], "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 }