{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Julia Version 1.7.1\n", "Commit ac5cc99908 (2021-12-22 19:35 UTC)\n", "Platform Info:\n", " OS: Linux (x86_64-pc-linux-gnu)\n", " CPU: AMD Ryzen 5 PRO 3400GE w/ Radeon Vega Graphics\n", " WORD_SIZE: 64\n", " LIBM: libopenlibm\n", " LLVM: libLLVM-12.0.1 (ORCJIT, znver1)\n", "Environment:\n", " JULIA_EDITOR = nvim\n", " JULIA_SHELL = /bin/bash\n" ] } ], "source": [ "versioninfo()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# DiracNotation.jl sample\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By using this package, matrix representation is changed into Dirac notation.\n", "\n", "## Basic usage\n", "\n", "In order to change display style, all you have to do is import this package." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:19:59.532000+09:00", "start_time": "2018-09-15T08:19:59.423Z" } }, "outputs": [], "source": [ "using DiracNotation, LinearAlgebra, Random; Random.seed!(0);" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:20:02.009000+09:00", "start_time": "2018-09-15T08:20:01.782Z" } }, "outputs": [], "source": [ "ket = normalize(rand(Complex{Float64}, 4)); bra = ket';" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:20:04.171000+09:00", "start_time": "2018-09-15T08:20:02.697Z" }, "scrolled": true }, "outputs": [ { "data": { "text/markdown": [ "$|\\psi\\rangle = (0.296201+0.0500454im)|00\\rangle+(0.62945+0.0627674im)|01\\rangle+(0.483044+0.0849307im)|10\\rangle+(0.0798625+0.512534im)|11\\rangle\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dirac(ket)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:20:12.002000+09:00", "start_time": "2018-09-15T08:20:11.999Z" } }, "outputs": [ { "data": { "text/markdown": [ "$\\langle\\psi| = (0.296201-0.0500454im)\\langle00|+(0.62945-0.0627674im)\\langle01|+(0.483044-0.0849307im)\\langle10|+(0.0798625-0.512534im)\\langle11|\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dirac(bra)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:20:35.471000+09:00", "start_time": "2018-09-15T08:20:35.469Z" } }, "outputs": [ { "data": { "text/markdown": [ "$|\\psi\\rangle = (0.296201+0.0500454im)|00\\rangle+(0.62945+0.0627674im)|01\\rangle+(0.483044+0.0849307im)|10\\rangle+(0.0798625+0.512534im)|11\\rangle\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dirac(ket)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:20:36.769000+09:00", "start_time": "2018-09-15T08:20:36.542Z" }, "scrolled": true }, "outputs": [ { "data": { "text/markdown": [ "$\\hat{\\rho} = 0.28951|0\\rangle\\langle0|+0.538639|0\\rangle\\langle1|+0.02855|1\\rangle\\langle0|+0.89699|1\\rangle\\langle1|\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "op = rand(2,2);\n", "dirac(op)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Qudit system and Operator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "7 dimensional state\n", "\n", "$| \\psi \\rangle \\in \\mathbb{C}^7$" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.216000+09:00", "start_time": "2018-09-15T08:14:36.004Z" } }, "outputs": [ { "data": { "text/markdown": [ "$|\\psi\\rangle = 0.178768|0\\rangle+0.234424|1\\rangle+0.29376|2\\rangle+0.625728|3\\rangle+0.515035|4\\rangle+0.107587|5\\rangle+0.398021|6\\rangle\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dim = 7\n", "ket = normalize(rand(dim))\n", "dirac(ket, [dim])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "qubit-qutrit\n", "\n", "$| \\psi \\rangle \\in \\mathbb{C}^2 \\otimes \\mathbb{C}^3$" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.255000+09:00", "start_time": "2018-09-15T08:14:36.007Z" } }, "outputs": [ { "data": { "text/markdown": [ "$|\\psi\\rangle = -0.248521|00\\rangle-0.0145385|01\\rangle-0.701118|02\\rangle-0.334889|10\\rangle+0.0444954|11\\rangle-0.57648|12\\rangle\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "dims = [2,3]\n", "ket = normalize(randn(prod(dims)))\n", "dirac(ket, dims)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Operator\n", "\n", "$A: V \\rightarrow W$ where $V = \\mathbb{C}^2$ and $W = \\mathbb{C}^3$" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.263000+09:00", "start_time": "2018-09-15T08:14:36.009Z" } }, "outputs": [ { "data": { "text/markdown": [ "$\\hat{\\rho} = 0.573612|0\\rangle\\langle0|+0.862693|0\\rangle\\langle1|+0.443074|1\\rangle\\langle0|+0.518326|1\\rangle\\langle1|+0.62073|2\\rangle\\langle0|+0.766871|2\\rangle\\langle1|\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "A = rand(3,2)\n", "dirac(A, [3], [2])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Precision" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.287000+09:00", "start_time": "2018-09-15T08:14:36.013Z" } }, "outputs": [], "source": [ "DiracNotation.set_properties(precision=2)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.289000+09:00", "start_time": "2018-09-15T08:14:36.015Z" } }, "outputs": [ { "data": { "text/markdown": [ "$\\hat{\\rho} = 0.13|0\\rangle\\langle0|+0.35|0\\rangle\\langle1|+0.12|0\\rangle\\langle2|+0.087|1\\rangle\\langle0|+0.19|1\\rangle\\langle1|+0.9|1\\rangle\\langle2|\n", "$" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "op = rand(2,3);\n", "leftdims = [2];\n", "rightdims = [3];\n", "dirac(op, leftdims, rightdims)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Disable mathjax" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.320000+09:00", "start_time": "2018-09-15T08:14:36.018Z" } }, "outputs": [], "source": [ "DiracNotation.set_properties(islatex=false)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2018-09-15T17:14:41.545000+09:00", "start_time": "2018-09-15T08:14:36.021Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ρ = 0.42|0⟩⟨0|+0.88|0⟩⟨1|+0.84|0⟩⟨2|+0.71|1⟩⟨0|+0.93|1⟩⟨1|+0.98|1⟩⟨2|\n" ] } ], "source": [ "op = rand(2,3);\n", "leftdims = [2];\n", "rightdims = [3];\n", "dirac(op, leftdims, rightdims)" ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "kernelspec": { "display_name": "Julia 1.7.1", "language": "julia", "name": "julia-1.7" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.7.1" }, "toc": { "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "toc_cell": true, "toc_position": {}, "toc_section_display": "block", "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }