├── current_version.txt ├── _themes └── bootstrap │ ├── localtoc.html │ ├── static │ ├── js │ │ └── jquery-fix.js │ ├── bootstrap-3.2.0 │ │ └── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ └── glyphicons-halflings-regular.woff │ ├── bootswatch-3.2.0 │ │ └── fonts │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ └── glyphicons-halflings-regular.woff │ ├── bootstrap-sphinx.css_t │ └── bootstrap-sphinx.js_t │ ├── sourcelink.html │ ├── navbartoc.html │ ├── searchbox.html │ ├── navbarsearchbox.html │ ├── globaltoc.html │ ├── relations.html │ ├── searchresults.html │ ├── theme.conf │ ├── navbar-2.html │ ├── navbar.html │ ├── search.html │ └── layout.html ├── figures ├── about.png ├── demos.png ├── jsps.jpg ├── logo.png ├── favicon.ico ├── citing │ ├── us.png │ ├── bibtex.png │ ├── qutip.bib │ └── qutip2.bib ├── korea-logo.png ├── nav │ ├── citing.png │ ├── home.png │ ├── spacer.png │ ├── download.png │ ├── features.png │ ├── home_red.png │ ├── support.png │ ├── updates.png │ ├── citing_red.png │ ├── end_spacer.png │ ├── support_red.png │ ├── updates_red.png │ ├── documentation.png │ ├── download_red.png │ ├── features_red.png │ ├── qutip2_header.png │ ├── qutip_header.png │ └── documentation_red.png ├── qutip_logo.png ├── riken-logo.png ├── wide_logo.png ├── bloch_decay.mp4 ├── download │ ├── gz.png │ ├── zip.png │ └── arrow.png ├── support │ ├── paul.png │ ├── rob.png │ ├── arrow.png │ ├── brain.png │ ├── issue.png │ ├── manual.png │ └── discussion.png ├── updates │ └── blog.png ├── features │ ├── docs.png │ ├── ninja.png │ ├── schcat.png │ ├── sparse.png │ ├── dynamics.png │ ├── mc_performance.png │ ├── me_performance.png │ └── multiprocessing.png ├── home │ ├── visitors.png │ └── multiprocessing.png └── documentation │ ├── pdf.png │ ├── online.png │ └── developer.png ├── guide ├── qutip_org.png ├── figures │ ├── bloch3d+data.png │ ├── bloch3d+points.png │ └── bloch3d-blank.png ├── quide-basics-qobj-box.png ├── scripts │ ├── bloch_ex1.py │ ├── correlation_ex2.py │ ├── correlation_ex1.py │ ├── floquet_ex0.py │ ├── correlation_ex3.py │ ├── correlation_ex4.py │ ├── ex_bloch_animation.py │ ├── floquet_ex1.py │ ├── ex_steady.py │ ├── floquet_ex2.py │ ├── floquet_ex3.py │ └── spectrum_ex1.py ├── guide-dynamics.rst ├── guide.rst ├── guide-overview.rst ├── guide-random.rst ├── guide-settings.rst ├── guide-parfor.rst ├── dynamics │ ├── dynamics-options.rst │ └── dynamics-data.rst ├── guide-saving.rst ├── guide-eseries.rst ├── guide-correlation.rst ├── guide-tensor.rst └── guide-steady.rst ├── _sphinxext └── requirements.txt ├── .gitignore ├── _templates └── layout.html ├── QuTiP_tree_plot ├── d3_data │ ├── tree.css │ └── tree-radial.js ├── qutip_org.html └── qutip-structure.py ├── apidoc ├── apidoc.rst ├── classes.rst └── functions.rst ├── latex_output_files ├── README.md └── latex_preamble.tex ├── README.md ├── index.rst ├── _static └── site.css ├── biblio.rst ├── contributors.rst ├── frontmatter.rst ├── Makefile ├── contrib ├── sim_ent_qkd │ └── sim_ent_qkd.py └── qpt.py └── conf.py /current_version.txt: -------------------------------------------------------------------------------- 1 | 3.1.0 2 | -------------------------------------------------------------------------------- /_themes/bootstrap/localtoc.html: -------------------------------------------------------------------------------- 1 | {{ toc }} 2 | -------------------------------------------------------------------------------- /figures/about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/about.png -------------------------------------------------------------------------------- /figures/demos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/demos.png -------------------------------------------------------------------------------- /figures/jsps.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/jsps.jpg -------------------------------------------------------------------------------- /figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/logo.png -------------------------------------------------------------------------------- /figures/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/favicon.ico -------------------------------------------------------------------------------- /guide/qutip_org.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/guide/qutip_org.png -------------------------------------------------------------------------------- /figures/citing/us.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/citing/us.png -------------------------------------------------------------------------------- /figures/korea-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/korea-logo.png -------------------------------------------------------------------------------- /figures/nav/citing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/citing.png -------------------------------------------------------------------------------- /figures/nav/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/home.png -------------------------------------------------------------------------------- /figures/nav/spacer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/spacer.png -------------------------------------------------------------------------------- /figures/qutip_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/qutip_logo.png -------------------------------------------------------------------------------- /figures/riken-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/riken-logo.png -------------------------------------------------------------------------------- /figures/wide_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/wide_logo.png -------------------------------------------------------------------------------- /_sphinxext/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | ipython 3 | -e git+http://github.com/qutip/qutip.git#egg=qutip 4 | -------------------------------------------------------------------------------- /figures/bloch_decay.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/bloch_decay.mp4 -------------------------------------------------------------------------------- /figures/download/gz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/download/gz.png -------------------------------------------------------------------------------- /figures/download/zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/download/zip.png -------------------------------------------------------------------------------- /figures/nav/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/download.png -------------------------------------------------------------------------------- /figures/nav/features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/features.png -------------------------------------------------------------------------------- /figures/nav/home_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/home_red.png -------------------------------------------------------------------------------- /figures/nav/support.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/support.png -------------------------------------------------------------------------------- /figures/nav/updates.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/updates.png -------------------------------------------------------------------------------- /figures/support/paul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/paul.png -------------------------------------------------------------------------------- /figures/support/rob.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/rob.png -------------------------------------------------------------------------------- /figures/updates/blog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/updates/blog.png -------------------------------------------------------------------------------- /figures/citing/bibtex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/citing/bibtex.png -------------------------------------------------------------------------------- /figures/download/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/download/arrow.png -------------------------------------------------------------------------------- /figures/features/docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/docs.png -------------------------------------------------------------------------------- /figures/features/ninja.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/ninja.png -------------------------------------------------------------------------------- /figures/features/schcat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/schcat.png -------------------------------------------------------------------------------- /figures/features/sparse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/sparse.png -------------------------------------------------------------------------------- /figures/home/visitors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/home/visitors.png -------------------------------------------------------------------------------- /figures/nav/citing_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/citing_red.png -------------------------------------------------------------------------------- /figures/nav/end_spacer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/end_spacer.png -------------------------------------------------------------------------------- /figures/nav/support_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/support_red.png -------------------------------------------------------------------------------- /figures/nav/updates_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/updates_red.png -------------------------------------------------------------------------------- /figures/support/arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/arrow.png -------------------------------------------------------------------------------- /figures/support/brain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/brain.png -------------------------------------------------------------------------------- /figures/support/issue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/issue.png -------------------------------------------------------------------------------- /figures/support/manual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/manual.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.png 3 | *.pyc 4 | *.pyx 5 | *.dat 6 | *.qu 7 | *.dat 8 | *~ 9 | 10 | HEAD 11 | -------------------------------------------------------------------------------- /figures/documentation/pdf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/documentation/pdf.png -------------------------------------------------------------------------------- /figures/features/dynamics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/dynamics.png -------------------------------------------------------------------------------- /figures/nav/documentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/documentation.png -------------------------------------------------------------------------------- /figures/nav/download_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/download_red.png -------------------------------------------------------------------------------- /figures/nav/features_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/features_red.png -------------------------------------------------------------------------------- /figures/nav/qutip2_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/qutip2_header.png -------------------------------------------------------------------------------- /figures/nav/qutip_header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/qutip_header.png -------------------------------------------------------------------------------- /figures/documentation/online.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/documentation/online.png -------------------------------------------------------------------------------- /figures/home/multiprocessing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/home/multiprocessing.png -------------------------------------------------------------------------------- /figures/support/discussion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/support/discussion.png -------------------------------------------------------------------------------- /guide/figures/bloch3d+data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/guide/figures/bloch3d+data.png -------------------------------------------------------------------------------- /guide/figures/bloch3d+points.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/guide/figures/bloch3d+points.png -------------------------------------------------------------------------------- /guide/figures/bloch3d-blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/guide/figures/bloch3d-blank.png -------------------------------------------------------------------------------- /guide/quide-basics-qobj-box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/guide/quide-basics-qobj-box.png -------------------------------------------------------------------------------- /figures/nav/documentation_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/nav/documentation_red.png -------------------------------------------------------------------------------- /figures/documentation/developer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/documentation/developer.png -------------------------------------------------------------------------------- /figures/features/mc_performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/mc_performance.png -------------------------------------------------------------------------------- /figures/features/me_performance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/me_performance.png -------------------------------------------------------------------------------- /figures/features/multiprocessing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/figures/features/multiprocessing.png -------------------------------------------------------------------------------- /_themes/bootstrap/static/js/jquery-fix.js: -------------------------------------------------------------------------------- 1 | // No Conflict in later (our) version of jQuery 2 | window.$jqTheme = jQuery.noConflict(true); -------------------------------------------------------------------------------- /_templates/layout.html: -------------------------------------------------------------------------------- 1 | {# Import the theme's layout. #} 2 | {% extends "!layout.html" %} 3 | 4 | {# Custom CSS overrides #} 5 | {% set bootswatch_css_custom = ['_static/site.css'] %} -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootstrap-3.2.0/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jrjohansson/qutip-doc/master/_themes/bootstrap/static/bootswatch-3.2.0/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /_themes/bootstrap/sourcelink.html: -------------------------------------------------------------------------------- 1 | {%- if show_source and has_source and sourcename %} 2 | 6 | {%- endif %} 7 | -------------------------------------------------------------------------------- /QuTiP_tree_plot/d3_data/tree.css: -------------------------------------------------------------------------------- 1 | .node circle { 2 | fill: #fff; 3 | stroke: mediumpurple; 4 | stroke-width: 1px; 5 | } 6 | 7 | .node { 8 | font: 8px sans-serif; 9 | } 10 | 11 | .link { 12 | fill: none; 13 | stroke: #ccc; 14 | stroke-width: 1px; 15 | } 16 | -------------------------------------------------------------------------------- /guide/scripts/bloch_ex1.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | 3 | b=Bloch() 4 | xp=[cos(th) for th in linspace(0,2*pi,20)] 5 | yp=[sin(th) for th in linspace(0,2*pi,20)] 6 | zp=zeros(20) 7 | xz=zeros(20) 8 | yz=[sin(th) for th in linspace(0,pi,20)] 9 | zz=[cos(th) for th in linspace(0,pi,20)] 10 | b.add_points([xp,yp,zp]) 11 | b.add_points([xz,yz,zz]) 12 | b.show() 13 | -------------------------------------------------------------------------------- /_themes/bootstrap/navbartoc.html: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /_themes/bootstrap/searchbox.html: -------------------------------------------------------------------------------- 1 | {%- if pagename != "search" %} 2 |
3 |
4 | 5 |
6 | 7 | 8 |
9 | {%- endif %} 10 | -------------------------------------------------------------------------------- /_themes/bootstrap/navbarsearchbox.html: -------------------------------------------------------------------------------- 1 | {%- if pagename != "search" %} 2 | 9 | {%- endif %} 10 | -------------------------------------------------------------------------------- /apidoc/apidoc.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _apidoc: 5 | 6 | ***************** 7 | API documentation 8 | ***************** 9 | 10 | This chapter contains automatically generated API documentation, including a 11 | complete list of QuTiP's public classes and functions. 12 | 13 | .. toctree:: 14 | :maxdepth: 3 15 | 16 | classes.rst 17 | functions.rst 18 | 19 | -------------------------------------------------------------------------------- /guide/scripts/correlation_ex2.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | times = linspace(0, 10.0, 200) 5 | a = destroy(10) 6 | x = a.dag() + a 7 | H = a.dag() * a 8 | alpha = 2.5 9 | rho0 = coherent_dm(10, alpha) 10 | corr = correlation(H, rho0, times, times, [sqrt(0.25) * a], x, x) 11 | 12 | from pylab import * 13 | pcolor(corr) 14 | xlabel(r'Time $t_2$') 15 | ylabel(r'Time $t_1$') 16 | title(r'Correlation $\left$') 17 | show() 18 | -------------------------------------------------------------------------------- /_themes/bootstrap/globaltoc.html: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /latex_output_files/README.md: -------------------------------------------------------------------------------- 1 | Contents 2 | ------------------------------------------- 3 | latex_preamble.tex contains the formatting options for 4 | the QuTiP latex docs file. 5 | 6 | Copy the sphinx.sty and sphinxmemoir.cls files into the 7 | QuTiP docs latex directory before compiling. 8 | 9 | Instructions 10 | ------------------------------------------- 11 | 12 | The call to: 13 | 14 | \usepackage{times} 15 | \usepackage[Bjarne]{fncychap} 16 | 17 | must be manually removed before compilation due to 18 | an options clash. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Repository for QuTiP documentation 2 | ================================== 3 | 4 | This repository contains the source files for the QuTiP documentation. 5 | 6 | For pre-built documentation, see http://code.google.com/p/qutip/wiki/Documentation 7 | 8 | Build requirements 9 | ------------------ 10 | 11 | * Sphinx: http://sphinx-doc.org/ 12 | * LaTeX and pdflatex. 13 | * The QuTiP source code (https://github.com/qutip/qutip) 14 | 15 | Build 16 | ----- 17 | 18 | To build the documentation run: 19 | 20 | $ make html pdflatex 21 | -------------------------------------------------------------------------------- /guide/scripts/correlation_ex1.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | times = linspace(0,10.0,200) 5 | a = destroy(10) 6 | x = a.dag() + a 7 | H = a.dag() * a 8 | 9 | corr1 = correlation_ss(H, times, [sqrt(0.5) * a], x, x) 10 | corr2 = correlation_ss(H, times, [sqrt(1.0) * a], x, x) 11 | corr3 = correlation_ss(H, times, [sqrt(2.0) * a], x, x) 12 | 13 | from pylab import * 14 | plot(times, real(corr1), times, real(corr2), times, real(corr3)) 15 | xlabel(r'Time $t$') 16 | ylabel(r'Correlation $\left$') 17 | show() 18 | -------------------------------------------------------------------------------- /index.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson 3 | 4 | 5 | QuTiP: Quantum Toolbox in Python (3.1.0) 6 | ======================================== 7 | 8 | .. toctree:: 9 | :maxdepth: 3 10 | 11 | frontmatter.rst 12 | installation.rst 13 | guide/guide.rst 14 | apidoc/apidoc.rst 15 | changelog.rst 16 | contributors.rst 17 | biblio.rst 18 | 19 | 20 | Indices and tables 21 | ==================== 22 | 23 | * :ref:`genindex` 24 | * :ref:`modindex` 25 | * :ref:`search` 26 | 27 | -------------------------------------------------------------------------------- /QuTiP_tree_plot/qutip_org.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | QuTiP Organization 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /guide/guide-dynamics.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _dynamics: 5 | 6 | ****************************************** 7 | Time Evolution and Quantum System Dynamics 8 | ****************************************** 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | dynamics/dynamics-data.rst 14 | dynamics/dynamics-master.rst 15 | dynamics/dynamics-monte.rst 16 | dynamics/dynamics-bloch-redfield.rst 17 | dynamics/dynamics-time.rst 18 | dynamics/dynamics-floquet.rst 19 | dynamics/dynamics-options.rst 20 | 21 | 22 | -------------------------------------------------------------------------------- /guide/guide.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _guide: 5 | 6 | ******************* 7 | Users Guide 8 | ******************* 9 | 10 | .. toctree:: 11 | :maxdepth: 2 12 | 13 | guide-overview.rst 14 | guide-basics.rst 15 | guide-states.rst 16 | guide-tensor.rst 17 | guide-dynamics.rst 18 | guide-steady.rst 19 | guide-eseries.rst 20 | guide-correlation.rst 21 | guide-bloch.rst 22 | guide-visualization.rst 23 | guide-parfor.rst 24 | guide-saving.rst 25 | guide-random.rst 26 | guide-settings.rst 27 | 28 | -------------------------------------------------------------------------------- /figures/citing/qutip.bib: -------------------------------------------------------------------------------- 1 | @article{Johansson20121760, 2 | title = "QuTiP: An open-source Python framework for the dynamics of open quantum systems", 3 | journal = "Computer Physics Communications", 4 | volume = "183", 5 | number = "8", 6 | pages = "1760 - 1772", 7 | year = "2012", 8 | note = "", 9 | issn = "0010-4655", 10 | doi = "10.1016/j.cpc.2012.02.021", 11 | url = "http://www.sciencedirect.com/science/article/pii/S0010465512000835", 12 | author = "J.R. Johansson and P.D. Nation and Franco Nori", 13 | keywords = "Open quantum systems", 14 | keywords = "Lindblad master equation", 15 | keywords = "Quantum Monte Carlo", 16 | keywords = "Python" 17 | } 18 | 19 | -------------------------------------------------------------------------------- /figures/citing/qutip2.bib: -------------------------------------------------------------------------------- 1 | @article{Johansson20131234, 2 | title = "QuTiP 2: A Python framework for the dynamics of open quantum systems", 3 | journal = "Computer Physics Communications", 4 | volume = "184", 5 | number = "4", 6 | pages = "1234 - 1240", 7 | year = "2013", 8 | note = "", 9 | issn = "0010-4655", 10 | doi = "10.1016/j.cpc.2012.11.019", 11 | url = "http://www.sciencedirect.com/science/article/pii/S0010465512003955", 12 | author = "J.R. Johansson and P.D. Nation and Franco Nori", 13 | keywords = "Open quantum systems", 14 | keywords = "Lindblad", 15 | keywords = "Bloch–Redfield", 16 | keywords = "Floquet–Markov", 17 | keywords = "Master equation", 18 | keywords = "Quantum Monte Carlo", 19 | keywords = "Python" 20 | } -------------------------------------------------------------------------------- /guide/scripts/floquet_ex0.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | delta = 0.2 * 2*pi; eps0 = 0.0 * 2*pi 5 | omega = 1.0 * 2*pi; A_vec = linspace(0, 10, 100) * omega; 6 | T = (2*pi)/omega 7 | tlist = linspace(0.0, 10 * T, 101) 8 | psi0 = basis(2,0) 9 | 10 | q_energies = zeros((len(A_vec), 2)) 11 | 12 | H0 = delta/2.0 * sigmaz() - eps0/2.0 * sigmax() 13 | args = omega 14 | for idx, A in enumerate(A_vec): 15 | H1 = A/2.0 * sigmax() 16 | H = [H0, [H1, lambda t, w: sin(w*t)]] 17 | f_modes,f_energies = floquet_modes(H, T, args, True) 18 | q_energies[idx,:] = f_energies 19 | 20 | # plot the results 21 | from pylab import * 22 | plot(A_vec/omega, real(q_energies[:,0]) / delta, 'b', \ 23 | A_vec/omega, real(q_energies[:,1]) / delta, 'r') 24 | xlabel(r'$A/\omega$') 25 | ylabel(r'Quasienergy / $\Delta$') 26 | title(r'Floquet quasienergies') 27 | show() 28 | -------------------------------------------------------------------------------- /guide/scripts/correlation_ex3.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | N = 15 5 | taus = linspace(0,10.0,200) 6 | a = destroy(N) 7 | H = 2 * pi * a.dag() * a 8 | 9 | # collapse operator 10 | G1 = 0.75 11 | n_th = 2.00 # bath temperature in terms of excitation number 12 | c_ops = [sqrt(G1 * (1 + n_th)) * a, sqrt(G1 * n_th) * a.dag()] 13 | 14 | # start with a coherent state 15 | rho0 = coherent_dm(N, 2.0) 16 | 17 | # first calculate the occupation number as a function of time 18 | n = mesolve(H, rho0, taus, c_ops, [a.dag() * a]).expect[0] 19 | 20 | # calculate the correlation function G1 and normalize with n to obtain g1 21 | G1 = correlation(H, rho0, None, taus, c_ops, a.dag(), a) 22 | g1 = G1 / sqrt(n[0] * n) 23 | 24 | from pylab import * 25 | plot(taus, g1, 'b') 26 | plot(taus, n, 'r') 27 | title('Decay of a coherent state to an incoherent (thermal) state') 28 | xlabel(r'$\tau$') 29 | legend((r'First-order coherence function $g^{(1)}(\tau)$', 30 | r'occupation number $n(\tau)$')) 31 | show() 32 | -------------------------------------------------------------------------------- /guide/scripts/correlation_ex4.py: -------------------------------------------------------------------------------- 1 | import pylab as plt 2 | from qutip import * 3 | from scipy import * 4 | 5 | N = 25 6 | taus = linspace(0, 25.0, 200) 7 | a = destroy(N) 8 | H = 2 * pi * a.dag() * a 9 | 10 | kappa = 0.25 11 | n_th = 2.0 # bath temperature in terms of excitation number 12 | c_ops = [sqrt(kappa * (1 + n_th)) * a, sqrt(kappa * n_th) * a.dag()] 13 | 14 | states = [{'state': coherent_dm(N, sqrt(2.0)), 'label': "coherent state"}, 15 | {'state': thermal_dm(N, 2.0), 'label': "thermal state"}, 16 | {'state': fock_dm(N, 2), 'label': "Fock state"}] 17 | 18 | fig, ax = plt.subplots(1, 1) 19 | 20 | for state in states: 21 | rho0 = state['state'] 22 | 23 | # first calculate the occupation number as a function of time 24 | n = mesolve(H, rho0, taus, c_ops, [a.dag() * a]).expect[0] 25 | 26 | # calculate the correlation function G2 and normalize with n(0)n(t) to 27 | # obtain g2 28 | G2 = correlation_4op_1t(H, rho0, taus, c_ops, a.dag(), a.dag(), a, a) 29 | g2 = G2 / (n[0] * n) 30 | 31 | ax.plot(taus, real(g2), label=state['label']) 32 | 33 | ax.legend(loc=0) 34 | ax.set_xlabel(r'$\tau$') 35 | ax.set_ylabel(r'$g^{(2)}(\tau)$') 36 | plt.show() 37 | -------------------------------------------------------------------------------- /_themes/bootstrap/relations.html: -------------------------------------------------------------------------------- 1 | {# Switch to icon instead of text in `sm` view size for BS3 only. #} 2 | {%- if prev %} 3 |
  • 4 | 5 | {%- if theme_bootstrap_version == "2" -%}{%- endif -%} 6 | {%- if theme_bootstrap_version == "3" -%}{%- endif -%} 7 | 8 | 9 |
  • 10 | {%- endif %} 11 | {%- if next %} 12 |
  • 13 | 14 | {%- if theme_bootstrap_version == "2" -%}{%- endif -%} 15 | {%- if theme_bootstrap_version == "3" -%}{%- endif -%} 16 | 17 | 18 |
  • 19 | {%- endif %} 20 | -------------------------------------------------------------------------------- /_themes/bootstrap/searchresults.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/searchresults.html 3 | ~~~~~~~~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the body of the search results page. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 |

    Search

    11 |

    12 | From here you can search these documents. Enter your search 13 | words into the box below and click "search". 14 |

    15 | 16 | 21 | 22 | {%- if search_performed %} 23 |

    Search Results

    24 | {%- if not search_results %} 25 |

    Your search did not match any results.

    26 | {%- endif %} 27 | {%- endif %} 28 |
    29 | {%- if search_results %} 30 | 37 | {%- endif %} 38 |
    39 | -------------------------------------------------------------------------------- /_static/site.css: -------------------------------------------------------------------------------- 1 | @import url('http://fonts.googleapis.com/css?family=Source+Code+Pro'); 2 | 3 | 4 | .navbar-text { 5 | color: #e8e8e8 !important; 6 | } 7 | 8 | a { 9 | color: #599AD3; 10 | text-decoration: none; 11 | } 12 | 13 | a:hover, 14 | a:focus { 15 | color: #8C0028; 16 | text-decoration: underline; 17 | } 18 | 19 | a:focus { 20 | outline: thin dotted #333; 21 | outline: 5px auto -webkit-focus-ring-color; 22 | outline-offset: -2px; 23 | } 24 | 25 | code, 26 | pre { 27 | padding: 0 3px 2px; 28 | font-family: "Source Code Pro", Monaco, Menlo, Consolas, "Courier New", monospace; 29 | font-size: 12px; 30 | color: #333333; 31 | -webkit-border-radius: 3px; 32 | -moz-border-radius: 3px; 33 | border-radius: 3px; 34 | } 35 | 36 | .alert { 37 | border-width: 2px; 38 | color: #09224F; 39 | font-weight: bold; 40 | -webkit-border-radius: 3px; 41 | -moz-border-radius: 3px; 42 | border-radius: 3px; 43 | } 44 | 45 | .alert-success { 46 | background-color: #B9E0B0; 47 | border-color: #79C36A; 48 | } 49 | 50 | 51 | .alert-info { 52 | background-color: #A6CBE9; 53 | border-color: #599AD3; 54 | } 55 | 56 | .alert-warning { 57 | background-color: #FBD1A7; 58 | border-color: #F9A65A; 59 | } 60 | 61 | .alert-danger { 62 | background-color: #F7A7AA; 63 | border-color: #F1595F; 64 | } 65 | -------------------------------------------------------------------------------- /guide/scripts/ex_bloch_animation.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | def qubit_integrate(w, theta, gamma1, gamma2, psi0, tlist): 4 | # operators and the hamiltonian 5 | sx = sigmax(); sy = sigmay(); sz = sigmaz(); sm = sigmam() 6 | H = w * (cos(theta) * sz + sin(theta) * sx) 7 | # collapse operators 8 | c_op_list = [] 9 | n_th = 0.5 # temperature 10 | rate = gamma1 * (n_th + 1) 11 | if rate > 0.0: c_op_list.append(sqrt(rate) * sm) 12 | rate = gamma1 * n_th 13 | if rate > 0.0: c_op_list.append(sqrt(rate) * sm.dag()) 14 | rate = gamma2 15 | if rate > 0.0: c_op_list.append(sqrt(rate) * sz) 16 | 17 | 18 | # evolve and calculate expectation values 19 | output = mesolve(H, psi0, tlist, c_op_list, [sx, sy, sz]) 20 | return output.expect[0], output.expect[1], output.expect[2] 21 | 22 | ## calculate the dynamics 23 | w = 1.0 * 2 * pi # qubit angular frequency 24 | theta = 0.2 * pi # qubit angle from sigma_z axis (toward sigma_x axis) 25 | gamma1 = 0.5 # qubit relaxation rate 26 | gamma2 = 0.2 # qubit dephasing rate 27 | # initial state 28 | a = 1.0 29 | psi0 = (a* basis(2,0) + (1-a)*basis(2,1))/(sqrt(a**2 + (1-a)**2)) 30 | tlist = linspace(0,4,250) 31 | #expectation values for ploting 32 | sx, sy, sz = qubit_integrate(w, theta, gamma1, gamma2, psi0, tlist) 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /guide/guide-overview.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2013, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _overview: 5 | 6 | ****************** 7 | Guide Overview 8 | ****************** 9 | 10 | The goal of this guide is to introduce you to the basic structures and functions that make up QuTiP. This guide is divided up into several sections, each highlighting a specific set of functionalities. In combination with the examples that can be found on the project web page `http://qutip.org/tutorials.html `_, this guide should provide a more or less complete overview. In addition, the :ref:`apidoc` for each function is located at the end of this guide. 11 | 12 | 13 | .. _overview-org: 14 | 15 | Organization 16 | ============= 17 | 18 | QuTiP is designed to be a general framework for solving quantum mechanics problems such as systems composed of few-level quantum systems and harmonic oscillators. To this end, QuTiP is built from a large (and ever growing) library of functions and classes; from :func:`qutip.states.basis` to :func:`qutip.wigner`. The general organization of QuTiP, highlighting the important API available to the user, is shown in the :ref:`figure-qutip_org` 19 | 20 | 21 | .. _figure-qutip_org: 22 | 23 | .. figure:: qutip_org.png 24 | :align: center 25 | :figwidth: 100% 26 | 27 | QuTiP tree-diagram of user accessible functions and classes. 28 | -------------------------------------------------------------------------------- /guide/scripts/floquet_ex1.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | delta = 0.2 * 2*pi; eps0 = 1.0 * 2*pi 5 | A = 0.5 * 2*pi; omega = 1.0 * 2*pi 6 | T = (2*pi)/omega 7 | tlist = linspace(0.0, 10 * T, 101) 8 | psi0 = basis(2,0) 9 | 10 | H0 = - delta/2.0 * sigmax() - eps0/2.0 * sigmaz() 11 | H1 = A/2.0 * sigmaz() 12 | args = {'w': omega} 13 | H = [H0, [H1, lambda t,args: sin(args['w'] * t)]] 14 | 15 | # find the floquet modes for the time-dependent hamiltonian 16 | f_modes_0,f_energies = floquet_modes(H, T, args) 17 | 18 | # decompose the inital state in the floquet modes 19 | f_coeff = floquet_state_decomposition(f_modes_0, f_energies, psi0) 20 | 21 | # calculate the wavefunctions using the from the floquet modes 22 | p_ex = zeros(len(tlist)) 23 | for n, t in enumerate(tlist): 24 | psi_t = floquet_wavefunction_t(f_modes_0, f_energies, f_coeff, t, H, T, args) 25 | p_ex[n] = expect(num(2), psi_t) 26 | 27 | # For reference: calculate the same thing with mesolve 28 | p_ex_ref = mesolve(H, psi0, tlist, [], [num(2)], args).expect[0] 29 | 30 | # plot the results 31 | from pylab import * 32 | plot(tlist, real(p_ex), 'ro', tlist, 1-real(p_ex), 'bo') 33 | plot(tlist, real(p_ex_ref), 'r', tlist, 1-real(p_ex_ref), 'b') 34 | xlabel('Time') 35 | ylabel('Occupation probability') 36 | legend(("Floquet $P_1$", "Floquet $P_0$", "Lindblad $P_1$", "Lindblad $P_0$")) 37 | show() 38 | -------------------------------------------------------------------------------- /guide/scripts/ex_steady.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from pylab import * 3 | from scipy import * 4 | 5 | # Define paramters 6 | N = 20 # number of basis states to consider 7 | a = destroy(N) 8 | H = a.dag() * a 9 | psi0 = basis(N, 10) # initial state 10 | kappa = 0.1 # coupling to oscillator 11 | 12 | # collapse operators 13 | c_op_list = [] 14 | n_th_a = 2 # temperature with average of 2 excitations 15 | rate = kappa * (1 + n_th_a) 16 | if rate > 0.0: 17 | c_op_list.append(sqrt(rate) * a) # decay operators 18 | rate = kappa * n_th_a 19 | if rate > 0.0: 20 | c_op_list.append(sqrt(rate) * a.dag()) # excitation operators 21 | 22 | # find steady-state solution 23 | final_state = steadystate(H, c_op_list) 24 | # find expectation value for particle number in steady state 25 | fexpt = expect(a.dag() * a, final_state) 26 | 27 | tlist = linspace(0, 50, 100) 28 | # monte-carlo 29 | mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=100) 30 | # master eq. 31 | medata = mesolve(H, psi0, tlist, c_op_list, [a.dag() * a]) 32 | 33 | plot(tlist, mcdata.expect[0], tlist, medata.expect[0], lw=2) 34 | # plot steady-state expt. value as horizontal line (should be = 2) 35 | axhline(y=fexpt, color='r', lw=1.5) 36 | ylim([0, 10]) 37 | xlabel('Time', fontsize=14) 38 | ylabel('Number of excitations', fontsize=14) 39 | legend(('Monte-Carlo', 'Master Equation', 'Steady State')) 40 | title('Decay of Fock state $\left|10\\rangle\\right.$' + 41 | ' in a thermal environment with $\langle n\\rangle=2$') 42 | show() 43 | -------------------------------------------------------------------------------- /guide/scripts/floquet_ex2.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | delta = 0.0 * 2*pi; eps0 = 1.0 * 2*pi 5 | A = 0.25 * 2*pi; omega = 1.0 * 2*pi 6 | T = (2*pi)/omega 7 | tlist = linspace(0.0, 10 * T, 101) 8 | psi0 = basis(2,0) 9 | 10 | H0 = - delta/2.0 * sigmax() - eps0/2.0 * sigmaz() 11 | H1 = A/2.0 * sigmax() 12 | args = {'w': omega} 13 | H = [H0, [H1, lambda t,args: sin(args['w'] * t)]] 14 | 15 | # find the floquet modes for the time-dependent hamiltonian 16 | f_modes_0,f_energies = floquet_modes(H, T, args) 17 | 18 | # decompose the inital state in the floquet modes 19 | f_coeff = floquet_state_decomposition(f_modes_0, f_energies, psi0) 20 | 21 | # calculate the wavefunctions using the from the floquet modes 22 | f_modes_table_t = floquet_modes_table(f_modes_0, f_energies, tlist, H, T, args) 23 | p_ex = zeros(len(tlist)) 24 | for n, t in enumerate(tlist): 25 | f_modes_t = floquet_modes_t_lookup(f_modes_table_t, t, T) 26 | psi_t = floquet_wavefunction(f_modes_t, f_energies, f_coeff, t) 27 | p_ex[n] = expect(num(2), psi_t) 28 | 29 | # For reference: calculate the same thing with mesolve 30 | p_ex_ref = mesolve(H, psi0, tlist, [], [num(2)], args).expect[0] 31 | 32 | # plot the results 33 | from pylab import * 34 | plot(tlist, real(p_ex), 'ro', tlist, 1-real(p_ex), 'bo') 35 | plot(tlist, real(p_ex_ref), 'r', tlist, 1-real(p_ex_ref), 'b') 36 | xlabel('Time') 37 | ylabel('Occupation probability') 38 | legend(("Floquet $P_1$", "Floquet $P_0$", "Lindblad $P_1$", "Lindblad $P_0$")) 39 | show() 40 | -------------------------------------------------------------------------------- /QuTiP_tree_plot/d3_data/tree-radial.js: -------------------------------------------------------------------------------- 1 | var r = 1000 / 2; 2 | 3 | var tree = d3.layout.tree() 4 | .size([360, r - 175]) 5 | .separation(function(a, b) { return (a.parent == b.parent ? 1 : 2) / a.depth; }); 6 | 7 | var diagonal = d3.svg.diagonal.radial() 8 | .projection(function(d) { return [d.y, d.x / 180 * Math.PI]; }); 9 | 10 | var vis = d3.select("#chart").append("svg") 11 | .attr("width", r * 2 ) 12 | .attr("height", r * 2 ) 13 | .append("g") 14 | .attr("transform", "translate(" + r + "," + r + ")"); 15 | 16 | d3.json("d3_data/qutip.json", function(json) { 17 | var nodes = tree.nodes(json); 18 | 19 | var link = vis.selectAll("path.link") 20 | .data(tree.links(nodes)) 21 | .enter().append("path") 22 | .attr("class", "link") 23 | .attr("d", diagonal); 24 | 25 | var node = vis.selectAll("g.node") 26 | .data(nodes) 27 | .enter().append("g") 28 | .attr("class", "node") 29 | .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + d.y + ")"; }) 30 | 31 | node.append("circle") 32 | .attr("r", 2.5) 33 | /*.style("fill", function(d) { return d.color; })*/ 34 | .style("stroke", function(d) { return d.color; }); 35 | 36 | node.append("text") 37 | .attr("dx", function(d) { return d.x < 180 ? 8 : -8; }) 38 | .attr("dy", ".31em") 39 | .attr("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; }) 40 | .attr("transform", function(d) { return d.x < 180 ? null : "rotate(180)"; }) 41 | .style("fill", function(d) { return d.color; }) 42 | .text(function(d) { return d.name; }); 43 | }); 44 | -------------------------------------------------------------------------------- /biblio.rst: -------------------------------------------------------------------------------- 1 | .. _biblo: 2 | 3 | Bibliography 4 | ============ 5 | 6 | .. [Hav03] 7 | Havel, T. *Robust procedures for converting among Lindblad, Kraus and matrix representations of quantum dynamical semigroups*. Journal of Mathematical Physics **44** 2, 534 (2003). :doi:`10.1063/1.1518555`. 8 | 9 | .. [Wat13] 10 | Watrous, J. |theory-qi|_, lecture notes. 11 | 12 | .. The trick with |text|_ is to get an italic link, and is described in the 13 | Docutils FAQ at http://docutils.sourceforge.net/FAQ.html#is-nested-inline-markup-possible. 14 | 15 | .. |theory-qi| replace:: *Theory of Quantum Information* 16 | .. _theory-qi: https://cs.uwaterloo.ca/~watrous/CS766/ 17 | 18 | .. [Moh08] 19 | M. Mohseni, A. T. Rezakhani, D. A. Lidar, *Quantum-process tomography: Resource analysis of different strategies*, Phys. Rev. A **77**, 032322 (2008). :doi:`10.1103/PhysRevA.77.032322`. 20 | 21 | .. [Gri98] 22 | M. Grifoni, P. Hänggi, *Driven quantum tunneling*, Physics Reports **304**, 299 (1998). :doi:`10.1016/S0370-1573(98)00022-2`. 23 | 24 | .. [Cre03] 25 | C. E. Creffield, *Location of crossings in the Floquet spectrum of a driven two-level system*, Phys. Rev. B **67**, 165301 (2003). :doi:`10.1103/PhysRevB.67.165301`. 26 | 27 | .. [Gar03] 28 | Gardineer and Zoller, *Quantum Noise* (Springer, 2004). 29 | 30 | .. [Bre02] 31 | H.-P. Breuer and F. Petruccione, *The Theory of Open Quantum Systems* (Oxford, 2002). 32 | 33 | .. [Coh92] 34 | C. Cohen-Tannoudji, J. Dupont-Roc, G. Grynberg, *Atom-Photon Interactions: Basic Processes and Applications*, (Wiley, 1992). 35 | 36 | .. [WBC11] 37 | C. Wood, J. Biamonte, D. G. Cory, *Tensor networks and graphical calculus for 38 | open quantum systems*. :arxiv:`1111.6950` 39 | -------------------------------------------------------------------------------- /guide/scripts/floquet_ex3.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | from scipy import * 3 | 4 | delta = 0.0 * 2*pi; eps0 = 1.0 * 2*pi 5 | A = 0.25 * 2*pi; omega = 1.0 * 2*pi 6 | T = (2*pi)/omega 7 | tlist = linspace(0.0, 20 * T, 101) 8 | psi0 = basis(2,0) 9 | 10 | H0 = - delta/2.0 * sigmax() - eps0/2.0 * sigmaz() 11 | H1 = A/2.0 * sigmax() 12 | args = {'w': omega} 13 | H = [H0, [H1, lambda t,args: sin(args['w'] * t)]] 14 | 15 | # noise power spectrum 16 | gamma1 = 0.1 17 | def noise_spectrum(omega): 18 | return 0.5 * gamma1 * omega/(2*pi) 19 | 20 | # find the floquet modes for the time-dependent hamiltonian 21 | f_modes_0, f_energies = floquet_modes(H, T, args) 22 | 23 | # precalculate mode table 24 | f_modes_table_t = floquet_modes_table(f_modes_0, f_energies, 25 | linspace(0, T, 500 + 1), H, T, args) 26 | 27 | # solve the floquet-markov master equation 28 | output = fmmesolve(H, psi0, tlist, [sigmax()], [], [noise_spectrum], T, args) 29 | 30 | # calculate expectation values in the computational basis 31 | p_ex = zeros(shape(tlist), dtype=complex) 32 | for idx, t in enumerate(tlist): 33 | f_modes_t = floquet_modes_t_lookup(f_modes_table_t, t, T) 34 | p_ex[idx] = expect(num(2), output.states[idx].transform(f_modes_t, True)) 35 | 36 | # For reference: calculate the same thing with mesolve 37 | output = mesolve(H, psi0, tlist, [sqrt(gamma1) * sigmax()], [num(2)], args) 38 | p_ex_ref = output.expect[0] 39 | 40 | # plot the results 41 | from pylab import * 42 | plot(tlist, real(p_ex), 'r--', tlist, 1-real(p_ex), 'b--') 43 | plot(tlist, real(p_ex_ref), 'r', tlist, 1-real(p_ex_ref), 'b') 44 | xlabel('Time') 45 | ylabel('Occupation probability') 46 | legend(("Floquet $P_1$", "Floquet $P_0$", "Lindblad $P_1$", "Lindblad $P_0$")) 47 | show() 48 | -------------------------------------------------------------------------------- /guide/scripts/spectrum_ex1.py: -------------------------------------------------------------------------------- 1 | from qutip import * 2 | import pylab as plt 3 | from scipy import * 4 | from scipy import * 5 | N = 4 # number of cavity fock states 6 | wc = wa = 1.0 * 2 * pi # cavity and atom frequency 7 | g = 0.1 * 2 * pi # coupling strength 8 | kappa = 0.75 # cavity dissipation rate 9 | gamma = 0.25 # atom dissipation rate 10 | 11 | # Jaynes-Cummings Hamiltonian 12 | a = tensor(destroy(N), qeye(2)) 13 | sm = tensor(qeye(N), destroy(2)) 14 | H = wc * a.dag() * a + wa * sm.dag() * sm + g * (a.dag() * sm + a * sm.dag()) 15 | 16 | # collapse operators 17 | n_th = 0.25 18 | c_ops = [sqrt(kappa * (1 + n_th)) * a, sqrt(kappa * n_th) * a.dag(), sqrt(gamma) * sm] 19 | 20 | # calculate the correlation function using the mesolve solver, and then fft to 21 | # obtain the spectrum. Here we need to make sure to evaluate the correlation 22 | # function for a sufficient long time and sufficiently high sampling rate so 23 | # that the discrete Fourier transform (FFT) captures all the features in the 24 | # resulting spectrum. 25 | tlist = linspace(0, 100, 5000) 26 | corr = correlation_ss(H, tlist, c_ops, a.dag(), a) 27 | wlist1, spec1 = spectrum_correlation_fft(tlist, corr) 28 | 29 | 30 | # calculate the power spectrum using spectrum_ss, which internally uses essolve 31 | # to solve for the dynamics 32 | wlist2 = linspace(0.25, 1.75, 200) * 2 * pi 33 | spec2 = spectrum_ss(H, wlist2, c_ops, a.dag(), a) 34 | 35 | # plot the spectra 36 | fig, ax = plt.subplots(1, 1) 37 | ax.plot(wlist1 / (2 * pi), spec1, 'b', lw=2, label='eseries method') 38 | ax.plot(wlist2 / (2 * pi), spec2, 'r--', lw=2, label='me+fft method') 39 | ax.legend() 40 | ax.set_xlabel('Frequency') 41 | ax.set_ylabel('Power spectrum') 42 | ax.set_title('Vacuum Rabi splitting') 43 | ax.set_xlim(wlist2[0]/(2*pi), wlist2[-1]/(2*pi)) 44 | plt.show() 45 | -------------------------------------------------------------------------------- /_themes/bootstrap/theme.conf: -------------------------------------------------------------------------------- 1 | # Bootstrap Theme 2 | [theme] 3 | inherit = basic 4 | stylesheet = basic.css 5 | pygments_style = colorful 6 | 7 | # Configurable options. 8 | [options] 9 | # Navigation bar title. (Default: ``project`` value) 10 | navbar_title = 11 | 12 | # Tab name for entire site. (Default: "Site") 13 | navbar_site_name = Site 14 | 15 | # A list of tuples containting pages to link to. The value should be 16 | # in the form [(name, page), ..] 17 | navbar_links = 18 | 19 | # Render the next and previous page links in navbar. (Default: true) 20 | navbar_sidebarrel = true 21 | 22 | # Render the current pages TOC in the navbar. (Default: true) 23 | navbar_pagenav = true 24 | 25 | # Tab name for the current pages TOC. (Default: "Page") 26 | navbar_pagenav_name = Page 27 | 28 | # Global TOC depth for "site" navbar tab. (Default: 1) 29 | # Switching to -1 shows all levels. 30 | globaltoc_depth = 1 31 | 32 | # Include hidden TOCs in Site navbar? 33 | # 34 | # Note: If this is "false", you cannot have mixed ``:hidden:`` and 35 | # non-hidden ``toctree`` directives in the same page, or else the build 36 | # will break. 37 | # 38 | # Values: "true" (default) or "false" 39 | globaltoc_includehidden = true 40 | 41 | # HTML navbar class (Default: "navbar") to attach to
    element. 42 | # For black navbar, do "navbar navbar-inverse" 43 | navbar_class = navbar 44 | 45 | # Fix navigation bar to top of page? 46 | # Values: "true" (default) or "false" 47 | navbar_fixed_top = true 48 | 49 | # Location of link to source. 50 | # Options are "nav" (default), "footer" or anything else to exclude. 51 | source_link_position = nav 52 | 53 | # Bootswatch (http://bootswatch.com/) theme. 54 | # 55 | # Options are nothing (default) or the name of a valid theme such as 56 | # "amelia" or "cosmo". 57 | bootswatch_theme = 58 | 59 | # Switch Bootstrap version? 60 | # Values: "3" (default) or "2" 61 | bootstrap_version = 3 62 | -------------------------------------------------------------------------------- /_themes/bootstrap/navbar-2.html: -------------------------------------------------------------------------------- 1 | 52 | -------------------------------------------------------------------------------- /_themes/bootstrap/navbar.html: -------------------------------------------------------------------------------- 1 | 50 | -------------------------------------------------------------------------------- /latex_output_files/latex_preamble.tex: -------------------------------------------------------------------------------- 1 | \usepackage{helvet} 2 | \usepackage{tikz} 3 | \makechapterstyle{box}{ 4 | \renewcommand*{\printchaptername}{} 5 | \renewcommand*{\chapnumfont}{\normalfont\sffamily\huge\bfseries} 6 | \renewcommand*{\printchapternum}{ 7 | \flushright 8 | \begin{tikzpicture} 9 | \draw[fill,color=black] (0,0) rectangle (2cm,2cm); 10 | \draw[color=white] (1cm,1cm) node { \chapnumfont\thechapter }; 11 | \end{tikzpicture} 12 | } 13 | \renewcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries} 14 | \renewcommand*{\printchaptertitle}[1]{\flushright\chaptitlefont##1} 15 | } 16 | \chapterstyle{box} 17 | \makeatletter 18 | \DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm} 19 | \DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf} 20 | \DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt} 21 | \DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf} 22 | \DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit} 23 | \DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl} 24 | \DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc} 25 | \makeatother 26 | 27 | \pagestyle{ruled} 28 | \makepagestyle{ruled} 29 | \makeevenfoot{ruled}{}{}{\thepage} 30 | \makeoddfoot{ruled}{}{}{\thepage} 31 | \pagenumbering{arabic} 32 | 33 | % Defines the color of the verbatim background 34 | \definecolor{VerbatimColor}{rgb}{0.95,0.95,0.95} 35 | 36 | \makeatletter 37 | \renewcommand{\maketitle}{% 38 | \let\footnotesize\small 39 | \let\footnoterule\relax 40 | \rule{\textwidth}{1pt}% 41 | \ifsphinxpdfoutput 42 | \begingroup 43 | % These \defs are required to deal with multi-line authors; it 44 | % changes \\ to ', ' (comma-space), making it pass muster for 45 | % generating document info in the PDF file. 46 | \def\\{, } 47 | \def\and{and } 48 | \pdfinfo{ 49 | /Author (\@author) 50 | /Title (\@title) 51 | } 52 | \endgroup 53 | \fi 54 | \begin{flushright}% 55 | \sphinxlogo% 56 | {\rm\Huge\py@HeaderFamily \@title \par}% 57 | {\em\LARGE\py@HeaderFamily \py@release\releaseinfo \par} 58 | \vfill 59 | {\LARGE\py@HeaderFamily 60 | \begin{tabular}[t]{c} 61 | \@author 62 | \end{tabular} 63 | \par} 64 | \vfill\vfill 65 | {\large 66 | \@date \par 67 | \vfill 68 | \py@authoraddress \par 69 | }% 70 | \end{flushright}%\par 71 | \@thanks 72 | \newpage 73 | \let\thanks\relax\let\maketitle\relax 74 | %\gdef\@thanks{}\gdef\@author{}\gdef\@title{} 75 | } 76 | \makeatother 77 | -------------------------------------------------------------------------------- /_themes/bootstrap/search.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/search.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Template for the search page. 6 | 7 | :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | {%- extends "layout.html" %} 11 | {% set title = _('Search') %} 12 | {% set script_files = script_files + ['_static/searchtools.js'] %} 13 | {% block extrahead %} 14 | 17 | {# this is used when loading the search index using $.ajax fails, 18 | such as on Chrome for documents on localhost #} 19 | 20 | {{ super() }} 21 | {% endblock %} 22 | {% block body %} 23 |

    {{ _('Search') }}

    24 |
    25 | 26 |

    27 | {% trans %}Please activate JavaScript to enable the search 28 | functionality.{% endtrans %} 29 |

    30 |
    31 |

    32 | {% trans %}From here you can search these documents. Enter your search 33 | words into the box below and click "search". Note that the search 34 | function will automatically search for all of the words. Pages 35 | containing fewer words won't appear in the result list.{% endtrans %} 36 |

    37 | 38 | {% if theme_bootstrap_version == "3" %} 39 |
    40 |
    41 | 42 |
    43 | 44 | 45 |
    46 | {% else %} 47 | 52 | {% endif %} 53 | 54 | {% if search_performed %} 55 |

    {{ _('Search Results') }}

    56 | {% if not search_results %} 57 |

    {{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}

    58 | {% endif %} 59 | {% endif %} 60 |
    61 | {% if search_results %} 62 |
      63 | {% for href, caption, context in search_results %} 64 |
    • {{ caption }} 65 |
      {{ context|e }}
      66 |
    • 67 | {% endfor %} 68 |
    69 | {% endif %} 70 |
    71 | {% endblock %} 72 | -------------------------------------------------------------------------------- /guide/guide-random.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _random: 5 | 6 | ******************************************** 7 | Generating Random Quantum States & Operators 8 | ******************************************** 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | QuTiP includes a collection of random state generators for simulations, theorem evaluation, and code testing: 16 | 17 | .. tabularcolumns:: | p{2cm} | p{3cm} | 18 | 19 | .. cssclass:: table-striped 20 | 21 | +-------------------------------+---------------------------------+ 22 | | Function | Description | 23 | +===============================+=================================+ 24 | | `rand_ket` | Random ket-vector | 25 | +-------------------------------+---------------------------------+ 26 | | `rand_dm` | Random density matrix | 27 | +-------------------------------+---------------------------------+ 28 | | `rand_herm` | Random Hermitian matrix | 29 | +-------------------------------+---------------------------------+ 30 | | `rand_unitary` | Random Unitary matrix | 31 | +-------------------------------+---------------------------------+ 32 | 33 | See the API documentation: :ref:`functions-rand` for details. 34 | 35 | In all cases, these functions can be called with a single parameter :math:`N` that indicates a :math:`NxN` matrix (`rand_dm`, `rand_herm`, `rand_unitary`), or a :math:`Nx1` vector (`rand_ket`), should be generated. For example: 36 | 37 | .. ipython:: 38 | 39 | In [1]: rand_ket(5) 40 | 41 | or 42 | 43 | .. ipython:: 44 | 45 | In [1]: rand_herm(5) 46 | 47 | In this previous example, we see that the generated Hermitian operator contains a fraction of elements that are identically equal to zero. The number of nonzero elements is called the `density` and can be controlled by calling any of the random state/operator generators with a second argument between 0 and 1. By default, the density for the operators is `0.75` where as ket vectors are completely dense (`1`). For example: 48 | 49 | .. ipython:: 50 | 51 | In [1]: rand_dm(5, 0.5) 52 | 53 | 54 | has roughly half nonzero elements, or equivalently a density of 0.5. 55 | 56 | .. warning:: 57 | 58 | In the case of a density matrix, setting the density too low will result in not enough diagonal elements to satisfy :math:`Tr(\rho)=1`. 59 | 60 | Composite random objects 61 | ======================== 62 | 63 | In many cases, one is interested in generating random quantum objects that correspond to composite systems generated using the :func:`qutip.tensor.tensor` function. Specifying the tensor structure of a quantum object is done using the `dims` keyword argument in the same fashion as one would do for a :class:`qutip.Qobj` object: 64 | 65 | 66 | .. ipython:: 67 | 68 | In [1]: rand_dm(4, 0.5, dims=[[2,2], [2,2]]) 69 | 70 | 71 | -------------------------------------------------------------------------------- /contributors.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _developers: 5 | 6 | ************ 7 | Developers 8 | ************ 9 | 10 | 11 | .. _developers-lead: 12 | 13 | Lead Developers 14 | =============== 15 | 16 | `Robert Johansson `_ (RIKEN) 17 | 18 | `Paul Nation `_ (Korea University) 19 | 20 | 21 | .. _developers-contributors: 22 | 23 | Contributors 24 | ============ 25 | 26 | .. note:: 27 | 28 | Anyone is welcome to contribute to QuTiP. If you are interested in helping, please let us know! 29 | 30 | **alexbrc** (github user) - Code contributor 31 | 32 | **Alexander Pitchford** (Aberystwyth University) - Code contributor 33 | 34 | **Amit Jamadagni** - Bug fix 35 | 36 | **Anders Lund** (Technical University of Denmark) - Bug hunting for the Monte-Carlo solver 37 | 38 | **Andre Carvalho** - Bug hunter 39 | 40 | **André Xuereb** (University of Hannover) - Bug hunter 41 | 42 | **Anubhav Vardhan** (IIT, Kanpur) - Bug hunter, Code contributor, Documentation 43 | 44 | **Arne Grimsmo** (University of Auckland) - Bug hunter, Code contributor 45 | 46 | **Ben Criger** (Waterloo IQC) - Code contributor 47 | 48 | **Bredan Abolins** (Berkeley) - Bug hunter 49 | 50 | **Chris Granade** - Code contributor 51 | 52 | **Claudia Degrandi** (Yale University) - Documentation 53 | 54 | **Dawid Crivelli** - Bug hunter 55 | 56 | **Denis Vasilyev** (St. Petersburg State University) - Code contributor 57 | 58 | **Dong Zhou** (Yale University) - Bug hunter 59 | 60 | **Florian Ong** (Institute for Quantum Computation) - Bug hunter 61 | 62 | **Frank Schima** - Macports packaging 63 | 64 | **Henri Nielsen** (Technical University of Denmark) - Bug hunter 65 | 66 | **Hwajung Kang** (Systems Biology Institute, Tokyo) - Suggestions for improving Bloch class 67 | 68 | **James Clemens** (Miami University - Ohio) - Bug hunter 69 | 70 | **Johannes Feist** - Code contributor 71 | 72 | **Jonas Hörsch** - Code contributor 73 | 74 | **Jonas Neergaard-Nielsen** (Technical University of Denmark) - Code contributor, Windows support 75 | 76 | **JP Hadden** (University of Bristol) - Code contributor, improved Bloch sphere visualization 77 | 78 | **Kevin Fischer** (Stanford) - Code contributor 79 | 80 | **Laurence Stant** - Documentation 81 | 82 | **Markus Baden** (Centre for Quantum Technologies, Singapore) - Code contributor, Documentation 83 | 84 | **Myung-Joong Hwang** (Pohang University of Science and Technology) - Bug hunter 85 | 86 | **Neill Lambert** (RIKEN) - Code contributor, Windows support 87 | 88 | **Nikolas Tezak** (Stanford) - Code contributor 89 | 90 | **Per Nielsen** (Technical University of Denmark) - Bug hunter, Code contributor 91 | 92 | **Piotr Migdał** (ICFO) - Code contributor 93 | 94 | **Reinier Heeres** (Yale University) - Code contributor 95 | 96 | **Robert Jördens** (NIST) - Linux packaging 97 | 98 | **Simon Whalen** - Code contributor 99 | 100 | **W.M. Witzel** - Bug hunter 101 | 102 | -------------------------------------------------------------------------------- /apidoc/classes.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _classes: 5 | 6 | *************** 7 | Classes 8 | *************** 9 | 10 | .. _classes-qobj: 11 | 12 | Qobj 13 | -------------- 14 | 15 | .. autoclass:: qutip.Qobj 16 | :members: 17 | 18 | .. _classes-eseries: 19 | 20 | eseries 21 | ----------------- 22 | 23 | .. autoclass:: qutip.eseries 24 | :members: 25 | 26 | .. _classes-bloch: 27 | 28 | Bloch sphere 29 | --------------- 30 | 31 | .. autoclass:: qutip.bloch.Bloch 32 | :members: 33 | 34 | .. autoclass:: qutip.bloch3d.Bloch3d 35 | :members: 36 | 37 | .. _classes-odeoptions: 38 | 39 | 40 | Solver Options and Results 41 | --------------------------- 42 | 43 | .. autoclass:: qutip.solver.Options 44 | :members: 45 | 46 | .. autoclass:: qutip.solver.Result 47 | :members: 48 | 49 | .. autoclass:: qutip.stochastic.StochasticSolverOptions 50 | :members: 51 | 52 | Distribution functions 53 | ---------------------------- 54 | 55 | .. autoclass:: qutip.distributions.Distribution 56 | :members: 57 | 58 | .. autoclass:: qutip.distributions.WignerDistribution 59 | :members: 60 | 61 | .. autoclass:: qutip.distributions.QDistribution 62 | :members: 63 | 64 | .. autoclass:: qutip.distributions.TwoModeQuadratureCorrelation 65 | :members: 66 | 67 | .. autoclass:: qutip.distributions.HarmonicOscillatorWaveFunction 68 | :members: 69 | 70 | .. autoclass:: qutip.distributions.HarmonicOscillatorProbabilityFunction 71 | :members: 72 | 73 | 74 | Quantum information processing 75 | ------------------------------ 76 | 77 | .. autoclass:: qutip.qip.circuit.Gate 78 | :members: 79 | 80 | .. autoclass:: qutip.qip.circuit.QubitCircuit 81 | :members: 82 | 83 | .. autoclass:: qutip.qip.models.CircuitProcessor 84 | :members: 85 | 86 | .. autoclass:: qutip.qip.models.spinchain.SpinChain 87 | :members: 88 | 89 | .. autoclass:: qutip.qip.models.spinchain.LinearSpinChain 90 | :members: 91 | 92 | .. autoclass:: qutip.qip.models.spinchain.CircularSpinChain 93 | :members: 94 | 95 | .. autoclass:: qutip.qip.models.cqed.DispersivecQED 96 | :members: 97 | 98 | 99 | Optimal control 100 | --------------- 101 | 102 | .. autoclass:: qutip.control.grape.GRAPEResult 103 | :members: 104 | 105 | .. autoclass:: qutip.control.optimizer.GRAPEResult 106 | :members: 107 | 108 | .. autoclass:: qutip.control.dynamics.Dynamics 109 | :members: 110 | 111 | .. autoclass:: qutip.control.dynamics.DynamicsUnitary 112 | :members: 113 | 114 | .. autoclass:: qutip.control.dynamics.DynamicsSymplectic 115 | :members: 116 | 117 | .. autoclass:: qutip.control.pulsegen.PulseGen 118 | :members: 119 | 120 | .. autoclass:: qutip.control.pulsegen.PulseGenRandom 121 | :members: 122 | 123 | .. autoclass:: qutip.control.pulsegen.PulseGenZero 124 | :members: 125 | 126 | .. autoclass:: qutip.control.pulsegen.PulseGenLinear 127 | :members: 128 | 129 | .. autoclass:: qutip.control.pulsegen.PulseGenLinear 130 | :members: 131 | 132 | .. autoclass:: qutip.control.pulsegen.PulseGenPeriodic 133 | :members: 134 | 135 | .. autoclass:: qutip.control.pulsegen.PulseGenSine 136 | :members: 137 | 138 | .. autoclass:: qutip.control.pulsegen.PulseGenSquare 139 | :members: 140 | 141 | .. autoclass:: qutip.control.pulsegen.PulseGenSaw 142 | :members: 143 | 144 | .. autoclass:: qutip.control.pulsegen.PulseGenTriangle 145 | :members: 146 | -------------------------------------------------------------------------------- /guide/guide-settings.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _settings: 5 | 6 | ********************************* 7 | Modifying Internal QuTiP Settings 8 | ********************************* 9 | 10 | .. _settings-params: 11 | 12 | User Accessible Parameters 13 | ========================== 14 | 15 | In this section we show how to modify a few of the internal parameters used by QuTiP. The settings that can be modified are given in the following table: 16 | 17 | .. tabularcolumns:: | p{3cm} | p{5cm} | p{5cm} | 18 | 19 | .. cssclass:: table-striped 20 | 21 | +-------------------------------+-------------------------------------------+-----------------------------+ 22 | | Setting | Description | Options | 23 | +===============================+===========================================+=============================+ 24 | | `qutip_graphics` | Use matplotlib | True / False | 25 | +-------------------------------+-------------------------------------------+-----------------------------+ 26 | | `auto_herm` | Automatically calculate the hermicity of | True / False | 27 | | | quantum objects. | | 28 | +-------------------------------+-------------------------------------------+-----------------------------+ 29 | | `auto_tidyup` | Automatically tidyup quantum objects. | True / False | 30 | +-------------------------------+-------------------------------------------+-----------------------------+ 31 | | `auto_tidyup_atol` | Tolerance used by tidyup | any `float` value > 0 | 32 | +-------------------------------+-------------------------------------------+-----------------------------+ 33 | | `num_cpus` | Number of CPU's used for multiprocessing. | `int` between 1 and # cpu's | 34 | +-------------------------------+-------------------------------------------+-----------------------------+ 35 | | `debug` | Show debug printouts. | True / False | 36 | +-------------------------------+-------------------------------------------+-----------------------------+ 37 | 38 | .. _settings-usage: 39 | 40 | Example: Changing Settings 41 | ========================== 42 | 43 | The two most important settings are ``auto_tidyup`` and ``auto_tidyup_atol`` as they control whether the small elements of a quantum object should be removed, and what number should be considered as the cut-off tolerance. Modifying these, or any other parameters, is quite simple:: 44 | 45 | >>> qutip.settings.auto_tidyup = False 46 | 47 | These settings will be used for the current QuTiP session only and will need to be modified again when restarting QuTiP. If running QuTiP from a script file, then place the `qutip.setings.xxxx` commands immediately after `from qutip import *` at the top of the script file. If you want to reset the parameters back to their default values then call the reset command:: 48 | 49 | >>> qutip.settings.reset() 50 | 51 | Persistent Settings 52 | =================== 53 | 54 | When QuTiP is imported, it looks for the file ``.qutiprc`` in the user's home directory. If this file is found, it will be loaded and overwrite the QuTiP default settings, which allows for persistent changes in the QuTiP settings to be made. A sample ``.qutiprc`` file is show below. The syntax is a simple key-value format, where the keys and possible values are described in the table above:: 55 | 56 | # QuTiP Graphics 57 | qutip_graphics="YES" 58 | # use auto tidyup 59 | auto_tidyup=True 60 | # detect hermiticity 61 | auto_herm=True 62 | # use auto tidyup absolute tolerance 63 | auto_tidyup_atol=1e-12 64 | # number of cpus 65 | num_cpus=4 66 | # debug 67 | debug=False 68 | 69 | 70 | -------------------------------------------------------------------------------- /guide/guide-parfor.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _parfor: 5 | 6 | ****************************************** 7 | Running Problems in Parallel 8 | ****************************************** 9 | 10 | QuTiP's Built-in Parallel for-loop 11 | ---------------------------------- 12 | 13 | .. ipython:: 14 | :suppress: 15 | 16 | In [1]: from qutip import * 17 | 18 | Often one is interested in the output of a given function as a single-parameter is varied. For instance, we can calculate the steady-state response of our system as the driving frequency is varied. In cases such as this, where each iteration is independent of the others, we can speedup the calculation by performing the iterations in parallel. In QuTiP, parallel computations may be performed using the :func:`qutip.parfor` (parallel-for-loop) function. 19 | 20 | To use the parfor function we need to define a function of one or more variables, and the range over which these variable are to be iterated. For example: 21 | 22 | 23 | .. ipython:: 24 | 25 | In [1]: def func1(x): return x, x**2, x**3 26 | 27 | In [2]: [a,b,c] = parfor(func1, range(10)) 28 | 29 | In [3]: print(a) 30 | 31 | In [4]: print(b) 32 | 33 | In [5]: print(c) 34 | 35 | One can also use a single output variable as: 36 | 37 | .. ipython:: 38 | 39 | In [1]: x = parfor(func1, range(10)) 40 | 41 | In [2]: print(x[0]) 42 | 43 | In [3]: print(x[1]) 44 | 45 | In [4]: print(x[2]) 46 | 47 | The :func:`qutip.parfor` function is not limited to just numbers, but also works for a variety of outputs: 48 | 49 | .. ipython:: 50 | 51 | In [1]: def func2(x): return x, Qobj(x), 'a' * x 52 | 53 | In [2]: [a, b, c] = parfor(func2, range(5)) 54 | 55 | In [3]: print(a) 56 | 57 | In [4]: print(b) 58 | 59 | In [5]: print(c) 60 | 61 | 62 | .. note:: 63 | 64 | New in QuTiP 3. 65 | 66 | One can also define functions with **multiple** input arguments and even keyword arguments: 67 | 68 | .. ipython:: 69 | 70 | In [1]: def sum_diff(x , y, z=0): return x + y, x - y, z 71 | 72 | In [2]: parfor(sum_diff, [1, 2, 3], [4, 5, 6], z=5.0) 73 | 74 | Note that the keyword arguments can be anything you like, but the keyword values are **not** iterated over. The keyword argument *num_cpus* is reserved as it sets the number of CPU's used by parfor. By default, this value is set to the total number of physical processors on your system. You can change this number to a lower value, however setting it higher than the number of CPU's will cause a drop in performance. 75 | 76 | Parfor is also useful for repeated tasks such as generating plots corresponding to the dynamical evolution of your system, or simultaneously simulating different parameter configurations. 77 | 78 | 79 | IPython-Based parfor 80 | -------------------- 81 | 82 | .. note:: 83 | 84 | New in QuTiP 3. 85 | 86 | When QuTiP is used with IPython interpreter, there is an alternative parallel for-loop implementation in the QuTiP module :func:`qutip.ipynbtools`, see :func:`qutip.ipynbtools.parfor`. The advantage of this parfor implementation is based on IPythons powerful framework for parallelization, so the compute processes are not confined to run on the same host as the main process. 87 | 88 | Parallel picloud Computations 89 | ----------------------------- 90 | 91 | .. note:: 92 | 93 | New in QuTiP 3. 94 | 95 | New to QuTiP version 3 is the option to run computations in parallel on the cloud computing platform provided by PiCloud. You must have their software installed on your machine, and an active account, for this function to work. Note that, at present, the picloud software is **only available for Python version 2.7**. Using the picloud function is very similar to using parfor, however the picloud function does not accept any keyword arguments: 96 | 97 | 98 | >>> from qutip.picloud import * 99 | >>> def add(x, y): return x + y 100 | >>> picloud(add, [10, 20, 30], [5, 6, 7]) 101 | [15, 26, 37] 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /QuTiP_tree_plot/qutip-structure.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import json 5 | import re 6 | 7 | exclude_dirs = ["examples", "tests"] 8 | 9 | # a list of exclude patterns for decrapated or poorly named 10 | # internal functions 11 | exclude_patterns = [r'.*_td', r'.*_es', r'.*_mc', r'.*_ode', r'_.*'] 12 | 13 | qutip_root = "../../qutip/qutip" 14 | 15 | colors = ["#0B5FA5", "#043C6B", "#3F8FD2", # blue colors 16 | "#00AE68", "#007143", "#36D695", # green colors 17 | "#FF4500", "#692102", "#BF5730" 18 | ] 19 | 20 | # "#FF9400", "#A66000", "#FFAE40" 21 | # "#FF6F00", "#A64800", "#BF6E30" 22 | 23 | module_cmap = {"mesolve": 0, # time evolution 24 | "mcsolve": 0, 25 | "sesolve": 0, 26 | "solver": 0, 27 | "stochastic": 0, 28 | "floquet": 0, 29 | "essolve": 0, 30 | "correlation": 0, 31 | "bloch_redfield": 0, 32 | "steadystate": 0, 33 | "rhs_generate": 0, 34 | "propagator": 0, 35 | "eseries": 0, 36 | "odeconfig": 1, # options and settings 37 | "settings": 1, 38 | "odechecks": 1, 39 | "odedata": 1, 40 | "odeoptions": 1, 41 | "bloch": 2, # visualization 42 | "bloch3d": 2, 43 | "sphereplot": 2, 44 | "orbital": 2, 45 | "visualization": 2, 46 | "wigner": 2, 47 | "distributions": 2, 48 | "tomography": 2, 49 | "operators": 3, # operators 50 | "superoperator": 3, 51 | "superop_reps": 3, 52 | "subsystem_apply": 3, 53 | "states": 4, # states 54 | "continuous_variables": 4, 55 | "qstate": 4, 56 | "random_objects": 4, 57 | "three_level_atom": 4, 58 | "gates": 5, # gates 59 | "entropy": 6, # measures 60 | "metrics": 6, 61 | "fileio": 8, # utilities 62 | "utilities": 8, 63 | "ipynbtools": 8, 64 | "sparse": 8, 65 | "graph": 8, 66 | "simdiag": 8, 67 | "permute": 8, 68 | "demos": 8, 69 | "about": 8, 70 | "version": 8, 71 | "testing": 8, 72 | "parfor": 8, 73 | "hardware_info": 8, 74 | "picloud": 8, 75 | "qobj": 7, # core 76 | "expect": 7, 77 | "tensor": 7, 78 | "partial_transpose": 7, 79 | "ptrace": 7, 80 | "istests": 7 81 | } 82 | 83 | 84 | module_list = [] 85 | 86 | for root, dirs, files in os.walk(qutip_root): 87 | 88 | if not ".svn" in root and root == "../../qutip/qutip": 89 | 90 | for f in files: 91 | if f[-3:] == ".py" and f[0] != "_" and f != "setup.py": 92 | 93 | module = f[:-3] 94 | 95 | idx = module_cmap[module] if module in module_cmap else -1 96 | color = colors[idx] if idx >= 0 else "black" 97 | 98 | symbol_list = [] 99 | 100 | cmd = "egrep '^(def|class) ' %s/%s | cut -f 2 -d ' ' | cut -f 1 -d '('" % (qutip_root, f) 101 | for name in os.popen(cmd).readlines(): 102 | if not any([re.match(pattern, name) for pattern in exclude_patterns]): 103 | symbol_list.append({"name": name.strip(), "size": 1000, "color": color}) 104 | 105 | module_list.append({"name": module, "children": symbol_list, "color": color, "idx": idx}) 106 | 107 | 108 | module_list_sorted = sorted(module_list, key=lambda x: x["idx"]) 109 | qutip_struct = {"name": "QuTiP", "children": module_list_sorted, "size": 2000} 110 | 111 | with open('d3_data/qutip.json', 'w') as outfile: 112 | json.dump(qutip_struct, outfile, sort_keys=True, indent=4) 113 | 114 | -------------------------------------------------------------------------------- /_themes/bootstrap/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "basic/layout.html" %} 2 | 3 | {% set theme_css_files = [] %} 4 | {% if theme_bootstrap_version == "3" %} 5 | {% set bootstrap_version, bootstrap_additional_css, navbar_version = "3.2.0", "theme", "" %} 6 | {% set bs_span_prefix = "col-md-" %} 7 | {% else %} 8 | {% set bootstrap_version, bootstrap_additional_css, navbar_version = "2.3.2", "responsive", "-2" %} 9 | {% set bs_span_prefix = "span" %} 10 | {% endif %} 11 | 12 | {% if theme_bootswatch_theme and theme_bootswatch_theme != "\"\"" %} 13 | {# BS2 needs "bootstrap-responsive.css". BS3 doesn't. #} 14 | {% if theme_bootstrap_version == "3" %} 15 | {% set theme_css_files = theme_css_files + [ 16 | '_static/bootswatch-' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css', 17 | '_static/bootstrap-sphinx.css' 18 | ] 19 | %} 20 | {% else %} 21 | {% set theme_css_files = theme_css_files + [ 22 | '_static/bootswatch-' + bootstrap_version + '/' + theme_bootswatch_theme + '/bootstrap.min.css', 23 | '_static/bootstrap-' + bootstrap_version + '/css/bootstrap-' + bootstrap_additional_css + '.min.css', 24 | '_static/bootstrap-sphinx.css' 25 | ] 26 | %} 27 | {% endif %} 28 | {% else %} 29 | {% set theme_css_files = theme_css_files + [ 30 | '_static/bootstrap-' + bootstrap_version + '/css/bootstrap.min.css', 31 | '_static/bootstrap-' + bootstrap_version + '/css/bootstrap-' + bootstrap_additional_css + '.min.css', 32 | '_static/bootstrap-sphinx.css' 33 | ] 34 | %} 35 | {% endif %} 36 | 37 | {% if not bootswatch_css_custom %} 38 | {% set bootswatch_css_custom = [] %} 39 | {% endif %} 40 | {% set css_files = css_files + theme_css_files + bootswatch_css_custom %} 41 | 42 | {% set script_files = script_files + [ 43 | '_static/js/jquery-1.11.0.min.js', 44 | '_static/js/jquery-fix.js', 45 | '_static/bootstrap-' + bootstrap_version + '/js/bootstrap.min.js', 46 | '_static/bootstrap-sphinx.js' 47 | ] 48 | %} 49 | 50 | {%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and sidebars %} 51 | 52 | {%- set bs_content_width = render_sidebar and "9" or "12"%} 53 | 54 | {%- block doctype -%} 55 | 56 | {%- endblock %} 57 | 58 | {# Sidebar: Rework into our Bootstrap nav section. #} 59 | {% macro navBar() %} 60 | {% include "navbar" + navbar_version + ".html" %} 61 | {% endmacro %} 62 | 63 | {% if theme_bootstrap_version == "3" %} 64 | {%- macro bsidebar() %} 65 | {%- if render_sidebar %} 66 |
    67 | 72 |
    73 | {%- endif %} 74 | {%- endmacro %} 75 | {% else %} 76 | {%- macro bsidebar() %} 77 | {%- if render_sidebar %} 78 |
    79 | 84 |
    85 | {%- endif %} 86 | {%- endmacro %} 87 | {% endif %} 88 | 89 | {%- block extrahead %} 90 | 91 | 92 | 93 | 94 | {% endblock %} 95 | 96 | {# Silence the sidebar's, relbar's #} 97 | {% block header %}{% endblock %} 98 | {% block relbar1 %}{% endblock %} 99 | {% block relbar2 %}{% endblock %} 100 | {% block sidebarsourcelink %}{% endblock %} 101 | 102 | {%- block content %} 103 | {{ navBar() }} 104 |
    105 |
    106 | {%- block sidebar1 %}{{ bsidebar() }}{% endblock %} 107 |
    108 | {% block body %}{% endblock %} 109 |
    110 | {% block sidebar2 %} {# possible location for sidebar #} {% endblock %} 111 |
    112 |
    113 | {%- endblock %} 114 | 115 | {%- block footer %} 116 |
    117 |
    118 |

    119 | Back to top 120 | {% if theme_source_link_position == "footer" %} 121 |
    122 | {% include "sourcelink.html" %} 123 | {% endif %} 124 |

    125 |

    126 | {%- if show_copyright %} 127 | {%- if hasdoc('copyright') %} 128 | {% trans path=pathto('copyright'), copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %}
    129 | {%- else %} 130 | {% trans copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %}
    131 | {%- endif %} 132 | {%- endif %} 133 | {%- if last_updated %} 134 | {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %}
    135 | {%- endif %} 136 | {%- if show_sphinx %} 137 | {% trans sphinx_version=sphinx_version|e %}Created using Sphinx {{ sphinx_version }}.{% endtrans %}
    138 | {%- endif %} 139 |

    140 |
    141 |
    142 | {%- endblock %} 143 | -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootstrap-sphinx.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * bootstrap-sphinx.css 3 | * ~~~~~~~~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- Bootstrap theme. 6 | */ 7 | 8 | .navbar-inverse .brand { 9 | color: #FFF; 10 | } 11 | 12 | /* 13 | * Reset navbar styles from overrides in: 14 | * https://bitbucket.org/birkenfeld/sphinx/commits/78d8ebf76b630ab4073a7328af9d91e8123b8d96 15 | */ 16 | .navbar .container { 17 | padding-top: 0; 18 | } 19 | 20 | .page-top { 21 | top: 0px; 22 | } 23 | 24 | {% if theme_navbar_fixed_top|tobool %} 25 | 26 | {% if theme_bootstrap_version == "2" %} 27 | @media (min-width: 980px) { 28 | {% endif %} 29 | 30 | body { 31 | {% if theme_bootswatch_theme and theme_bootswatch_theme != "\"\"" %} 32 | padding-top: 60px; 33 | {% else %} 34 | padding-top: 40px; 35 | {% endif %} 36 | } 37 | .page-top { 38 | {% if theme_bootswatch_theme and theme_bootswatch_theme != "\"\"" %} 39 | top: 60px; 40 | {% else %} 41 | top: 40px; 42 | {% endif %} 43 | } 44 | 45 | {% if theme_bootstrap_version == "2" %} 46 | } 47 | {% endif %} 48 | 49 | .navbar-inner { 50 | padding-left: 12px !important; 51 | padding-right: 12px !important; 52 | } 53 | {% else %} 54 | {% if theme_bootstrap_version == "2" %} 55 | @media (min-width: 980px) { 56 | .navbar .container { 57 | width: 940px; 58 | } 59 | } 60 | {% endif %} 61 | {% endif %} 62 | 63 | table { 64 | border: 0; 65 | } 66 | 67 | .highlighttable .code pre { 68 | font-size: 12px; 69 | } 70 | 71 | .highlighttable .linenos pre { 72 | word-break: normal; 73 | font-size: 12px; 74 | } 75 | 76 | div.highlight { 77 | background: none; 78 | } 79 | 80 | a.footnote-reference { 81 | vertical-align: super; 82 | font-size: 75%; 83 | } 84 | 85 | table.footnote td.label { 86 | font-size: 100%; 87 | display: block; 88 | line-height: normal; 89 | background: inherit; 90 | } 91 | 92 | table.footnote { 93 | width: auto; 94 | margin-bottom: 0px; 95 | } 96 | 97 | table.field-list { 98 | width: auto; 99 | } 100 | 101 | .footer { 102 | width: 100%; 103 | border-top: 1px solid #ccc; 104 | padding-top: 10px; 105 | } 106 | 107 | .bs-sidenav form, .bs-sidenav #sourcelink { 108 | padding: 5px 20px; 109 | } 110 | 111 | {% if theme_bootstrap_version == "3" %} 112 | 113 | /* The code below is based on the bootstrap website sidebar */ 114 | 115 | .bs-sidenav.affix { 116 | position: static; 117 | } 118 | 119 | /* First level of nav */ 120 | .bs-sidenav { 121 | margin-top: 30px; 122 | margin-bottom: 30px; 123 | padding-top: 10px; 124 | padding-bottom: 10px; 125 | text-shadow: 0 1px 0 #fff; 126 | background-color: #f7f5fa; 127 | border-radius: 5px; 128 | } 129 | 130 | /* All levels of nav */ 131 | .bs-sidenav .nav > li > a { 132 | display: block; 133 | color: #716b7a; 134 | padding: 5px 20px; 135 | } 136 | .bs-sidenav .nav > li > a:hover, 137 | .bs-sidenav .nav > li > a:focus { 138 | text-decoration: none; 139 | background-color: #e5e3e9; 140 | border-right: 1px solid #dbd8e0; 141 | } 142 | .bs-sidenav .nav > .active > a, 143 | .bs-sidenav .nav > .active:hover > a, 144 | .bs-sidenav .nav > .active:focus > a { 145 | font-weight: bold; 146 | color: #563d7c; 147 | background-color: transparent; 148 | border-right: 1px solid #563d7c; 149 | } 150 | 151 | .bs-sidenav .nav .nav > li > a { 152 | padding-top: 3px; 153 | padding-bottom: 3px; 154 | padding-left: 30px; 155 | font-size: 90%; 156 | } 157 | 158 | .bs-sidenav .nav .nav .nav > li > a { 159 | padding-top: 3px; 160 | padding-bottom: 3px; 161 | padding-left: 40px; 162 | font-size: 90%; 163 | } 164 | 165 | .bs-sidenav .nav .nav .nav .nav > li > a { 166 | padding-top: 3px; 167 | padding-bottom: 3px; 168 | padding-left: 50px; 169 | font-size: 90%; 170 | } 171 | 172 | /* Show and affix the side nav when space allows it */ 173 | @media screen and (min-width: 992px) { 174 | .bs-sidenav .nav > .active > ul { 175 | display: block; 176 | } 177 | /* Widen the fixed sidenav */ 178 | .bs-sidenav.affix, 179 | .bs-sidenav.affix-bottom { 180 | width: 213px; 181 | } 182 | .bs-sidenav.affix { 183 | position: fixed; /* Undo the static from mobile first approach */ 184 | top: 80px; 185 | } 186 | .bs-sidenav.affix-bottom { 187 | position: absolute; /* Undo the static from mobile first approach */ 188 | } 189 | .bs-sidenav.affix-bottom .bs-sidenav, 190 | .bs-sidenav.affix .bs-sidenav { 191 | margin-top: 0; 192 | margin-bottom: 0; 193 | } 194 | } 195 | @media screen and (min-width: 1200px) { 196 | /* Widen the fixed sidenav again */ 197 | .bs-sidenav.affix-bottom, 198 | .bs-sidenav.affix { 199 | width: 263px; 200 | } 201 | } 202 | 203 | 204 | {% else %} 205 | 206 | .bs-sidenav { 207 | width: 228px; 208 | margin: 30px 0 0; 209 | padding: 10px 0 0 5px; 210 | } 211 | 212 | .bs-sidenav ul{ 213 | list-style-type: none; 214 | padding-left: 25px; 215 | margin-left: 0; /* bootstrap 2 compatability. */ 216 | } 217 | 218 | @media (min-width: 1200px) { 219 | .bs-sidenav { 220 | width: 258px; 221 | } 222 | } 223 | 224 | /* Desktop 225 | ------------------------- */ 226 | @media (max-width: 980px) { 227 | .bs-sidenav { 228 | width: 218px; 229 | margin-top: 30px; 230 | margin-right: 0; 231 | } 232 | } 233 | 234 | /* Tablet to desktop 235 | ------------------------- */ 236 | @media (min-width: 768px) and (max-width: 979px) { 237 | .bs-sidenav { 238 | width: 166px; 239 | margin-top: 20px; 240 | } 241 | } 242 | 243 | /* Tablet 244 | ------------------------- */ 245 | @media (max-width: 767px) { 246 | .navbar-version { 247 | padding-left: 5px; 248 | } 249 | .bs-sidenav { 250 | width: auto; 251 | margin-bottom: 20px; 252 | } 253 | .bs-sidenav.affix { 254 | position: static; 255 | top: 0; 256 | } 257 | } 258 | {% endif %} 259 | -------------------------------------------------------------------------------- /guide/dynamics/dynamics-options.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _options: 5 | 6 | ********************************************* 7 | Setting Options for the Dynamics Solvers 8 | ********************************************* 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | In [1]: import numpy as np 16 | 17 | Occasionally it is necessary to change the built in parameters of the dynamics solvers used by for example the :func:`qutip.mesolve` and :func:`qutip.mcsolve` functions. The options for all dynamics solvers may be changed by using the Options class :class:`qutip.solver.Options`. 18 | 19 | .. ipython:: 20 | 21 | In [1]: options = Options() 22 | 23 | the properties and default values of this class can be view via the `print` function: 24 | 25 | .. ipython:: 26 | 27 | In [1]: print(options) 28 | 29 | These properties are detailed in the following table. Assuming ``options = Options()``: 30 | 31 | .. cssclass:: table-striped 32 | 33 | +---------------------+-----------------+----------------------------------------------------------------+ 34 | | Property | Default setting | Description | 35 | +=====================+=================+================================================================+ 36 | | options.atol | 1e-8 | Absolute tolerance | 37 | +---------------------+-----------------+----------------------------------------------------------------+ 38 | | options.rtol | 1e-6 | Relative tolerance | 39 | +---------------------+-----------------+----------------------------------------------------------------+ 40 | | options.method | 'adams' | Solver method. Can be 'adams' (non-stiff) or 'bdf' (stiff) | 41 | +---------------------+-----------------+----------------------------------------------------------------+ 42 | | options.order | 12 | Order of solver. Must be <=12 for 'adams' and <=5 for 'bdf' | 43 | +---------------------+-----------------+----------------------------------------------------------------+ 44 | | options.nsteps | 1000 | Max. number of steps to take for each interval | 45 | +---------------------+-----------------+----------------------------------------------------------------+ 46 | | options.first_step | 0 | Size of initial step. 0 = determined automatically by solver. | 47 | +---------------------+-----------------+----------------------------------------------------------------+ 48 | | options.min_step | 0 | Minimum step size. 0 = determined automatically by solver. | 49 | +---------------------+-----------------+----------------------------------------------------------------+ 50 | | options.max_step | 0 | Maximum step size. 0 = determined automatically by solver. | 51 | +---------------------+-----------------+----------------------------------------------------------------+ 52 | | options.tidy | True | Whether to run tidyup function on time-independent Hamiltonian.| 53 | +---------------------+-----------------+----------------------------------------------------------------+ 54 | | options.num_cpus | installed num | Integer number of cpu's used by mcsolve. | 55 | | | of processors | | 56 | +---------------------+-----------------+----------------------------------------------------------------+ 57 | | options.rhs_filename| None | RHS filename when using compiled time-dependent Hamiltonians. | 58 | +---------------------+-----------------+----------------------------------------------------------------+ 59 | | options.rhs_reuse | False | Reuse compiled RHS function. Useful for repeatative tasks. | 60 | +---------------------+-----------------+----------------------------------------------------------------+ 61 | | options.gui | True (if GUI) | Use the mcsolve progessbar. Defaults to False on Windows. | 62 | +---------------------+-----------------+----------------------------------------------------------------+ 63 | | options.mc_avg | True | Average over trajectories for expectation values from mcsolve. | 64 | +---------------------+-----------------+----------------------------------------------------------------+ 65 | 66 | 67 | As an example, let us consider changing the number of processors used, turn the GUI off, and strengthen the absolute tolerance. There are two equivalent ways to do this using the Options class. First way, 68 | 69 | .. ipython:: 70 | 71 | In[1]: options = Options() 72 | 73 | In[1]: options.num_cpus = 3 74 | 75 | In[1]: options.gui = False 76 | 77 | In[1]: options.atol = 1e-10 78 | 79 | or one can use an inline method, 80 | 81 | .. ipython:: 82 | 83 | In[1]: options = Options(num_cpus=4, gui=False, atol=1e-10) 84 | 85 | Note that the order in which you input the options does not matter. Using either method, the resulting `options` variable is now: 86 | 87 | .. ipython:: 88 | 89 | In [1]: print(options) 90 | 91 | To use these new settings we can use the keyword argument ``options`` in either the func:`qutip.mesolve` and :func:`qutip.mcsolve` function. We can modify the last example as:: 92 | 93 | >>> mesolve(H0, psi0, tlist, c_op_list, [sigmaz()], options=options) 94 | >>> mesolve(hamiltonian_t, psi0, tlist, c_op_list, [sigmaz()], H_args, options=options) 95 | 96 | or:: 97 | 98 | >>> mcsolve(H0, psi0, tlist, ntraj,c_op_list, [sigmaz()], options=options) 99 | >>> mcsolve(hamiltonian_t, psi0, tlist, ntraj, c_op_list, [sigmaz()], H_args, options=options) 100 | 101 | 102 | -------------------------------------------------------------------------------- /_themes/bootstrap/static/bootstrap-sphinx.js_t: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | /** 3 | * Patch TOC list. 4 | * 5 | * Will mutate the underlying span to have a correct ul for nav. 6 | * 7 | * @param $span: Span containing nested UL's to mutate. 8 | * @param minLevel: Starting level for nested lists. (1: global, 2: local). 9 | */ 10 | var patchToc = function ($ul, minLevel) { 11 | var findA, 12 | patchTables, 13 | $localLi; 14 | 15 | // Find all a "internal" tags, traversing recursively. 16 | findA = function ($elem, level) { 17 | level = level || 0; 18 | var $items = $elem.find("> li > a.internal, > ul, > li > ul"); 19 | 20 | // Iterate everything in order. 21 | $items.each(function (index, item) { 22 | var $item = $(item), 23 | tag = item.tagName.toLowerCase(), 24 | $childrenLi = $item.children('li'), 25 | $parentLi = $($item.parent('li'), $item.parent().parent('li')); 26 | 27 | // Add dropdowns if more children and above minimum level. 28 | if (tag === 'ul' && level >= minLevel && $childrenLi.length > 0) { 29 | $parentLi 30 | .addClass('dropdown-submenu') 31 | .children('a').first().attr('tabindex', -1); 32 | 33 | $item.addClass('dropdown-menu'); 34 | } 35 | 36 | findA($item, level + 1); 37 | }); 38 | }; 39 | 40 | findA($ul); 41 | }; 42 | 43 | /** 44 | * Patch all tables to remove ``docutils`` class and add Bootstrap base 45 | * ``table`` class. 46 | */ 47 | patchTables = function () { 48 | $("table.docutils") 49 | .removeClass("docutils") 50 | .addClass("table") 51 | .attr("border", 0); 52 | }; 53 | 54 | $(window).load(function () { 55 | /* 56 | * Scroll the window to avoid the topnav bar 57 | * https://github.com/twbs/bootstrap/issues/1768 58 | */ 59 | if ($("#navbar.navbar-fixed-top").length > 0) { 60 | var navHeight = $("#navbar").height(), 61 | shiftWindow = function() { scrollBy(0, -navHeight - 10); }; 62 | 63 | if (location.hash) { 64 | setTimeout(shiftWindow, 1); 65 | } 66 | 67 | window.addEventListener("hashchange", shiftWindow); 68 | } 69 | }); 70 | 71 | $(document).ready(function () { 72 | // Add styling, structure to TOC's. 73 | $(".dropdown-menu").each(function () { 74 | $(this).find("ul").each(function (index, item){ 75 | var $item = $(item); 76 | $item.addClass('unstyled'); 77 | }); 78 | }); 79 | 80 | // Global TOC. 81 | if ($("ul.globaltoc li").length) { 82 | patchToc($("ul.globaltoc"), 1); 83 | } else { 84 | // Remove Global TOC. 85 | $(".globaltoc-container").remove(); 86 | } 87 | 88 | // Local TOC. 89 | $(".bs-sidenav ul").addClass("nav nav-list"); 90 | $(".bs-sidenav > ul > li > a").addClass("nav-header"); 91 | 92 | {% if theme_navbar_fixed_top|tobool and theme_bootstrap_version == "3" %} 93 | // back to top 94 | setTimeout(function () { 95 | var $sideBar = $('.bs-sidenav'); 96 | 97 | $sideBar.affix({ 98 | offset: { 99 | top: function () { 100 | var offsetTop = $sideBar.offset().top; 101 | var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10); 102 | var navOuterHeight = $('#navbar').height(); 103 | 104 | return (this.top = offsetTop - navOuterHeight - sideBarMargin); 105 | } 106 | , bottom: function () { 107 | // add 25 because the footer height doesn't seem to be enough 108 | return (this.bottom = $('.footer').outerHeight(true) + 25); 109 | } 110 | } 111 | }); 112 | }, 100); 113 | {% endif %} 114 | 115 | // Local TOC. 116 | patchToc($("ul.localtoc"), 2); 117 | 118 | // Mutate sub-lists (for bs-2.3.0). 119 | $(".dropdown-menu ul").not(".dropdown-menu").each(function () { 120 | var $ul = $(this), 121 | $parent = $ul.parent(), 122 | tag = $parent[0].tagName.toLowerCase(), 123 | $kids = $ul.children().detach(); 124 | 125 | // Replace list with items if submenu header. 126 | if (tag === "ul") { 127 | $ul.replaceWith($kids); 128 | } else if (tag === "li") { 129 | // Insert into previous list. 130 | $parent.after($kids); 131 | $ul.remove(); 132 | } 133 | }); 134 | 135 | // Add divider in page TOC. 136 | $localLi = $("ul.localtoc li"); 137 | if ($localLi.length > 2) { 138 | $localLi.first().after('
  • '); 139 | } 140 | 141 | // Manually add dropdown. 142 | // Appears unnecessary as of: 143 | // https://github.com/ryan-roemer/sphinx-bootstrap-theme/pull/90 144 | // Remove next time around... 145 | // a.dropdown-toggle class needed in globaltoc.html 146 | //$('.dropdown-toggle').dropdown(); 147 | 148 | // Patch tables. 149 | patchTables(); 150 | 151 | // Add Note, Warning styles. (BS v2,3 compatible). 152 | $('.admonition').addClass('alert alert-info') 153 | .filter('.warning, .caution') 154 | .removeClass('alert-info') 155 | .addClass('alert-warning').end() 156 | .filter('.error, .danger') 157 | .removeClass('alert-info') 158 | .addClass('alert-danger alert-error').end(); 159 | 160 | // Inline code styles to Bootstrap style. 161 | $('tt.docutils.literal').not(".xref").each(function (i, e) { 162 | // ignore references 163 | if (!$(e).parent().hasClass("reference")) { 164 | $(e).replaceWith(function () { 165 | return $("").html($(this).html()); 166 | }); 167 | }}); 168 | 169 | // Update sourcelink to remove outerdiv (fixes appearance in navbar). 170 | var $srcLink = $(".nav #sourcelink"); 171 | $srcLink.parent().html($srcLink.html()); 172 | }); 173 | }(window.$jqTheme || window.jQuery)); 174 | -------------------------------------------------------------------------------- /frontmatter.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011 and later, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _frontmatter: 5 | 6 | ************* 7 | Frontmatter 8 | ************* 9 | 10 | .. _about-docs: 11 | 12 | About This Documentation 13 | ========================== 14 | 15 | This document contains a user guide and automatically generated API documentation for QuTiP. A PDF version of this text is available at the `documentation page `_. 16 | 17 | **For more information see the** `QuTiP project web page`_. 18 | 19 | .. _QuTiP project web page: http://www.qutip.org 20 | 21 | 22 | :Author: P.D. Nation 23 | :Address: Department of Physics, Korea University, 24 | Seongbuk-gu Seoul, 136-713 South Korea 25 | 26 | :Author: J.R. Johansson 27 | :Address: iTHES Research Group, RIKEN, 28 | Wako-shi Saitama, 351-0198 Japan 29 | 30 | :version: 3.1.0 31 | :status: Released 32 | :copyright: This documentation is licensed under the Creative Commons Attribution 3.0 Unported License. 33 | 34 | .. _citing-qutip: 35 | 36 | Citing This Project 37 | ========================== 38 | 39 | If you find this project useful, then please cite: 40 | 41 | .. centered:: J. R. Johansson, P.D. Nation, and F. Nori, "QuTiP 2: A Python framework for the dynamics of open quantum systems", Comp. Phys. Comm. **184**, 1234 (2013). 42 | 43 | or 44 | 45 | .. centered:: J. R. Johansson, P.D. Nation, and F. Nori, "QuTiP: An open-source Python framework for the dynamics of open quantum systems", Comp. Phys. Comm. **183**, 1760 (2012). 46 | 47 | 48 | which may also be download from http://arxiv.org/abs/1211.6518 or http://arxiv.org/abs/1110.0573, respectively. 49 | 50 | .. _funding-qutip: 51 | 52 | Funding 53 | ======= 54 | 55 | The development of QuTiP has been partially supported by the Japanese Society for the Promotion of Science Foreign Postdoctoral Fellowship Program under grants P11202 (PDN) and P11501 (JRJ). Additional funding comes from RIKEN, Kakenhi grant Nos. 2301202 (PDN), 2302501 (JRJ), and Korea University. 56 | 57 | .. _image-jsps: 58 | 59 | .. figure:: figures/jsps.jpg 60 | :width: 4in 61 | :figclass: align-center 62 | 63 | .. _image-riken: 64 | 65 | .. figure:: figures/riken-logo.png 66 | :width: 1.5in 67 | :figclass: align-center 68 | 69 | | 70 | 71 | .. _image-korea: 72 | 73 | .. figure:: figures/korea-logo.png 74 | :width: 3in 75 | :figclass: align-center 76 | 77 | 78 | .. _about: 79 | 80 | About QuTiP 81 | =========== 82 | 83 | Every quantum system encountered in the real world is an open quantum system. For although much care is taken experimentally to eliminate the unwanted influence of external interactions, there remains, if ever so slight, a coupling between the system of interest and the external world. In addition, any measurement performed on the system necessarily involves coupling to the measuring device, therefore introducing an additional source of external influence. Consequently, developing the necessary tools, both theoretical and numerical, to account for the interactions between a system and its environment is an essential step in understanding the dynamics of quantum systems. 84 | 85 | In general, for all but the most basic of Hamiltonians, an analytical description of the system dynamics is not possible, and one must resort to numerical simulations of the equations of motion. In absence of a quantum computer, these simulations must be carried out using classical computing techniques, where the exponentially increasing dimensionality of the underlying Hilbert space severely limits the size of system that can be efficiently simulated. However, in many fields such as quantum optics, trapped ions, superconducting circuit devices, and most recently nanomechanical systems, it is possible to design systems using a small number of effective oscillator and spin components, excited by a limited number of quanta, that are amenable to classical simulation in a truncated Hilbert space. 86 | 87 | The Quantum Toolbox in Python, or QuTiP, is a fully open-source implementation of a framework written in the Python programming language designed for simulating the open quantum dynamics for systems such as those listed above. This framework distinguishes itself from the other available software solutions by providing the following advantages: 88 | 89 | * QuTiP relies entirely on open-source software. You are free to modify and use it as you wish with no licensing fees or limitations. 90 | 91 | * QuTiP is based on the Python scripting language, providing easy to read, fast code generation without the need to compile after modification. 92 | 93 | * The numerics underlying QuTiP are time-tested algorithms that run at C-code speeds, thanks to the `Numpy `_ and `Scipy `_ libraries, and are based on many of the same algorithms used in propriety software. 94 | 95 | * QuTiP allows for solving the dynamics of Hamiltonians with arbitrary time-dependence, including collapse operators. 96 | 97 | * Time-dependent problems can be automatically compiled into C-code at run-time for increased performance. 98 | 99 | * Takes advantage of the multiple processing cores found in essentially all modern computers. 100 | 101 | * QuTiP was designed from the start to require a minimal learning curve for those users who have experience using the popular quantum optics toolbox by Sze M. Tan. 102 | 103 | * Includes the ability to create high-quality plots, and animations, using the excellent `Matplotlib `_ package. 104 | 105 | 106 | For detailed information about new features of each release of QuTiP, see the :ref:`changelog`. 107 | 108 | Contributing to QuTiP 109 | ===================== 110 | We welcome anyone who is interested in helping us make QuTiP the best package for simulating quantum systems. Anyone who contributes will be duly recognized. Even small contributions are noted. See :ref:`developers-contributors` for a list of people who have helped in one way or another. If you are interested, please drop us a line at the `QuTiP discussion group webpage`_. 111 | 112 | 113 | .. _QuTiP discussion group webpage: http://groups.google.com/group/qutip. 114 | 115 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = HEAD 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/QuTiP.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/QuTiP.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/QuTiP" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/QuTiP" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /guide/guide-saving.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _saving: 5 | 6 | ********************************** 7 | Saving QuTiP Objects and Data Sets 8 | ********************************** 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | import numpy as np 15 | 16 | 17 | With time-consuming calculations it is often necessary to store the results to files on disk, so it can be post-processed and archived. In QuTiP there are two facilities for storing data: Quantum objects can be stored to files and later read back as python pickles, and numerical data (vectors and matrices) can be exported as plain text files in for example CSV (comma-separated values), TSV (tab-separated values), etc. The former method is preferred when further calculations will be performed with the data, and the latter when the calculations are completed and data is to be imported into a post-processing tool (e.g. for generating figures). 18 | 19 | Storing and loading QuTiP objects 20 | ================================= 21 | 22 | To store and load arbitrary QuTiP related objects (:class:`qutip.Qobj`, :class:`qutip.solver.Result`, etc.) there are two functions: :func:`qutip.fileio.qsave` and :func:`qutip.fileio.qload`. The function :func:`qutip.fileio.qsave` takes an arbitrary object as first parameter and an optional filename as second parameter (default filename is `qutip_data.qu`). The filename extension is always `.qu`. The function :func:`qutip.fileio.qload` takes a mandatory filename as first argument and loads and returns the objects in the file. 23 | 24 | To illustrate how these functions can be used, consider a simple calculation of the steadystate of the harmonic oscillator: 25 | 26 | .. ipython:: 27 | 28 | In [1]: a = destroy(10); H = a.dag() * a ; c_ops = [sqrt(0.5) * a, sqrt(0.25) * a.dag()] 29 | 30 | In [2]: rho_ss = steadystate(H, c_ops) 31 | 32 | The steadystate density matrix `rho_ss` is an instance of :class:`qutip.Qobj`. It can be stored to a file `steadystate.qu` using 33 | 34 | .. ipython:: 35 | 36 | In [1]: qsave(rho_ss, 'steadystate') 37 | 38 | In [2]: ls *.qu 39 | 40 | 41 | and it can later be loaded again, and used in further calculations: 42 | 43 | .. ipython:: 44 | 45 | In [1]: rho_ss_loaded = qload('steadystate') 46 | 47 | In [2]: a = destroy(10) 48 | 49 | In [3]: expect(a.dag() * a, rho_ss_loaded) 50 | 51 | The nice thing about the :func:`qutip.fileio.qsave` and :func:`qutip.fileio.qload` functions is that almost any object can be stored and load again later on. We can for example store a list of density matrices as returned by :func:`qutip.mesolve`: 52 | 53 | .. ipython:: 54 | 55 | In [1]: a = destroy(10); H = a.dag() * a ; c_ops = [sqrt(0.5) * a, sqrt(0.25) * a.dag()] 56 | 57 | In [2]: psi0 = rand_ket(10) 58 | 59 | In [3]: times = np.linspace(0, 10, 10) 60 | 61 | In [4]: dm_list = mesolve(H, psi0, times, c_ops, []) 62 | 63 | In [5]: qsave(dm_list, 'density_matrix_vs_time') 64 | 65 | And it can then be loaded and used again, for example in an other program: 66 | 67 | .. ipython:: 68 | 69 | In [1]: dm_list_loaded = qload('density_matrix_vs_time') 70 | 71 | In [2]: a = destroy(10) 72 | 73 | In [3]: expect(a.dag() * a, dm_list_loaded.states) 74 | 75 | 76 | Storing and loading datasets 77 | ============================ 78 | 79 | The :func:`qutip.fileio.qsave` and :func:`qutip.fileio.qload` are great, but the file format used is only understood by QuTiP (python) programs. When data must be exported to other programs the preferred method is to store the data in the commonly used plain-text file formats. With the QuTiP functions :func:`qutip.fileio.file_data_store` and :func:`qutip.fileio.file_data_read` we can store and load **numpy** arrays and matrices to files on disk using a deliminator-separated value format (for example comma-separated values CSV). Almost any program can handle this file format. 80 | 81 | The :func:`qutip.fileio.file_data_store` takes two mandatory and three optional arguments: 82 | 83 | >>> file_data_store(filename, data, numtype="complex", numformat="decimal", sep=",") 84 | 85 | where `filename` is the name of the file, `data` is the data to be written to the file (must be a *numpy* array), `numtype` (optional) is a flag indicating numerical type that can take values `complex` or `real`, `numformat` (optional) specifies the numerical format that can take the values `exp` for the format `1.0e1` and `decimal` for the format `10.0`, and `sep` (optional) is an arbitrary single-character field separator (usually a tab, space, comma, semicolon, etc.). 86 | 87 | A common use for the :func:`qutip.fileio.file_data_store` function is to store the expectation values of a set of operators for a sequence of times, e.g., as returned by the :func:`qutip.mesolve` function, which is what the following example does: 88 | 89 | .. ipython:: 90 | 91 | In [1]: a = destroy(10); H = a.dag() * a ; c_ops = [sqrt(0.5) * a, sqrt(0.25) * a.dag()] 92 | 93 | In [2]: psi0 = rand_ket(10) 94 | 95 | In [3]: times = np.linspace(0, 100, 100) 96 | 97 | In [4]: medata = mesolve(H, psi0, times, c_ops, [a.dag() * a, a + a.dag(), -1j * (a - a.dag())]) 98 | 99 | In [5]: shape(medata.expect) 100 | 101 | In [6]: shape(times) 102 | 103 | In [7]: output_data = np.vstack((times, medata.expect)) # join time and expt data 104 | 105 | In [8]: file_data_store('expect.dat', output_data.T) # Note the .T for transpose! 106 | 107 | In [9]: ls *.dat 108 | 109 | In [10]: !head expect.dat 110 | 111 | 112 | In this case we didn't really need to store both the real and imaginary parts, so instead we could use the `numtype="real"` option: 113 | 114 | .. ipython:: 115 | 116 | In [1]: file_data_store('expect.dat', output_data.T, numtype="real") 117 | 118 | In [2]: !head -n5 expect.dat 119 | 120 | 121 | and if we prefer scientific notation we can request that using the `numformat="exp"` option 122 | 123 | .. ipython:: 124 | 125 | In [1]: file_data_store('expect.dat', output_data.T, numtype="real", numformat="exp") 126 | 127 | In [2]: !head -n 5 expect.dat 128 | 129 | Loading data previously stored using :func:`qutip.fileio.file_data_store` (or some other software) is a even easier. Regardless of which deliminator was used, if data was stored as complex or real numbers, if it is in decimal or exponential form, the data can be loaded using the :func:`qutip.fileio.file_data_read`, which only takes the filename as mandatory argument. 130 | 131 | .. ipython:: 132 | 133 | In [1]: input_data = file_data_read('expect.dat') 134 | 135 | In [2]: shape(input_data) 136 | 137 | In [4]: from pylab import * 138 | 139 | @savefig saving_ex.png width=4in align=center 140 | In [3]: plot(input_data[:,0], input_data[:,1]); # plot the data 141 | 142 | 143 | (If a particularly obscure choice of deliminator was used it might be necessary to use the optional second argument, for example `sep="_"` if _ is the deliminator). 144 | 145 | -------------------------------------------------------------------------------- /guide/guide-eseries.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _eseries: 5 | 6 | ********************************** 7 | An Overview of the Eseries Class 8 | ********************************** 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | In [2]: from scipy import * 16 | 17 | .. _eseries-rep: 18 | 19 | Exponential-series representation of time-dependent quantum objects 20 | =================================================================== 21 | 22 | The eseries object in QuTiP is a representation of an exponential-series expansion of time-dependent quantum objects (a concept borrowed from the quantum optics toolbox). 23 | 24 | An exponential series is parameterized by its amplitude coefficients :math:`c_i` and rates :math:`r_i`, so that the series takes the form :math:`E(t) = \sum_i c_i e^{r_it}`. The coefficients are typically quantum objects (type Qobj: states, operators, etc.), so that the value of the eseries also is a quantum object, and the rates can be either real or complex numbers (describing decay rates and oscillation frequencies, respectively). Note that all amplitude coefficients in an exponential series must be of the same dimensions and composition. 25 | 26 | In QuTiP, an exponential series object is constructed by creating an instance of the class :class:`qutip.eseries`: 27 | 28 | .. ipython:: 29 | 30 | In [1]: es1 = eseries(sigmax(), 1j) 31 | 32 | where the first argument is the amplitude coefficient (here, the sigma-X operator), and the second argument is the rate. The eseries in this example represents the time-dependent operator :math:`\sigma_x e^{i t}`. 33 | 34 | To add more terms to an :class:`qutip.eseries` object we simply add objects using the ``+`` operator: 35 | 36 | .. ipython:: 37 | 38 | In [1]: omega=1.0 39 | 40 | In [2]: es2 = (eseries(0.5 * sigmax(), 1j * omega) + 41 | ...: eseries(0.5 * sigmax(), -1j * omega)) 42 | 43 | The :class:`qutip.eseries` in this example represents the operator :math:`0.5 \sigma_x e^{i\omega t} + 0.5 \sigma_x e^{-i\omega t}`, which is the exponential series representation of :math:`\sigma_x \cos(\omega t)`. Alternatively, we can also specify a list of amplitudes and rates when the :class:`qutip.eseries` is created: 44 | 45 | .. ipython:: 46 | 47 | In [2]: es2 = eseries([0.5 * sigmax(), 0.5 * sigmax()], [1j * omega, -1j * omega]) 48 | 49 | 50 | We can inspect the structure of an :class:`qutip.eseries` object by printing it to the standard output console: 51 | 52 | .. ipython:: 53 | 54 | In [1]: es2 55 | 56 | 57 | and we can evaluate it at time `t` by using the :func:`qutip.eseries.esval` function: 58 | 59 | .. ipython:: 60 | 61 | In [1]: esval(es2, 0.0) # equivalent to es2.value(0.0) 62 | 63 | 64 | or for a list of times ``[0.0, 1.0 * pi, 2.0 * pi]``: 65 | 66 | .. ipython:: 67 | 68 | In [1]: times = [0.0, 1.0 * pi, 2.0 * pi] 69 | 70 | In [2]: esval(es2, times) # equivalent to es2.value(times) 71 | 72 | To calculate the expectation value of an time-dependent operator represented by an :class:`qutip.eseries`, we use the :func:`qutip.expect` function. For example, consider the operator :math:`\sigma_x \cos(\omega t) + \sigma_z\sin(\omega t)`, and say we would like to know the expectation value of this operator for a spin in its excited state (``rho = fock_dm(2,1)`` produce this state): 73 | 74 | .. ipython:: 75 | 76 | In [1]: es3 = (eseries([0.5*sigmaz(), 0.5*sigmaz()], [1j, -1j]) + 77 | ...: eseries([-0.5j*sigmax(), 0.5j*sigmax()], [1j, -1j])) 78 | 79 | In [2]: rho = fock_dm(2, 1) 80 | 81 | In [3]: es3_expect = expect(rho, es3) 82 | 83 | In [4]: es3_expect 84 | 85 | In [5]: es3_expect.value([0.0, pi/2]) 86 | 87 | Note the expectation value of the :class:`qutip.eseries` object, ``expect(rho, es3)``, itself is an :class:`qutip.eseries`, but with amplitude coefficients that are C-numbers instead of quantum operators. To evaluate the C-number :class:`qutip.eseries` at the times `times` we use ``esval(es3_expect, times)``, or, equivalently, ``es3_expect.value(times)``. 88 | 89 | .. _eseries-applications: 90 | 91 | Applications of exponential series 92 | ================================== 93 | 94 | The exponential series formalism can be useful for the time-evolution of quantum systems. One approach to calculating the time evolution of a quantum system is to diagonalize its Hamiltonian (or Liouvillian, for dissipative systems) and to express the propagator (e.g., :math:`\exp(-iHt) \rho \exp(iHt)`) as an exponential series. 95 | 96 | The QuTiP function :func:`qutip.essolve.ode2es` and :func:`qutip.essolve` use this method to evolve quantum systems in time. The exponential series approach is particularly suitable for cases when the same system is to be evolved for many different initial states, since the diagonalization only needs to be performed once (as opposed to e.g. the ode solver that would need to be ran independently for each initial state). 97 | 98 | As an example, consider a spin-1/2 with a Hamiltonian pointing in the :math:`\sigma_z` direction, and that is subject to noise causing relaxation. For a spin originally is in the up state, we can create an :class:`qutip.eseries` object describing its dynamics by using the :func:`qutip.es2ode` function: 99 | 100 | .. ipython:: 101 | 102 | In [1]: psi0 = basis(2,1) 103 | 104 | In [2]: H = sigmaz() 105 | 106 | In [3]: L = liouvillian(H, [sqrt(1.0) * destroy(2)]) 107 | 108 | In [4]: es = ode2es(L, psi0) 109 | 110 | The :func:`qutip.essolve.ode2es` function diagonalizes the Liouvillian :math:`L` and creates an exponential series with the correct eigenfrequencies and amplitudes for the initial state :math:`\psi_0` (`psi0`). 111 | 112 | We can examine the resulting :class:`qutip.eseries` object by printing a text representation: 113 | 114 | .. ipython:: 115 | 116 | In [1]: es 117 | 118 | or by evaluating it and arbitrary points in time (here at 0.0 and 1.0): 119 | 120 | .. ipython:: 121 | 122 | In [1]: es.value([0.0, 1.0]) 123 | 124 | and the expectation value of the exponential series can be calculated using the :func:`qutip.expect` function: 125 | 126 | .. ipython:: 127 | 128 | In [1]: es_expect = expect(sigmaz(), es) 129 | 130 | The result `es_expect` is now an exponential series with c-numbers as amplitudes, which easily can be evaluated at arbitrary times: 131 | 132 | .. ipython:: 133 | 134 | In [1]: es_expect.value([0.0, 1.0, 2.0, 3.0]) 135 | 136 | .. ipython:: 137 | 138 | In [1]: times = linspace(0.0, 10.0, 100) 139 | 140 | In [2]: sz_expect = es_expect.value(times) 141 | 142 | In [3]: from pylab import * 143 | 144 | In [4]: plot(times, sz_expect, lw=2); 145 | 146 | In [5]: xlabel("Time", fontsize=16) 147 | ...:ylabel("Expectation value of sigma-z", fontsize=16); 148 | 149 | @savefig eseries_example.png width=4in align=center 150 | In [6]: title("The expectation value of the $\sigma_{z}$ operator", fontsize=16); 151 | 152 | -------------------------------------------------------------------------------- /guide/dynamics/dynamics-data.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _solver_result: 5 | 6 | ******************************************************** 7 | Dynamics Simulation Results 8 | ******************************************************** 9 | 10 | .. important:: In QuTiP 2, the results from all of the dynamics solvers are returned as Odedata objects. This unified and significantly simplified postprocessing of simulation results from different solvers, compared to QuTiP 1. However, this change also results in the loss of backward compatibility with QuTiP version 1.x. In QuTiP 3, the Odedata class has been renamed to Result, but for backwards compatibility an alias between Result and Odedata is provided. 11 | 12 | .. _solver_result-class: 13 | 14 | The solver.Result Class 15 | ======================= 16 | 17 | Before embarking on simulating the dynamics of quantum systems, we will first look at the data structure used for returning the simulation results to the user. This object is a :func:`qutip.solver.Result` class that stores all the crucial data needed for analyzing and plotting the results of a simulation. Like the :func:`qutip.Qobj` class, the ``Result`` class has a collection of properties for storing information. However, in contrast to the ``Qobj`` class, this structure contains no methods, and is therefore nothing but a container object. A generic ``Result`` object ``result`` contains the following properties for storing simulation data: 18 | 19 | .. cssclass:: table-striped 20 | 21 | +------------------------+-----------------------------------------------------------------------+ 22 | | Property | Description | 23 | +========================+=======================================================================+ 24 | | ``result.solver`` | String indicating which solver was used to generate the data. | 25 | +------------------------+-----------------------------------------------------------------------+ 26 | | ``result.times`` | List/array of times at which simulation data is calculated. | 27 | +------------------------+-----------------------------------------------------------------------+ 28 | | ``result.expect`` | List/array of expectation values, if requested. | 29 | +------------------------+-----------------------------------------------------------------------+ 30 | | ``result.states`` | List/array of state vectors/density matrices calculated at ``times``, | 31 | | | if requested. | 32 | +------------------------+-----------------------------------------------------------------------+ 33 | | ``result.num_expect`` | The number of expectation value operators in the simulation. | 34 | +------------------------+-----------------------------------------------------------------------+ 35 | | ``result.num_collapse``| The number of collapse operators in the simulation. | 36 | +------------------------+-----------------------------------------------------------------------+ 37 | | ``result.ntraj`` | Number of Monte Carlo trajectories run. | 38 | +------------------------+-----------------------------------------------------------------------+ 39 | | ``result.col_times`` | Times at which state collapse occurred. Only for Monte Carlo solver. | 40 | +------------------------+-----------------------------------------------------------------------+ 41 | | ``result.col_which`` | Which collapse operator was responsible for each collapse in | 42 | | | in ``col_times``. Only used by Monte Carlo solver. | 43 | +------------------------+-----------------------------------------------------------------------+ 44 | | ``result.seeds`` | Seeds used in generating random numbers for Monte Carlo solver. | 45 | +------------------------+-----------------------------------------------------------------------+ 46 | 47 | 48 | .. _odedata-access: 49 | 50 | Accessing Result Data 51 | ====================== 52 | 53 | To understand how to access the data in a Result object we will use an example as a guide, although we do not worry about the simulation details at this stage. Like all solvers, the Monte Carlo solver used in this example returns an Result object, here called simply ``result``. To see what is contained inside ``result`` we can use the print function: 54 | 55 | >>> print(result) 56 | Result object with mcsolve data. 57 | --------------------------------- 58 | expect = True 59 | num_expect = 2, num_collapse = 2, ntraj = 500 60 | 61 | The first line tells us that this data object was generated from the Monte Carlo solver ``mcsolve`` (discussed in :ref:`monte`). The next line (not the ``---`` line of course) indicates that this object contains expectation value data. Finally, the last line gives the number of expectation value and collapse operators used in the simulation, along with the number of Monte Carlo trajectories run. Note that the number of trajectories ``ntraj`` is only displayed when using the Monte Carlo solver. 62 | 63 | Now we have all the information needed to analyze the simulation results. To access the data for the two expectation values one can do:: 64 | 65 | >>> expt0 = result.expect[0] 66 | >>> expt1 = result.expect[1] 67 | 68 | Recall that Python uses C-style indexing that begins with zero (i.e., [0] => 1st collapse operator data). Together with the array of times at which these expectation values are calculated:: 69 | 70 | >>> times = result.times 71 | 72 | we can plot the resulting expectation values:: 73 | 74 | >>> plot(times, expt0, times, expt1) 75 | >>> show() 76 | 77 | 78 | State vectors, or density matrices, as well as ``col_times`` and ``col_which``, are accessed in a similar manner, although typically one does not need an index (i.e [0]) since there is only one list for each of these components. The one exception to this rule is if you choose to output state vectors from the Monte Carlo solver, in which case there are ``ntraj`` number of state vector arrays. 79 | 80 | .. _odedata-saving: 81 | 82 | Saving and Loading Result Objects 83 | ================================== 84 | 85 | The main advantage in using the Result class as a data storage object comes from the simplicity in which simulation data can be stored and later retrieved. The :func:`qutip.fileio.qsave` and :func:`qutip.fileio.qload` functions are designed for this task. To begin, let us save the ``data`` object from the previous section into a file called "cavity+qubit-data" in the current working directory by calling: 86 | 87 | >>> qsave(result, 'cavity+qubit-data') 88 | 89 | All of the data results are then stored in a single file of the same name with a ".qu" extension. Therefore, everything needed to later this data is stored in a single file. Loading the file is just as easy as saving: 90 | 91 | >>> stored_result = qload('cavity+qubit-data') 92 | Loaded Result object: 93 | Result object with mcsolve data. 94 | --------------------------------- 95 | expect = True 96 | num_expect = 2, num_collapse = 2, ntraj = 500 97 | 98 | where ``stored_result`` is the new name of the Result object. We can then extract the data and plot in the same manner as before:: 99 | 100 | expt0 = stored_result.expect[0] 101 | expt1 = stored_result.expect[1] 102 | times = stored_result.times 103 | plot(times, expt0, times, expt1) 104 | show() 105 | 106 | Also see :ref:`saving` for more information on saving quantum objects, as well as arrays for use in other programs. 107 | -------------------------------------------------------------------------------- /apidoc/functions.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _functions: 5 | 6 | *************** 7 | Functions 8 | *************** 9 | 10 | Manipulation and Creation of States and Operators 11 | ================================================= 12 | 13 | Quantum States 14 | ---------------- 15 | 16 | .. automodule:: qutip.states 17 | :members: basis, coherent, coherent_dm, fock, fock_dm, ket2dm, qutrit_basis, thermal_dm, phase_basis, state_number_enumerate, state_number_index, state_index_number, state_number_qobj, enr_state_dictionaries, enr_thermal_dm, enr_fock 18 | 19 | 20 | Quantum Operators 21 | --------------------- 22 | 23 | .. automodule:: qutip.operators 24 | :members: create, destroy, displace, jmat, num, qeye, identity, qutrit_ops, sigmam, sigmap, sigmax, sigmay, sigmaz, squeeze, squeezing, phase, enr_destroy, enr_identity 25 | 26 | 27 | .. _functions-rand: 28 | 29 | Random Operators and States 30 | --------------------------- 31 | 32 | .. automodule:: qutip.random_objects 33 | :members: rand_dm, rand_herm, rand_ket, rand_unitary 34 | 35 | 36 | Three-Level Atoms 37 | ------------------- 38 | 39 | .. automodule:: qutip.three_level_atom 40 | :members: three_level_basis, three_level_ops 41 | :undoc-members: 42 | 43 | 44 | Superoperators and Liouvillians 45 | ------------------------------- 46 | 47 | .. automodule:: qutip.superoperator 48 | :members: operator_to_vector, vector_to_operator, liouvillian, spost, spre, sprepost, lindblad_dissipator 49 | 50 | Superoperator Representations 51 | ----------------------------- 52 | 53 | .. automodule:: qutip.superop_reps 54 | :members: to_choi, to_super, to_kraus 55 | :undoc-members: 56 | 57 | 58 | Functions acting on states and operators 59 | ======================================== 60 | 61 | Tensor 62 | ------- 63 | 64 | .. automodule:: qutip.tensor 65 | :members: tensor, super_tensor, composite, tensor_contract 66 | 67 | 68 | Expectation Values 69 | -------------------- 70 | 71 | .. automodule:: qutip.expect 72 | :members: expect, variance, expect_rho_vec, expect_psi 73 | 74 | Partial Transpose 75 | ----------------- 76 | 77 | .. automodule:: qutip.partial_transpose 78 | :members: partial_transpose 79 | 80 | 81 | .. _functions-entropy: 82 | 83 | Entropy Functions 84 | ----------------- 85 | 86 | .. automodule:: qutip.entropy 87 | :members: concurrence, entropy_conditional, entropy_linear, entropy_mutual, entropy_vn 88 | 89 | 90 | Density Matrix Metrics 91 | ---------------------- 92 | 93 | .. automodule:: qutip.metrics 94 | :members: fidelity, tracedist, bures_dist, bures_angle, hilbert_dist, average_gate_fidelity, process_fidelity 95 | 96 | 97 | Continous Variables 98 | ------------------- 99 | 100 | .. automodule:: qutip.continuous_variables 101 | :members: correlation_matrix, covariance_matrix, correlation_matrix_field, correlation_matrix_quadrature, wigner_covariance_matrix, logarithmic_negativity 102 | 103 | 104 | Dynamics and Time-Evolution 105 | =========================== 106 | 107 | Schrödinger Equation 108 | -------------------- 109 | 110 | .. automodule:: qutip.sesolve 111 | :members: sesolve 112 | 113 | Master Equation 114 | ----------------- 115 | 116 | .. automodule:: qutip.mesolve 117 | :members: mesolve 118 | 119 | Monte Carlo Evolution 120 | ----------------------- 121 | 122 | .. automodule:: qutip.mcsolve 123 | :members: mcsolve 124 | 125 | .. automodule:: qutip.fortran.mcsolve_f90 126 | :members: mcsolve_f90 127 | 128 | 129 | Exponential Series 130 | ------------------ 131 | 132 | .. automodule:: qutip.essolve 133 | :members: essolve, ode2es 134 | 135 | 136 | Bloch-Redfield Master Equation 137 | ------------------------------ 138 | 139 | .. automodule:: qutip.bloch_redfield 140 | :members: brmesolve, bloch_redfield_tensor, bloch_redfield_solve 141 | 142 | 143 | Floquet States and Floquet-Markov Master Equation 144 | ------------------------------------------------- 145 | 146 | .. automodule:: qutip.floquet 147 | :members: fmmesolve, floquet_modes, floquet_modes_t, floquet_modes_table, floquet_modes_t_lookup, floquet_states_t, floquet_wavefunction_t, floquet_state_decomposition, fsesolve 148 | 149 | 150 | Stochastic Schrödinger Equation and Master Equation 151 | --------------------------------------------------- 152 | 153 | .. automodule:: qutip.stochastic 154 | :members: smesolve, ssesolve, smepdpsolve, ssepdpsolve 155 | 156 | 157 | Correlation Functions 158 | ----------------------- 159 | 160 | .. automodule:: qutip.correlation 161 | :members: correlation, correlation_ss, correlation_2op_1t, correlation_2op_2t, correlation_3op_1t, correlation_3op_2t, correlation_4op_1t, correlation_4op_2t, spectrum, spectrum_ss, spectrum_pi, spectrum_correlation_fft, coherence_function_g1, coherence_function_g2 162 | 163 | 164 | Steady-state Solvers 165 | -------------------- 166 | 167 | .. automodule:: qutip.steadystate 168 | :members: steadystate, build_preconditioner 169 | :undoc-members: 170 | 171 | Propagators 172 | ----------- 173 | 174 | .. automodule:: qutip.propagator 175 | :members: propagator, propagator_steadystate 176 | :undoc-members: 177 | 178 | 179 | Time-dependent problems 180 | ----------------------- 181 | 182 | .. automodule:: qutip 183 | :members: rhs_generate, rhs_clear 184 | 185 | Visualization 186 | =============== 187 | 188 | 189 | Pseudoprobability Functions 190 | ---------------------------- 191 | 192 | .. automodule:: qutip.wigner 193 | :members: qfunc, wigner 194 | 195 | 196 | Graphs and Visualization 197 | ------------------------ 198 | 199 | .. automodule:: qutip.visualization 200 | :members: hinton, matrix_histogram, matrix_histogram_complex, plot_energy_levels, wigner_cmap, plot_fock_distribution, plot_wigner_fock_distribution, plot_wigner, sphereplot, plot_schmidt, plot_qubism, plot_expectation_values, plot_spin_distribution_2d, plot_spin_distribution_3d 201 | :undoc-members: 202 | 203 | .. automodule:: qutip 204 | :members: orbital 205 | 206 | 207 | Quantum Process Tomography 208 | -------------------------- 209 | 210 | .. automodule:: qutip.tomography 211 | :members: qpt, qpt_plot, qpt_plot_combined 212 | :undoc-members: 213 | 214 | 215 | 216 | .. _functions-qip: 217 | 218 | Quantum Information Processing 219 | ============================== 220 | 221 | Gates 222 | ----- 223 | 224 | .. automodule:: qutip.qip.gates 225 | :members: rx, ry, rz, sqrtnot, snot, phasegate, cphase, cnot, csign, berkeley, swapalpha, swap, iswap, sqrtswap, sqrtiswap, fredkin, toffoli, rotation, controlled_gate, globalphase, hadamard_transform, gate_sequence_product, gate_expand_1toN, gate_expand_2toN, gate_expand_3toN 226 | 227 | Qubits 228 | ------ 229 | 230 | .. automodule:: qutip.qip.qubits 231 | :members: qubit_states 232 | 233 | Algorithms 234 | ---------- 235 | 236 | .. automodule:: qutip.qip.algorithms.qft 237 | :members: qft, qft_steps, qft_gate_sequence 238 | 239 | 240 | .. _functions-metrics: 241 | 242 | Optimal control 243 | =============== 244 | 245 | .. automodule:: qutip.control.grape 246 | :members: plot_grape_control_fields, grape_unitary, grape_unitary_adaptive 247 | 248 | .. automodule:: qutip.control.pulseoptim 249 | :members: optimize_pulse, optimize_pulse_unitary, create_pulse_optimizer 250 | 251 | .. automodule:: qutip.control.pulsegen 252 | :members: create_pulse_gen 253 | 254 | .. automodule:: qutip.control.pulsegen 255 | :members: initialize_controls 256 | 257 | 258 | Utilitiy Functions 259 | ================== 260 | 261 | 262 | Graph Theory Routines 263 | ---------------------- 264 | 265 | .. automodule:: qutip.graph 266 | :members: breadth_first_search, graph_degree, reverse_cuthill_mckee, maximum_bipartite_matching, weighted_bipartite_matching 267 | 268 | 269 | .. _functions-utilities: 270 | 271 | Utility Functions 272 | ------------------ 273 | 274 | .. automodule:: qutip.utilities 275 | :members: n_thermal, linspace_with, clebsch, convert_unit 276 | 277 | 278 | .. _functions-fileio: 279 | 280 | File I/O Functions 281 | ------------------ 282 | 283 | .. automodule:: qutip.fileio 284 | :members: file_data_read, file_data_store, qload, qsave 285 | 286 | 287 | .. _functions-parallel: 288 | 289 | Parallelization 290 | --------------- 291 | 292 | .. automodule:: qutip.parallel 293 | :members: parfor, parallel_map, serial_map 294 | 295 | 296 | .. _functions-ipython: 297 | 298 | IPython Notebook Tools 299 | ---------------------- 300 | 301 | .. automodule:: qutip.ipynbtools 302 | :members: parfor, parallel_map, version_table 303 | 304 | .. _functions-misc: 305 | 306 | Miscellaneous 307 | -------------- 308 | 309 | .. automodule:: qutip 310 | :members: about, simdiag 311 | -------------------------------------------------------------------------------- /contrib/sim_ent_qkd/sim_ent_qkd.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Code for simulating secure key rate, twofolds, and quantum bit error rate 3 | Written in Python and QuTIP by Catherine Holloway (c2hollow@iqc.ca). 4 | 5 | Detector model and squashing functions by Catherine Holloway, 6 | based on code by Dr. Thomas Jennewein (tjennewe@iqc.ca). 7 | 8 | Contributed to the QuTiP project on June 06, 2012 by Catherine Holloway. 9 | ''' 10 | 11 | #imports 12 | from qutip import * 13 | from numpy import * 14 | from pylab import * 15 | import matplotlib 16 | import matplotlib.pyplot as plt 17 | 18 | 19 | def choose(n, k): 20 | """ 21 | Binomial coefficient function for the detector model. 22 | 23 | Parameters 24 | ---------- 25 | n : int 26 | Number of elements. 27 | k : int 28 | Number of subelements. 29 | 30 | Returns 31 | ------- 32 | coeff : int 33 | Binomial coefficient. 34 | 35 | """ 36 | if 0 <= k <= n: 37 | ntok = 1 38 | ktok = 1 39 | for t in xrange(1, min(k, n - k) + 1): 40 | ntok *= n 41 | ktok *= t 42 | n -= 1 43 | return ntok // ktok 44 | else: 45 | return 0 46 | 47 | 48 | def BucketDetector_realistic_detector(N,efficiency,n_factor): 49 | """ 50 | Bucket detector model based on H. Lee, U. Yurtsever, P. Kok, G. Hockney, C. Adami, S. Braunstein, 51 | and J. Dowling, "Towards photostatistics from photon-number discriminating detectors," 52 | Journal of Modern Optics, vol. 51, p. 15171528, 2004. 53 | 54 | Parameters 55 | ---------- 56 | N : int 57 | The Fock Space dimension. 58 | efficiency : float 59 | The channel efficiency. 60 | n_factor : float 61 | The average number of dark counts per detection window APD (Bucket Detector). 62 | 63 | Returns 64 | ------- 65 | [proj, un_proj] : list 66 | The projection and unprojection operators. 67 | 68 | """ 69 | proj=zeros((N,N)) 70 | #APD (Bucket Detector) un_detector (=gives probability for 0-detection) 71 | un_proj=identity(N) 72 | #n_factor = 0; 73 | for i in range(N): 74 | probs = 0; 75 | for k in range (1,100): 76 | for d in range(k+1): 77 | if k-d<=i: 78 | probs= probs+ (exp(-n_factor)*(n_factor)**(d))/factorial(d)*choose(i,k-d)*efficiency**(k-d)*(1-efficiency)**(i-k+d) 79 | 80 | proj[i,i]=probs 81 | 82 | 83 | un_proj = un_proj-proj 84 | un_proj = Qobj(un_proj) 85 | proj = Qobj(proj) 86 | return [proj,un_proj] 87 | 88 | 89 | def measure_2folds_4modes_squashing(N,psi,proj,proj2): 90 | """ 91 | Determines the 2-fold count rate on the joint state 92 | outputs for an array of double count probabilities. 93 | 94 | Parameters 95 | ---------- 96 | N : int 97 | The Fock Space dimension. 98 | psi : qobj 99 | The entangled state to analyze 100 | proj1 : qobj 101 | 1st projection operator for the Channel between Alice and 102 | the Channel between Bob. 103 | proj2 : qobj 104 | 2nd projection operator for the Channel between Alice and 105 | the Channel between Bob. 106 | 107 | Returns 108 | ------- 109 | [HH,HV,VH,VV] : list 110 | Two-fold probabilities. 111 | 112 | Notes 113 | ----- 114 | The squashing (assigning double pairs to random bases) comes from two papers: 115 | 116 | T. Moroder, O. Guhne, N. Beaudry, M. Piani, and N. Lutkenhaus, 117 | "Entanglement verication with realistic measurement devices via squashing operations," 118 | Phys. Rev. A, vol. 81, p. 052342, May 2010. 119 | 120 | N. Lutkenhaus, "Estimates for practical quantum cryptography," Phys. Rev.A, 121 | vol. 59, pp. 3301-3319, May 1999. 122 | 123 | """ 124 | ida=qeye(N) 125 | final_state=psi 126 | det_exp = zeros((2,2,2,2)) 127 | 128 | #i,j,k,l means Ha,Va,Hb,Vb, 0 means detector clicked, 1 means detector did not click 129 | for i in range(2): 130 | for j in range(2): 131 | for k in range(2): 132 | for l in range(2): 133 | #expectation values for different detector configurations 134 | det_exp[i][j][k][l] = abs(expect(tensor(proj[i],proj[j],proj2[k],proj[l]),final_state)) 135 | #two fold probabilities 136 | HH = det_exp[0][1][0][1]+0.5*(det_exp[0][0][0][1]+det_exp[0][1][0][0])+0.25*det_exp[0][0][0][0] 137 | VV = det_exp[1][0][1][0]+0.5*(det_exp[0][0][1][0]+det_exp[1][0][0][0])+0.25*det_exp[0][0][0][0] 138 | HV = det_exp[0][1][1][0]+0.5*(det_exp[0][0][1][0]+det_exp[0][1][0][0])+0.25*det_exp[0][0][0][0] 139 | VH = det_exp[1][0][0][1]+0.5*(det_exp[0][0][0][1]+det_exp[1][0][0][0])+0.25*det_exp[0][0][0][0] 140 | 141 | return [HH,HV,VH,VV] 142 | 143 | 144 | def sim_qkd_entanglement(eps,loss_a,loss_b,n_factor_a,n_factor_b,N): 145 | """ 146 | Simulate skr with an SPDC state. 147 | 148 | Parameters 149 | ---------- 150 | eps : float 151 | The squeezing factor, sort of analogous to the amount of 152 | pumping power to the spdc source, but not really. 153 | loss_a : float 154 | Efficiency of the quantum channel going to Alice. 155 | loss_b : float 156 | Efficiency of the quantum channel going to Bob. 157 | n_factor_a : float 158 | Background noise in Alice's detection. 159 | n_factor_b : float 160 | Background noise in Bob's detection. 161 | N : int 162 | Size of the fock space that we allow for the states 163 | 164 | Returns 165 | ------- 166 | qber : float 167 | The Quantum Bit Error Rate 168 | twofolds : float 169 | Probability of Alice and Bob getting a simultaneous detection 170 | of a photon pair (also referred to as coincidences) within a 171 | timing window. 172 | skr : float 173 | Probability of getting a secure key bit within a timing window, 174 | assuming error correction and privacy amplification, in the 175 | limit of many coincidences. 176 | 177 | """ 178 | #make vaccuum state 179 | vacc = basis(N,0) 180 | 181 | #make squeezing operator for SPDC 182 | H_sq = 1j*eps*(tensor(create(N),create(N))+tensor(destroy(N),destroy(N))) 183 | 184 | #exponentiate hamiltonian and apply it to vaccuum state to make an SPDC state 185 | U_sq = H_sq.expm() 186 | spdc = U_sq*tensor(vacc,vacc) 187 | psi = tensor(spdc,spdc) 188 | #since qutip doesn't have a permute function, 189 | #we have to do a couple of steps in between 190 | #1. turn psi from a sparse matrix to a full matrix 191 | out = psi.full() 192 | #2. reshape psi into a 4-D matrix 193 | out = reshape(out, (N,N,N,-1)) 194 | #3. permute the dimensions of our 4-D matrix 195 | out = transpose(out,(0,3,2,1)) 196 | #4. turn the matrix back into a 1-D array 197 | out = reshape(out,(N*N*N*N,-1)) 198 | #5. convert the matrix back into a quantum object 199 | psi = Qobj(out,dims = [[N, N, N, N], [1, 1, 1, 1]]) 200 | 201 | # model detectors 202 | a_det = BucketDetector_realistic_detector(N,loss_a,n_factor_a) 203 | b_det = BucketDetector_realistic_detector(N,loss_b,n_factor_b) 204 | 205 | #measure detection probabilities 206 | probs2f=measure_2folds_4modes_squashing(N,psi,a_det,b_det) 207 | 208 | #Rates returned are 'per pulse', so multiply by source rate 209 | twofolds=probs2f[0]+probs2f[1]+probs2f[2]+probs2f[3] 210 | #Determine QBER from returned detection probabilities 211 | qber = (probs2f[0]+probs2f[3])/twofolds 212 | 213 | #calculate the entropy of the qber 214 | if qber>0: 215 | H2=-qber*log2(qber) - (1-qber)*log2(1-qber) 216 | else: 217 | H2 = 0 218 | # estimate error correction efficiency from the CASCADE algorithm 219 | f_e = 1.16904371810274 + qber 220 | #security analysis - calculate skr in infinite key limit 221 | #See Chris Erven's PhD thesis or Xiongfeng Ma's paper 222 | #to understand where this equation comes from 223 | skr=real(twofolds*0.5*(1-(1+f_e)*H2)) 224 | return [qber, skr, twofolds] 225 | 226 | 227 | if __name__=='__main__': 228 | #Lets look at what happens to the secure key rate and 229 | #the quantum bit error rate as the loss gets worse. 230 | #Analogous to distance with fiber optic links. 231 | 232 | #define the fock space 233 | N = 7 234 | #define the squeezing paramter 235 | eps = 0.2 236 | #define the noise factor 237 | n_factor = 4.0e-5 238 | #define the length of the coincidence window (in s) 239 | coinc_window = 2.0e-9 240 | loss_db = arange(0,30) 241 | skr = zeros(30) 242 | qber = zeros(30) 243 | twofolds = zeros(30) 244 | 245 | #run calculation 246 | for i in range(30): 247 | exp_loss = 10.0**(-loss_db[i]/10.0); 248 | [qber[i], skr[i], twofolds[i]] = sim_qkd_entanglement(eps,exp_loss,exp_loss,n_factor,n_factor,N) 249 | skr = skr/coinc_window 250 | qber = qber*100 251 | 252 | #plot results 253 | fig = plt.figure() 254 | ax = fig.add_subplot(211) 255 | ax.plot(loss_db, skr,lw=2) 256 | ax.set_yscale('log') 257 | ax.set_ylabel('Secure Key Rate (bits/s)') 258 | ax.set_xlabel('Loss (dB)') 259 | ax = fig.add_subplot(212) 260 | ax.plot(loss_db, qber,lw=2) 261 | ax.set_ylabel('Quantum Bit Error Rate (%)') 262 | ax.set_ylim([0,15]) 263 | ax.set_xlabel('Loss (dB)') 264 | plt.show() 265 | 266 | -------------------------------------------------------------------------------- /guide/guide-correlation.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _correlation: 5 | 6 | ****************************** 7 | Two-time correlation functions 8 | ****************************** 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | In [1]: import numpy as np 16 | 17 | In [1]: from pylab import * 18 | 19 | 20 | With the QuTiP time-evolution functions (for example :func:`qutip.mesolve` and :func:`qutip.mcsolve`), a state vector or density matrix can be evolved from an initial state at :math:`t_0` to an arbitrary time :math:`t`, :math:`\rho(t)=V(t, t_0)\left\{\rho(t_0)\right\}`, where :math:`V(t, t_0)` is the propagator defined by the equation of motion. The resulting density matrix can then be used to evaluate the expectation values of arbitrary combinations of *same-time* operators. 21 | 22 | To calculate *two-time* correlation functions on the form :math:`\left`, we can use the quantum regression theorem (see, e.g., [Gar03]_) to write 23 | 24 | .. math:: 25 | 26 | \left = {\rm Tr}\left[A V(t+\tau, t)\left\{B\rho(t)\right\}\right] 27 | = {\rm Tr}\left[A V(t+\tau, t)\left\{BV(t, 0)\left\{\rho(0)\right\}\right\}\right] 28 | 29 | We therefore first calculate :math:`\rho(t)=V(t, 0)\left\{\rho(0)\right\}` using one of the QuTiP evolution solvers with :math:`\rho(0)` as initial state, and then again use the same solver to calculate :math:`V(t+\tau, t)\left\{B\rho(t)\right\}` using :math:`B\rho(t)` as initial state. 30 | 31 | Note that if the intial state is the steady state, then :math:`\rho(t)=V(t, 0)\left\{\rho_{\rm ss}\right\}=\rho_{\rm ss}` and 32 | 33 | .. math:: 34 | 35 | \left = {\rm Tr}\left[A V(t+\tau, t)\left\{B\rho_{\rm ss}\right\}\right] 36 | = {\rm Tr}\left[A V(\tau, 0)\left\{B\rho_{\rm ss}\right\}\right] = \left, 37 | 38 | which is independent of :math:`t`, so that we only have one time coordinate :math:`\tau`. 39 | 40 | QuTiP provides a family of functions that assists in the process of calculating two-time correlation functions. The available functions and their usage is show in the table below. Each of these functions can use one of the following evolution solvers: Master-equation, Exponential series and the Monte-Carlo. The choice of solver is defined by the optional argument ``solver``. 41 | 42 | .. cssclass:: table-striped 43 | 44 | +----------------------------------------------+--------------------------------------------------+ 45 | | QuTiP function | Correlation function | 46 | +==============================================+==================================================+ 47 | | :func:`qutip.correlation.correlation` or | :math:`\left` or | 48 | | :func:`qutip.correlation.correlation_2op_2t` | :math:`\left`. | 49 | +----------------------------------------------+--------------------------------------------------+ 50 | | :func:`qutip.correlation.correlation_ss` or | :math:`\left` or | 51 | | :func:`qutip.correlation.correlation_2op_1t` | :math:`\left`. | 52 | +----------------------------------------------+--------------------------------------------------+ 53 | | :func:`qutip.correlation.correlation_4op_1t` | :math:`\left`. | 54 | +----------------------------------------------+--------------------------------------------------+ 55 | | :func:`qutip.correlation.correlation_4op_2t` | :math:`\left`. | 56 | +----------------------------------------------+--------------------------------------------------+ 57 | 58 | The most common use-case is to calculate correlation functions of the kind :math:`\left`, in which case we use the correlation function solvers that start from the steady state, e.g., the :func:`qutip.correlation.correlation_2op_1t` function. These correlation function sovlers return a vector or matrix (in general complex) with the correlations as a function of the delays times. 59 | 60 | .. _correlation-steady: 61 | 62 | Steadystate correlation function 63 | ================================ 64 | 65 | The following code demonstrates how to calculate the :math:`\left` correlation for a leaky cavity with three different relaxation rates. 66 | 67 | .. ipython:: 68 | 69 | In [1]: times = np.linspace(0,10.0,200) 70 | 71 | In [1]: a = destroy(10) 72 | 73 | In [1]: x = a.dag() + a 74 | 75 | In [1]: H = a.dag() * a 76 | 77 | In [1]: corr1 = correlation_ss(H, times, [np.sqrt(0.5) * a], x, x) 78 | 79 | In [1]: corr2 = correlation_ss(H, times, [np.sqrt(1.0) * a], x, x) 80 | 81 | In [1]: corr3 = correlation_ss(H, times, [np.sqrt(2.0) * a], x, x) 82 | 83 | In [1]: figure() 84 | 85 | In [1]: plot(times, np.real(corr1), times, np.real(corr2), times, np.real(corr3)) 86 | 87 | In [1]: legend(['0.5','1.0','2.0']) 88 | 89 | In [1]: xlabel(r'Time $t$') 90 | 91 | In [1]: ylabel(r'Correlation $\left$') 92 | 93 | @savefig guide-correlation1.png width=5.0in align=center 94 | In [1]: show() 95 | 96 | 97 | Emission spectrum 98 | ================= 99 | 100 | Given a correlation function :math:`\left` we can define the corresponding power spectrum as 101 | 102 | .. math:: 103 | 104 | S(\omega) = \int_{-\infty}^{\infty} \left e^{-i\omega\tau} d\tau. 105 | 106 | In QuTiP, we can calculate :math:`S(\omega)` using either :func:`qutip.correlation.spectrum_ss`, which first calculates the correlation function using the :func:`qutip.essolve.essolve` solver and then performs the Fourier transform semi-analytically, or we can use the function :func:`qutip.correlation.spectrum_correlation_fft` to numerically calculate the Fourier transform of a given correlation data using FFT. 107 | 108 | The following example demonstrates how these two functions can be used to obtain the emission power spectrum. 109 | 110 | .. plot:: guide/scripts/spectrum_ex1.py 111 | :width: 4.0in 112 | :include-source: 113 | 114 | .. _correlation-spectrum: 115 | 116 | 117 | Non-steadystate correlation function 118 | ==================================== 119 | 120 | More generally, we can also calculate correlation functions of the kind :math:`\left`, i.e., the correlation function of a system that is not in its steadystate. In QuTiP, we can evoluate such correlation functions using the function :func:`qutip.correlation.correlation`. The default behavior of this function is to return a matrix with the correlations as a function of the two time coordinates (:math:`t_1` and :math:`t_2`). 121 | 122 | .. plot:: guide/scripts/correlation_ex2.py 123 | :width: 4.0in 124 | :include-source: 125 | 126 | However, in some cases we might be interested in the correlation functions on the form :math:`\left`, but only as a function of time coordinate :math:`t_2`. In this case we can also use the :func:`qutip.correlation.correlation` function, if we pass the density matrix at time :math:`t_1` as second argument, and `None` as third argument. The :func:`qutip.correlation.correlation` function then returns a vector with the correlation values corresponding to the times in `taulist` (the fourth argument). 127 | 128 | Example: first-order optical coherence function 129 | ----------------------------------------------- 130 | 131 | This example demonstrates how to calculate a correlation function on the form :math:`\left` for a non-steady initial state. Consider an oscillator that is interacting with a thermal environment. If the oscillator initially is in a coherent state, it will gradually decay to a thermal (incoherent) state. The amount of coherence can be quantified using the first-order optical coherence function :math:`g^{(1)}(\tau) = \frac{\left}{\sqrt{\left\left}}`. For a coherent state :math:`|g^{(1)}(\tau)| = 1`, and for a completely incoherent (thermal) state :math:`g^{(1)}(\tau) = 0`. The following code calculates and plots :math:`g^{(1)}(\tau)` as a function of :math:`\tau`. 132 | 133 | .. plot:: guide/scripts/correlation_ex3.py 134 | :width: 4.0in 135 | :include-source: 136 | 137 | For convenience, the steps for calculating the first-order coherence function have been collected in the function :func:`qutip.correlation.coherence_function_g1`. 138 | 139 | Example: second-order optical coherence function 140 | ------------------------------------------------ 141 | 142 | The second-order optical coherence function, with time-delay :math:`\tau`, is defined as 143 | 144 | .. math:: 145 | 146 | \displaystyle g^{(2)}(\tau) = \frac{\langle a^\dagger(0)a^\dagger(\tau)a(\tau)a(0)\rangle}{\langle a^\dagger(0)a(0)\rangle^2} 147 | 148 | For a coherent state :math:`g^{(2)}(\tau) = 1`, for a thermal state :math:`g^{(2)}(\tau=0) = 2` and it decreases as a function of time (bunched photons, they tend to appear together), and for a Fock state with :math:`n` photons :math:`g^{(2)}(\tau = 0) = n(n - 1)/n^2 < 1` and it increases with time (anti-bunched photons, more likely to arrive separated in time). 149 | 150 | To calculate this type of correlation function with QuTiP, we can use :func:`qutip.correlation.correlation_4op_1t`, which computes a correlation function on the form :math:`\left` (four operators, one delay-time vector). 151 | 152 | The following code calculates and plots :math:`g^{(2)}(\tau)` as a function of :math:`\tau` for a coherent, thermal and fock state. 153 | 154 | .. plot:: guide/scripts/correlation_ex4.py 155 | :width: 4.0in 156 | :include-source: 157 | 158 | For convenience, the steps for calculating the second-order coherence function have been collected in the function :func:`qutip.correlation.coherence_function_g2`. 159 | 160 | 161 | -------------------------------------------------------------------------------- /guide/guide-tensor.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _tensor: 5 | 6 | ****************************************** 7 | Using Tensor Products and Partial Traces 8 | ****************************************** 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | 16 | .. _tensor-products: 17 | 18 | Tensor products 19 | =============== 20 | 21 | To describe the states of multipartite quantum systems - such as two coupled qubits, a qubit coupled to an oscillator, etc. - we need to expand the Hilbert space by taking the tensor product of the state vectors for each of the system components. Similarly, the operators acting on the state vectors in the combined Hilbert space (describing the coupled system) are formed by taking the tensor product of the individual operators. 22 | 23 | In QuTiP the function :func:`qutip.tensor.tensor` is used to accomplish this task. This function takes as argument a collection:: 24 | 25 | >>> tensor(op1, op2, op3) 26 | 27 | or a ``list``:: 28 | 29 | >>> tensor([op1, op2, op3]) 30 | 31 | of state vectors *or* operators and returns a composite quantum object for the combined Hilbert space. The function accepts an arbitray number of states or operators as argument. The type returned quantum object is the same as that of the input(s). 32 | 33 | For example, the state vector describing two qubits in their ground states is formed by taking the tensor product of the two single-qubit ground state vectors: 34 | 35 | .. ipython:: 36 | 37 | In [1]: tensor(basis(2, 0), basis(2, 0)) 38 | 39 | 40 | or equivalently using the ``list`` format: 41 | 42 | .. ipython:: 43 | 44 | In [1]: tensor([basis(2, 0), basis(2, 0)]) 45 | 46 | This is straightforward to generalize to more qubits by adding more component state vectors in the argument list to the :func:`qutip.tensor.tensor` function, as illustrated in the following example: 47 | 48 | .. ipython:: 49 | 50 | In [1]: tensor((basis(2, 0) + basis(2, 1)).unit(), 51 | ...: (basis(2, 0) + basis(2, 1)).unit(), basis(2, 0)) 52 | 53 | 54 | This state is slightly more complicated, describing two qubits in a superposition between the up and down states, while the third qubit is in its ground state. 55 | 56 | To construct operators that act on an extended Hilbert space of a combined system, we similarly pass a list of operators for each component system to the :func:`qutip.tensor.tensor` function. For example, to form the operator that represents the simultaneous action of the :math:`\sigma_x` operator on two qubits: 57 | 58 | .. ipython:: 59 | 60 | In [1]: tensor(sigmax(), sigmax()) 61 | 62 | To create operators in a combined Hilbert space that only act only on a single component, we take the tensor product of the operator acting on the subspace of interest, with the identity operators corresponding to the components that are to be unchanged. For example, the operator that represents :math:`\sigma_z` on the first qubit in a two-qubit system, while leaving the second qubit unaffected: 63 | 64 | .. ipython:: 65 | 66 | In [1]: tensor(sigmaz(), identity(2)) 67 | 68 | 69 | .. _tensor-product-example: 70 | 71 | Example: Constructing composite Hamiltonians 72 | ============================================ 73 | 74 | The :func:`qutip.tensor.tensor` function is extensively used when constructing Hamiltonians for composite systems. Here we'll look at some simple examples. 75 | 76 | .. _tensor-product-example-2qubits: 77 | 78 | Two coupled qubits 79 | ------------------ 80 | 81 | First, let's consider a system of two coupled qubits. Assume that both qubit has equal energy splitting, and that the qubits are coupled through a :math:`\sigma_x\otimes\sigma_x` interaction with strength g = 0.05 (in units where the bare qubit energy splitting is unity). The Hamiltonian describing this system is: 82 | 83 | .. ipython:: 84 | 85 | In [1]: H = tensor(sigmaz(), identity(2)) + tensor(identity(2), 86 | ...: sigmaz()) + 0.05 * tensor(sigmax(), sigmax()) 87 | 88 | In [2]: H 89 | 90 | .. _tensor-product-example-3qubits: 91 | 92 | Three coupled qubits 93 | -------------------- 94 | 95 | The two-qubit example is easily generalized to three coupled qubits: 96 | 97 | .. ipython:: 98 | 99 | In [1]: H = (tensor(sigmaz(), identity(2), identity(2)) + 100 | ...: tensor(identity(2), sigmaz(), identity(2)) + 101 | ...: tensor(identity(2), identity(2), sigmaz()) + 102 | ...: 0.5 * tensor(sigmax(), sigmax(), identity(2)) + 103 | ...: 0.25 * tensor(identity(2), sigmax(), sigmax())) 104 | 105 | In [2]: H 106 | 107 | 108 | .. _tensor-product-example-jcmodel: 109 | 110 | A two-level system coupled to a cavity: The Jaynes-Cummings model 111 | ------------------------------------------------------------------- 112 | 113 | The simplest possible quantum mechanical description for light-matter interaction is encapsulated in the Jaynes-Cummings model, which describes the coupling between a two-level atom and a single-mode electromagnetic field (a cavity mode). Denoting the energy splitting of the atom and cavity ``omega_a`` and ``omega_c``, respectively, and the atom-cavity interaction strength ``g``, the Jaynes-Cumming Hamiltonian can be constructed as: 114 | 115 | .. ipython:: 116 | 117 | In [1]: N = 10 118 | 119 | In [1]: omega_a = 1.0 120 | 121 | In [1]: omega_c = 1.25 122 | 123 | In [1]: g = 0.05 124 | 125 | In [1]: a = tensor(identity(2), destroy(N)) 126 | 127 | In [1]: sm = tensor(destroy(2), identity(N)) 128 | 129 | In [1]: sz = tensor(sigmaz(), identity(N)) 130 | 131 | In [1]: H = 0.5 * omega_a * sz + omega_c * a.dag() * a + g * (a.dag() * sm + a * sm.dag()) 132 | 133 | 134 | Here ``N`` is the number of Fock states included in the cavity mode. 135 | 136 | .. _tensor-ptrace: 137 | 138 | Partial trace 139 | ============= 140 | 141 | The partial trace is an operation that reduces the dimension of a Hilbert space by eliminating some degrees of freedom by averaging (tracing). In this sense it is therefore the converse of the tensor product. It is useful when one is interested in only a part of a coupled quantum system. For open quantum systems, this typically involves tracing over the environment leaving only the system of interest. In QuTiP the class method :func:`qutip.Qobj.ptrace` is used to take partial traces. :func:`qutip.Qobj.ptrace` acts on the :class:`qutip.Qobj` instance for which it is called, and it takes one argument ``sel``, which is a ``list`` of integers that mark the component systems that should be **kept**. All other components are traced out. 142 | 143 | For example, the density matrix describing a single qubit obtained from a coupled two-qubit system is obtained via: 144 | 145 | .. ipython:: 146 | 147 | In [1]: psi = tensor(basis(2, 0), basis(2, 1)) 148 | 149 | In [2]: psi.ptrace(0) 150 | 151 | In [3]: psi.ptrace(1) 152 | 153 | Note that the partial trace always results in a density matrix (mixed state), regardless of whether the composite system is a pure state (described by a state vector) or a mixed state (described by a density matrix): 154 | 155 | .. ipython:: 156 | 157 | In [1]: psi = tensor((basis(2, 0) + basis(2, 1)).unit(), basis(2, 0)) 158 | 159 | In [2]: psi 160 | 161 | In [3]: psi.ptrace(0) 162 | 163 | In [4]: rho = tensor(ket2dm((basis(2, 0) + basis(2, 1)).unit()), fock_dm(2, 0)) 164 | 165 | In [5]: rho 166 | 167 | In [6]: rho.ptrace(0) 168 | 169 | Superoperators and Tensor Manipulations 170 | ======================================= 171 | 172 | As described in :ref:`states-super`, *superoperators* are operators 173 | that act on Liouville space, the vectorspace of linear operators. 174 | Superoperators can be represented 175 | using the isomorphism 176 | :math:`\mathrm{vec} : \mathcal{L}(\mathcal{H}) \to \mathcal{H} \otimes \mathcal{H}` [Hav03]_, [Wat13]_. 177 | To represent superoperators acting on :math:`\mathcal{L}(\mathcal{H}_1 \otimes \mathcal{H}_2)` thus takes some tensor rearrangement to get the desired ordering 178 | :math:`\mathcal{H}_1 \otimes \mathcal{H}_2 \otimes \mathcal{H}_1 \otimes \mathcal{H}_2`. 179 | 180 | In particular, this means that :func:`qutip.tensor` does not act as 181 | one might expect on the results of :func:`qutip.to_super`: 182 | 183 | .. ipython:: 184 | 185 | In [1]: A = qeye([2]) 186 | 187 | In [2]: B = qeye([3]) 188 | 189 | 190 | In [3]: to_super(tensor(A, B)).dims 191 | Out[3]: [[[2, 3], [2, 3]], [[2, 3], [2, 3]]] 192 | 193 | In [4]: tensor(to_super(A), to_super(B)).dims 194 | Out[4]: [[[2], [2], [3], [3]], [[2], [2], [3], [3]]] 195 | 196 | In the former case, the result correctly has four copies 197 | of the compound index with dims ``[2, 3]``. In the latter 198 | case, however, each of the Hilbert space indices is listed 199 | independently and in the wrong order. 200 | 201 | The :func:`qutip.super_tensor` function performs the needed 202 | rearrangement, providing the most direct analog to :func:`qutip.tensor` on 203 | the underlying Hilbert space. In particular, for any two ``type="oper"`` 204 | Qobjs ``A`` and ``B``, ``to_super(tensor(A, B)) == super_tensor(to_super(A), to_super(B))`` and 205 | ``operator_to_vector(tensor(A, B)) == super_tensor(operator_to_vector(A), operator_to_vector(B))``. Returning to the previous example: 206 | 207 | .. ipython:: 208 | 209 | In [5]: super_tensor(to_super(A), to_super(B)).dims 210 | Out[5]: [[[2, 3], [2, 3]], [[2, 3], [2, 3]]] 211 | 212 | The :func:`qutip.composite` function automatically switches between 213 | :func:`qutip.tensor` and :func:`qutip.super_tensor` based on the ``type`` 214 | of its arguments, such that ``composite(A, B)`` returns an appropriate Qobj to 215 | represent the composition of two systems. 216 | 217 | .. ipython:: 218 | 219 | In [6]: composite(A, B).dims 220 | Out[6]: [[2, 3], [2, 3]] 221 | 222 | In [7]: composite(to_super(A), to_super(B)).dims 223 | Out[7]: [[[2, 3], [2, 3]], [[2, 3], [2, 3]]] 224 | 225 | QuTiP also allows more general tensor manipulations that are 226 | useful for converting between superoperator representations [WBC11]_. 227 | In particular, the :func:`tensor_contract` function allows for 228 | contracting one or more pairs of indices. As detailed in 229 | the `channel contraction tutorial`_, this can be used to find 230 | superoperators that represent partial trace maps. 231 | Using this functionality, we can construct some quite exotic maps, 232 | such as a map from :math:`3 \times 3` operators to :math:`2 \times 2` 233 | operators: 234 | 235 | .. ipython:: 236 | 237 | In [8]: tensor_contract(composite(to_super(A), to_super(B)), (1, 3), (4, 6)).dims 238 | Out[8]: [[[2], [2]], [[3], [3]]] 239 | 240 | 241 | 242 | .. _channel contraction tutorial: http://nbviewer.ipython.org/github/qutip/qutip-notebooks/blob/master/examples/example-superop-contract.ipynb 243 | -------------------------------------------------------------------------------- /conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # QuTiP documentation build configuration file, created by 4 | # sphinx-quickstart on Tue Oct 25 14:08:15 2011. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | sys.path.append(os.path.abspath('_sphinxext')) 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | needs_sphinx = '1.2' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = ['sphinx.ext.mathjax', 29 | 'IPython.sphinxext.ipython_console_highlighting', 30 | 'IPython.sphinxext.ipython_directive', 31 | 'matplotlib.sphinxext.only_directives', 32 | 'matplotlib.sphinxext.plot_directive', 33 | 'sphinx.ext.autodoc', 34 | 'sphinx.ext.todo', 35 | 'sphinx.ext.doctest', 36 | 'sphinx.ext.autosummary', 37 | 'numpydoc', 38 | 'sphinx.ext.extlinks', 39 | 'sphinx.ext.viewcode', 40 | 'sphinx.ext.ifconfig', 41 | ] 42 | 43 | 44 | # Add any paths that contain templates here, relative to this directory. 45 | templates_path = ['_templates'] 46 | 47 | # The suffix of source filenames. 48 | source_suffix = '.rst' 49 | 50 | # The encoding of source files. 51 | #source_encoding = 'utf-8-sig' 52 | 53 | # The master toctree document. 54 | master_doc = 'index' 55 | 56 | # General information about the project. 57 | project = u'QuTiP: Quantum Toolbox in Python' 58 | copyright = u'2011 and later, P.D. Nation, J.R. Johansson' 59 | 60 | # The version info for the project you're documenting, acts as replacement for 61 | # |version| and |release|, also used in various other places throughout the 62 | # built documents. 63 | # 64 | # The short X.Y version. 65 | version = '3.1.0' 66 | # The full version, including alpha/beta/rc tags. 67 | release = '3.1.0' 68 | 69 | # The language for content autogenerated by Sphinx. Refer to documentation 70 | # for a list of supported languages. 71 | #language = None 72 | 73 | # There are two options for replacing |today|: either, you set today to some 74 | # non-false value, then it is used: 75 | #today = '' 76 | # Else, today_fmt is used as the format for a strftime call. 77 | #today_fmt = '%B %d, %Y' 78 | 79 | # List of patterns, relative to source directory, that match files and 80 | # directories to ignore when looking for source files. 81 | exclude_patterns = ['_build'] 82 | 83 | # The reST default role (used for this markup: `text`) to use for all documents. 84 | #default_role = None 85 | 86 | # If true, '()' will be appended to :func: etc. cross-reference text. 87 | add_function_parentheses = False 88 | 89 | # If true, the current module name will be prepended to all description 90 | # unit titles (such as .. function::). 91 | add_module_names = False 92 | 93 | # If true, sectionauthor and moduleauthor directives will be shown in the 94 | # output. They are ignored by default. 95 | show_authors = True 96 | 97 | # The name of the Pygments (syntax highlighting) style to use. 98 | pygments_style = 'sphinx' 99 | 100 | # A list of ignored prefixes for module index sorting. 101 | #modindex_common_prefix = [] 102 | todo_include_todos = True 103 | 104 | # -- Options for HTML output --------------------------------------------------- 105 | 106 | # The theme to use for HTML and HTML Help pages. See the documentation for 107 | # a list of builtin themes. 108 | html_theme = 'bootstrap' 109 | full_logo= True 110 | html_theme_options = { 111 | 'navbar_title': "QuTiP", 112 | 113 | # Tab name for entire site. (Default: "Site") 114 | 'navbar_site_name': "Docs", 115 | 116 | # A list of tuples containing pages or urls to link to. 117 | # Valid tuples should be in the following forms: 118 | # (name, page) # a link to a page 119 | # (name, "/aa/bb", 1) # a link to an arbitrary relative url 120 | # (name, "http://example.com", True) # arbitrary absolute url 121 | # Note the "1" or "True" value above as the third argument to indicate 122 | # an arbitrary url. 123 | 'navbar_links': [ 124 | ("qutip.org", "http://qutip.org", True), 125 | ], 126 | 127 | # Global TOC depth for "site" navbar tab. (Default: 1) 128 | # Switching to -1 shows all levels. 129 | 'globaltoc_depth': 2, 130 | 131 | # Include hidden TOCs in Site navbar? 132 | # 133 | # Note: If this is "false", you cannot have mixed ``:hidden:`` and 134 | # non-hidden ``toctree`` directives in the same page, or else the build 135 | # will break. 136 | # 137 | # Values: "true" (default) or "false" 138 | 'globaltoc_includehidden': "true", 139 | 140 | # HTML navbar class (Default: "navbar") to attach to
    element. 141 | # For black navbar, do "navbar navbar-inverse" 142 | 'navbar_class': "navbar", 143 | 144 | # Fix navigation bar to top of page? 145 | # Values: "true" (default) or "false" 146 | 'navbar_fixed_top': "true", 147 | 148 | # Location of link to source. 149 | # Options are "nav" (default), "footer" or anything else to exclude. 150 | 'source_link_position': "nav", 151 | 'bootswatch_theme': "flatly", 152 | 'bootstrap_version': "3", 153 | } 154 | 155 | # Theme options are theme-specific and customize the look and feel of a theme 156 | # further. For a list of options available for each theme, see the 157 | # documentation. 158 | # Add any paths that contain custom themes here, relative to this directory. 159 | html_theme_path = ['_themes'] 160 | 161 | # The name for this set of Sphinx documents. If None, it defaults to 162 | # " v documentation". 163 | html_title = 'QuTiP 3.1.0 Documentation' 164 | 165 | # A shorter title for the navigation bar. Default is the same as html_title. 166 | html_short_title = u'QuTiP' 167 | 168 | # The name of an image file (relative to this directory) to place at the top 169 | # of the sidebar. 170 | #html_logo = '_static/logo.png' 171 | 172 | # The name of an image file (within the static path) to use as favicon of the 173 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 174 | # pixels large. 175 | html_favicon = 'figures/favicon.ico' 176 | 177 | # Add any paths that contain custom static files (such as style sheets) here, 178 | # relative to this directory. They are copied after the builtin static files, 179 | # so a file named "default.css" will overwrite the builtin "default.css". 180 | html_static_path = ['_static'] 181 | 182 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 183 | # using the given strftime format. 184 | html_last_updated_fmt = '%b %d, %Y' 185 | 186 | # If true, SmartyPants will be used to convert quotes and dashes to 187 | # typographically correct entities. 188 | #html_use_smartypants = True 189 | 190 | # Custom sidebar templates, maps document names to template names. 191 | html_sidebars = {'sidebar': ['localtoc.html', 'sourcelink.html', 'searchbox.html']} 192 | 193 | # Additional templates that should be rendered to pages, maps page names to 194 | # template names. 195 | #html_additional_pages = {} 196 | 197 | # If false, no module index is generated. 198 | #html_domain_indices = True 199 | 200 | # If false, no index is generated. 201 | #html_use_index = True 202 | 203 | # If true, the index is split into individual pages for each letter. 204 | #html_split_index = False 205 | 206 | # If true, links to the reST sources are added to the pages. 207 | html_show_sourcelink = False 208 | 209 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 210 | html_show_sphinx = True 211 | 212 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 213 | html_show_copyright = True 214 | 215 | # If true, an OpenSearch description file will be output, and all pages will 216 | # contain a tag referring to it. The value of this option must be the 217 | # base URL from which the finished HTML is served. 218 | #html_use_opensearch = '' 219 | 220 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 221 | #html_file_suffix = None 222 | 223 | # Output file base name for HTML help builder. 224 | htmlhelp_basename = 'QuTiPdoc' 225 | 226 | 227 | # -- Options for LaTeX output -------------------------------------------------- 228 | 229 | latex_header = open('latex_output_files/latex_preamble.tex', 'r+') 230 | PREAMBLE = latex_header.read(); 231 | 232 | 233 | latex_elements = { 234 | 'papersize':'a4paper', 235 | 'pointsize':'10pt', 236 | 'classoptions': '', 237 | 'babel': '\\usepackage[english]{babel}', 238 | 'preamble': PREAMBLE 239 | } 240 | 241 | # Grouping the document tree into LaTeX files. List of tuples 242 | # (source start file, target name, title, author, documentclass [howto/manual]). 243 | latex_documents = [ 244 | ('index', 'qutip.tex', u'QuTiP: Quantum Toolbox in Python', 245 | u'P.D. Nation and J.R. Johansson', 'memoir'), 246 | ] 247 | 248 | # The name of an image file (relative to this directory) to place at the top of 249 | # the title page. 250 | latex_logo = 'figures/logo.png' 251 | 252 | # For "manual" documents, if this is true, then toplevel headings are parts, 253 | # not chapters. 254 | #latex_use_parts = True 255 | 256 | # If true, show page references after internal links. 257 | #latex_show_pagerefs = False 258 | 259 | # If true, show URL addresses after external links. 260 | #latex_show_urls = False 261 | 262 | # Documents to append as an appendix to all manuals. 263 | #latex_appendices = [] 264 | 265 | # If false, no module index is generated. 266 | #latex_domain_indices = True 267 | 268 | 269 | # -- Options for manual page output -------------------------------------------- 270 | 271 | # One entry per manual page. List of tuples 272 | # (source start file, name, description, authors, manual section). 273 | man_pages = [ 274 | ('index', 'qutip', u'QuTiP: Quantum Toolbox in Python', 275 | [u'P.D. Nation and J.R. Johansson'], 1) 276 | ] 277 | 278 | # If true, show URL addresses after external links. 279 | #man_show_urls = False 280 | 281 | 282 | # -- Options for Texinfo output ------------------------------------------------ 283 | 284 | # Grouping the document tree into Texinfo files. List of tuples 285 | # (source start file, target name, title, author, 286 | # dir menu entry, description, category) 287 | texinfo_documents = [ 288 | ('index', 'qutip', u'QuTiP: Quantum Toolbox in Python', u'P.D. Nation and J.R. Johansson', 289 | 'QuTiP', 'Quantum Toolbox in Python', 'Miscellaneous'), 290 | ] 291 | 292 | # Documents to append as an appendix to all manuals. 293 | #texinfo_appendices = [] 294 | 295 | # If false, no module index is generated. 296 | #texinfo_domain_indices = True 297 | 298 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 299 | #texinfo_show_urls = 'footnote' 300 | 301 | 302 | autodoc_member_order = 'alphabetical' 303 | 304 | ## EXTLINKS CONFIGURATION ###################################################### 305 | 306 | extlinks = { 307 | 'arxiv': ('http://arxiv.org/abs/%s', 'arXiv:'), 308 | 'doi': ('http://dx.doi.org/%s', 'doi:'), 309 | } 310 | 311 | -------------------------------------------------------------------------------- /contrib/qpt.py: -------------------------------------------------------------------------------- 1 | #This file is part of QuTIP. 2 | # 3 | # QuTIP is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # QuTIP is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with QuTIP. If not, see . 15 | # 16 | # Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 17 | # 18 | ########################################################################### 19 | 20 | from qutip.tensor import tensor 21 | from qutip.superoperator import spre, spost, mat2vec, vec2mat 22 | from qutip.Qobj import Qobj 23 | from numpy import hstack 24 | import scipy.linalg as la 25 | 26 | from pylab import * 27 | 28 | def index_permutations(size_list, perm=[]): 29 | """ 30 | Generate a list with all index permutations. size_list is a list that 31 | contains the sizes for each composite system. 32 | """ 33 | if len(size_list) == 0: 34 | yield perm 35 | else: 36 | for n in range(size_list[0]): 37 | for ip in index_permutations(size_list[1:], perm + [n]): 38 | yield ip 39 | 40 | def qpt_plot(chi, lbls_list, title=None, fig=None): 41 | """ 42 | Visualize the quantum process tomography chi matrix. Plot the real and 43 | imaginary parts separately. 44 | """ 45 | if fig == None: 46 | fig = figure(figsize=(16,8)) 47 | 48 | xlabels = [] 49 | for inds in index_permutations([len(lbls) for lbls in lbls_list]): 50 | xlabels.append("".join([lbls_list[k][inds[k]] for k in range(len(lbls_list))])) 51 | 52 | ax = fig.add_subplot(1,2,1, projection='3d', position=[0, 0, 1, 1]) 53 | matrix_histogram(real(chi), xlabels, xlabels, r"real($\chi$)", [-1,1], ax) 54 | 55 | ax = fig.add_subplot(1,2,2, projection='3d', position=[0, 0, 1, 1]) 56 | matrix_histogram(imag(chi), xlabels, xlabels, r"imag($\chi$)", [-1,1], ax) 57 | 58 | if title: 59 | fig.suptitle(title) 60 | 61 | def qpt_plot_combined(chi, lbls_list, title=None, fig=None): 62 | """ 63 | Visualize the quantum process tomography chi matrix. Plot bars with 64 | height that correspond to the absolute value and color that correspond 65 | to the phase. 66 | """ 67 | if fig == None: 68 | fig = figure(figsize=(8,6)) 69 | 70 | xlabels = [] 71 | for inds in index_permutations([len(lbls) for lbls in lbls_list]): 72 | xlabels.append("".join([lbls_list[k][inds[k]] for k in range(len(lbls_list))])) 73 | 74 | if not title: 75 | title = r"$\chi$" 76 | 77 | ax = fig.add_subplot(1,1,1, projection='3d', position=[0, 0, 1, 1]) 78 | 79 | matrix_histogram_complex(chi, xlabels, xlabels, title, None, ax) 80 | 81 | def qpt(U, op_basis_list): 82 | """ 83 | Calculate the quantum process tomography chi matrix for a given 84 | (possibly nonunitary) transformation matrix U, which transforms a 85 | density matrix in vector form according to: 86 | 87 | vec(rho) = U * vec(rho0) 88 | 89 | or 90 | 91 | rho = vec2mat(U * mat2vec(rho0)) 92 | 93 | U can be calculated for an open quantum system using the QuTiP propagator 94 | function. 95 | """ 96 | 97 | E_ops = [] 98 | # loop over all index permutations 99 | for inds in index_permutations([len(op_list) for op_list in op_basis_list]): 100 | # loop over all composite systems 101 | E_op_list = [op_basis_list[k][inds[k]] for k in range(len(op_basis_list))] 102 | E_ops.append(tensor(E_op_list)) 103 | 104 | EE_ops = [spre(E1) * spost(E2.dag()) for E1 in E_ops for E2 in E_ops] 105 | 106 | M = hstack([mat2vec(EE.full()) for EE in EE_ops]) 107 | 108 | Uvec = mat2vec(U.full()) 109 | 110 | chi_vec = la.solve(M, Uvec) 111 | 112 | return vec2mat(chi_vec) 113 | 114 | def matrix_histogram(M, xlabels, ylabels, title, limits=None, ax=None): 115 | """ 116 | Draw a histogram for the matrix M, with the given x and y labels and title. 117 | 118 | Parameters 119 | ---------- 120 | M : Matrix of Qobj 121 | The matrix to visualize 122 | 123 | xlabels : list of strings 124 | list of x labels 125 | 126 | ylabels : list of strings 127 | list of y labels 128 | 129 | title : string 130 | title of the plot 131 | 132 | limits : list/array with two float numbers 133 | The z-axis limits [min, max] (optional) 134 | 135 | ax : a matplotlib axes instance 136 | The axes context in which the plot will be drawn. 137 | 138 | Returns 139 | ------- 140 | 141 | An matplotlib axes instance for the plot. 142 | 143 | Raises 144 | ------ 145 | ValueError 146 | Input argument is not valid. 147 | 148 | """ 149 | 150 | if isinstance(M, Qobj): 151 | # extract matrix data from Qobj 152 | M = M.full() 153 | 154 | n=size(M) 155 | xpos,ypos=meshgrid(range(M.shape[0]),range(M.shape[1])) 156 | xpos=xpos.T.flatten()-0.5 157 | ypos=ypos.T.flatten()-0.5 158 | zpos = zeros(n) 159 | dx = dy = 0.8 * ones(n) 160 | dz = real(M.flatten()) 161 | 162 | if limits: # check that limits is a list type 163 | z_min = limits[0] 164 | z_max = limits[1] 165 | else: 166 | z_min = min(dz) 167 | z_max = max(dz) 168 | 169 | norm=mpl.colors.Normalize(z_min, z_max) 170 | cmap=get_cmap('jet') # Spectral 171 | colors=cmap(norm(dz)) 172 | 173 | if ax == None: 174 | fig = plt.figure() 175 | ax = Axes3D(fig, azim=-35, elev=35) 176 | 177 | ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors) 178 | plt.title(title) 179 | 180 | # x axis 181 | ax.axes.w_xaxis.set_major_locator(IndexLocator(1,-0.5)) 182 | ax.set_xticklabels(xlabels) 183 | ax.tick_params(axis='x', labelsize=14) 184 | 185 | # y axis 186 | ax.axes.w_yaxis.set_major_locator(IndexLocator(1,-0.5)) 187 | ax.set_yticklabels(ylabels) 188 | ax.tick_params(axis='y', labelsize=14) 189 | 190 | # z axis 191 | ax.axes.w_zaxis.set_major_locator(IndexLocator(1,0.5)) 192 | ax.set_zlim3d([z_min, z_max]) 193 | 194 | # color axis 195 | cax, kw = mpl.colorbar.make_axes(ax, shrink=.75, pad=.0) 196 | cb1 = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm) 197 | 198 | return ax 199 | 200 | def matrix_histogram_complex(M, xlabels, ylabels, title, limits=None, ax=None): 201 | """ 202 | Draw a histogram for the amplitudes of matrix M, using the argument of each element 203 | for coloring the bars, with the given x and y labels and title. 204 | 205 | Parameters 206 | ---------- 207 | M : Matrix of Qobj 208 | The matrix to visualize 209 | 210 | xlabels : list of strings 211 | list of x labels 212 | 213 | ylabels : list of strings 214 | list of y labels 215 | 216 | title : string 217 | title of the plot 218 | 219 | limits : list/array with two float numbers 220 | The z-axis limits [min, max] (optional) 221 | 222 | ax : a matplotlib axes instance 223 | The axes context in which the plot will be drawn. 224 | 225 | Returns 226 | ------- 227 | 228 | An matplotlib axes instance for the plot. 229 | 230 | Raises 231 | ------ 232 | ValueError 233 | Input argument is not valid. 234 | 235 | """ 236 | 237 | if isinstance(M, Qobj): 238 | # extract matrix data from Qobj 239 | M = M.full() 240 | 241 | n=size(M) 242 | xpos,ypos=meshgrid(range(M.shape[0]),range(M.shape[1])) 243 | xpos=xpos.T.flatten()-0.5 244 | ypos=ypos.T.flatten()-0.5 245 | zpos = zeros(n) 246 | dx = dy = 0.8 * ones(n) 247 | Mvec = M.flatten() 248 | dz = abs(Mvec) 249 | 250 | # make small numbers real, to avoid random colors 251 | idx, = where(abs(Mvec) < 0.001) 252 | Mvec[idx] = abs(Mvec[idx]) 253 | 254 | if limits: # check that limits is a list type 255 | phase_min = limits[0] 256 | phase_max = limits[1] 257 | else: 258 | phase_min = -pi 259 | phase_max = pi 260 | 261 | norm=mpl.colors.Normalize(phase_min, phase_max) 262 | 263 | # create a cyclic colormap 264 | cdict = {'blue': ((0.00, 0.0, 0.0), 265 | (0.25, 0.0, 0.0), 266 | (0.50, 1.0, 1.0), 267 | (0.75, 1.0, 1.0), 268 | (1.00, 0.0, 0.0)), 269 | 'green': ((0.00, 0.0, 0.0), 270 | (0.25, 1.0, 1.0), 271 | (0.50, 0.0, 0.0), 272 | (0.75, 1.0, 1.0), 273 | (1.00, 0.0, 0.0)), 274 | 'red': ((0.00, 1.0, 1.0), 275 | (0.25, 0.5, 0.5), 276 | (0.50, 0.0, 0.0), 277 | (0.75, 0.0, 0.0), 278 | (1.00, 1.0, 1.0))} 279 | cmap = matplotlib.colors.LinearSegmentedColormap('phase_colormap', cdict, 256) 280 | 281 | colors = cmap(norm(angle(Mvec))) 282 | 283 | if ax == None: 284 | fig = plt.figure() 285 | ax = Axes3D(fig, azim=-35, elev=35) 286 | 287 | ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors) 288 | plt.title(title) 289 | 290 | # x axis 291 | ax.axes.w_xaxis.set_major_locator(IndexLocator(1,-0.5)) 292 | ax.set_xticklabels(xlabels) 293 | ax.tick_params(axis='x', labelsize=12) 294 | 295 | # y axis 296 | ax.axes.w_yaxis.set_major_locator(IndexLocator(1,-0.5)) 297 | ax.set_yticklabels(ylabels) 298 | ax.tick_params(axis='y', labelsize=12) 299 | 300 | # z axis 301 | #ax.axes.w_zaxis.set_major_locator(IndexLocator(1,0.5)) 302 | ax.set_zlim3d([0, 1]) 303 | #ax.set_zlabel('abs') 304 | 305 | # color axis 306 | cax, kw = mpl.colorbar.make_axes(ax, shrink=.75, pad=.0) 307 | cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm) 308 | cb.set_ticks([-pi, -pi/2, 0, pi/2, pi]) 309 | cb.set_ticklabels((r'$-\pi$',r'$-\pi/2$',r'$0$',r'$\pi/2$',r'$\pi$')) 310 | cb.set_label('arg') 311 | 312 | return ax 313 | 314 | def iswap(): 315 | """Quantum object representing the iSWAP gate. 316 | 317 | Returns 318 | ------- 319 | iswap_gate : qobj 320 | Quantum object representation of iSWAP gate 321 | 322 | Examples 323 | -------- 324 | >>> iswap() 325 | Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = False 326 | Qobj data = 327 | [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] 328 | [ 0.+0.j 0.+0.j 0.+1.j 0.+0.j] 329 | [ 0.+0.j 0.+1.j 0.+0.j 0.+0.j] 330 | [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j]] 331 | """ 332 | return Qobj(array([[1,0,0,0], [0,0,1j,0], [0,1j,0,0], [0,0,0,1]]), dims=[[2, 2], [2, 2]]) 333 | 334 | 335 | def sqrtiswap(): 336 | """Quantum object representing the square root iSWAP gate. 337 | 338 | Returns 339 | ------- 340 | sqrtiswap_gate : qobj 341 | Quantum object representation of square root iSWAP gate 342 | 343 | Examples 344 | -------- 345 | >>> sqrtiswap() 346 | Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = False 347 | Qobj data = 348 | [[ 1.00000000+0.j 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j] 349 | [ 0.00000000+0.j 0.70710678+0.j 0.00000000-0.70710678j 0.00000000+0.j] 350 | [ 0.00000000+0.j 0.00000000-0.70710678j 0.70710678+0.j 0.00000000+0.j] 351 | [ 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j 1.00000000+0.j]] 352 | """ 353 | return Qobj(array([[1,0,0,0], [0, 1/sqrt(2), -1j/sqrt(2), 0], [0, -1j/sqrt(2), 1/sqrt(2), 0], [0, 0, 0, 1]]), dims=[[2, 2], [2, 2]]) 354 | -------------------------------------------------------------------------------- /guide/guide-steady.rst: -------------------------------------------------------------------------------- 1 | .. QuTiP 2 | Copyright (C) 2011-2012, Paul D. Nation & Robert J. Johansson 3 | 4 | .. _steady: 5 | 6 | ************************************* 7 | Solving for Steady-State Solutions 8 | ************************************* 9 | 10 | .. ipython:: 11 | :suppress: 12 | 13 | In [1]: from qutip import * 14 | 15 | In [1]: import numpy as np 16 | 17 | In [1]: from pylab import * 18 | 19 | .. _steady-intro: 20 | 21 | Introduction 22 | ============ 23 | 24 | For time-independent open quantum systems with decay rates larger than the corresponding excitation rates, the system will tend toward a steady state as :math:`t\rightarrow\infty` that satisfies the equation 25 | 26 | .. math:: 27 | \frac{d\hat{\rho}_{ss}}{dt}=\mathcal{L}\hat{\rho}_{ss}=0. 28 | 29 | Although the requirement for time-independence seems quite resitrictive, one can often employ a transformation to the interaction picture that yields a time-independent Hamiltonian. For many these systems, solving for the asymptotic density matrix :math:`\hat{\rho}_{ss}` can be achieved using direct or iterative solution methods faster than using master equation or Monte Carlo simulations. Although the steady state equation has a simple mathematical form, the properties of the Liouvillian operator are such that the solutions to this equation are anything but straightforward to find. 30 | 31 | Steady State Solutions for Arbitrary Systems 32 | ============================================ 33 | 34 | 35 | Steady State solvers in QuTiP 36 | ============================= 37 | In QuTiP, the steady-state solution for a system Hamiltonian or Liouvillian is given by :func:`qutip.steadystate.steadystate`. This function implements a number of different methods for finding the steady state, each with their own pros and cons, where the method used can be chosen using the ``method`` keyword argument. 38 | 39 | Available Steady-State Methods: 40 | 41 | .. cssclass:: table-striped 42 | 43 | .. list-table:: 44 | :widths: 10 15 30 45 | :header-rows: 1 46 | 47 | * - Method 48 | - Keyword 49 | - Description 50 | * - Direct (default) 51 | - 'direct' 52 | - Direct solution solving :math:`Ax=b` via sparse LU decomposition. 53 | * - Eigenvalue 54 | - 'eigen' 55 | - Iteratively find the eigenvector corresponding to the zero eigenvalue of :math:`\mathcal{L}`. 56 | * - Inverse-Power 57 | - 'power' 58 | - Iteratively solve for the steady-state solution using the inverse-power method. 59 | * - GMRES 60 | - 'iterative-gmres' 61 | - Iteratively solve for the steady-state solution using the GMRES method and optional preconditioner. 62 | * - LGMRES 63 | - 'iterative-lgmres' 64 | - Iteratively solve for the steady-state solution using the LGMRES method and optional preconditioner. 65 | * - BICGSTAB 66 | - 'iterative-bicgstab' 67 | - Iteratively solve for the steady-state solution using the BICGSTAB method and optional preconditioner. 68 | * - SVD 69 | - 'svd' 70 | - Steady-state solution via the SVD of the Liouvillian represented by a **dense** matrix. 71 | 72 | 73 | The function :func:`qutip.steadystate.steadystate` can take either a Hamiltonian and a list of collapse operators as input, generating internally the corresponding Liouvillian super operator in Lindblad form, or alternatively, an arbitrary Liouvillian passed by the user. When possible, we recommend passing the Hamiltonian and collapse operators to :func:`qutip.steadystate.steadystate`, and letting the function automatically build the Liouvillian for the system. 74 | 75 | 76 | .. _steady-usage: 77 | 78 | Using the Steadystate Solver 79 | ============================= 80 | 81 | Solving for the steady state solution to the Lindblad master equation for a general system with :func:`qutip.steadystate.steadystate` can be accomplished using:: 82 | 83 | >>> rho_ss = steadystate(H, c_ops) 84 | 85 | where ``H`` is a quantum object representing the system Hamiltonian, and ``c_ops`` is a list of quantum objects for the system collapse operators. The output, labeled as ``rho_ss``, is the steady-state solution for the systems. If no other keywords are passed to the solver, the default 'direct' method is used, generating a solution that is exact to machine precision at the expense of a large memory requirement. The large amount of memory need for the direct LU decomposition method stems from the large bandwidth of the system Liouvillian and the correspondingly large fill-in (extra nonzero elements) generated in the LU factors. This fill-in can be reduced by using bandwidth minimization algorithms such as those discussed in :ref:`steady-args`. Additional parameters may be used by calling the steady-state solver as:: 86 | 87 | >>> rho_ss = steadystate(H, c_ops, method='power', use_rcm=True) 88 | 89 | where ``method='power'`` indicates that we are using the inverse-power solution method, and ``use_rcm=True`` turns on the bandwidth minimization routine. 90 | 91 | 92 | Although it is not obvious, the ``'direct'``, ``eigen``, and ``'power'`` methods all use an LU decomposition internally and thus suffer from a large memory overhead. In contrast, iterative methods such as the ``'iterative-gmres'``, ``'iterative-lgmres'``, and ``'iterative-bicgstab'`` methods do not factor the matrix and thus take less memory than these previous methods and allowing, in principle, for extremely large system sizes. The downside is that these methods can take much longer than the direct method as the condition number of the Liouvillian matrix is large, indicating that these iterative methods require a large number of iterations for convergence. To overcome this, one can use a preconditioner :math:`M` that solves for an approximate inverse for the (modified) Liouvillian, thus better conditioning the problem, leading to faster convergence. The use of a preconditioner can actually make these iterative methods faster than the other solution methods. The problem with precondioning is that it is only well defined for Hermitian matrices. Since the Liouvillian is non-Hermitian, the ability to find a good preconditioner is not guaranteed. And moreover, if a preconditioner is found, it is not guaranteed to have a good condition number. QuTiP can make use of an incomplete LU preconditioner when using the iterative ``'gmres'``, ``'lgmres'``, and ``'bicgstab'`` solvers by setting ``use_precond=True``. The preconditioner optionally makes use of a combination of symmetric and anti-symmetric matrix permutations that attempt to improve the preconditioning process. These features are discussed in the :ref:`steady-args` section. Even with these state-of-the-art permutations, the generation of a successful preconditoner for non-symmetric matrices is currently a trial-and-error process due to the lack of mathematical work done in this area. It is always recommended to begin with the direct solver with no additional arguments before selecting a different method. 93 | 94 | Finding the steady-state solution is not limited to the Lindblad form of the master equation. Any time-independent Liouvillian constructed from a Hamiltonian and collapse operators can be used as an input:: 95 | 96 | >>> rho_ss = steadystate(L) 97 | 98 | where ``L`` is the Louvillian. All of the additional arguments can also be used in this case. 99 | 100 | 101 | .. _steady-args: 102 | 103 | Additional Solver Arguments 104 | ============================= 105 | 106 | The following additional solver arguments are available for the steady-state solver: 107 | 108 | .. cssclass:: table-striped 109 | 110 | .. list-table:: 111 | :widths: 10 30 50 112 | :header-rows: 1 113 | 114 | * - Keyword 115 | - Options (default listed first) 116 | - Description 117 | * - method 118 | - 'direct', 'eigen', 'power', 'iterative-gmres','iterative-lgmres', 'svd' 119 | - Method used for solving for the steady-state density matrix. 120 | * - sparse 121 | - True, False 122 | - Use sparse version of direct solver. 123 | * - weight 124 | - None 125 | - Allows the user to define the weighting factor used in the ``'direct'``, ``'GMRES'``, and ``'LGMRES'`` solvers. 126 | * - permc_spec 127 | - 'COLAMD', 'NATURAL' 128 | - Column ordering used in the sparse LU decomposition. 129 | * - use_rcm 130 | - False, True 131 | - Use a Reverse Cuthill-Mckee reordering to minimize the bandwidth of the modified Liouvillian used in the LU decomposition. If ``use_rcm=True`` then the column ordering is set to ``'Natural'`` automatically unless explicitly set. 132 | * - use_umfpack 133 | - False, True 134 | - Use the umfpack solver rather than the default superLU. on SciPy 0.14+, this option requires installing the scikits.umfpack extension. 135 | * - use_precond 136 | - False, True 137 | - Attempt to generate a preconditioner when using the ``'iterative-gmres'`` and ``'iterative-lgmres'`` methods. 138 | * - M 139 | - None, sparse_matrix, LinearOperator 140 | - A user defined preconditioner, if any. 141 | * - use_wbm 142 | - False, True 143 | - Use a Weighted Bipartite Matching algorithm to attempt to make the modified Liouvillian more diagonally dominate, and thus for favorable for preconditioning. Set to ``True`` automatically when using a iterative method, unless explicitly set. 144 | * - tol 145 | - 1e-9 146 | - Tolerance used in finding the solution for all methods expect ``'direct'`` and ``'svd'``. 147 | * - maxiter 148 | - 10000 149 | - Maximum number of iterations to perform for all methods expect ``'direct'`` and ``'svd'``. 150 | * - fill_factor 151 | - 10 152 | - Upper-bound on the allowed fill-in for the approximate inverse preconditioner. This value may need to be set much higher than this in some cases. 153 | * - drop_tol 154 | - 1e-3 155 | - Sets the threshold for the relative magnitude of preconditioner elements that should be dropped. A lower number yields a more accurate approximate inverse at the expense of fill-in and increased runtime. 156 | * - diag_pivot_thresh 157 | - None 158 | - Sets the threshold between :math:`[0,1]` for which diagonal elements are considered acceptable pivot points when using a preconditioner. 159 | * - ILU_MILU 160 | - 'smilu_2' 161 | - Selects the incomplete LU decomposition method algorithm used. 162 | 163 | Further information can be found in the :func:`qutip.steadystate.steadystate` docstrings. 164 | 165 | .. _steady-example: 166 | 167 | Example: Harmonic Oscillator in Thermal Bath 168 | ============================================ 169 | 170 | A simple example of a system that reaches a steady state is a harmonic oscillator coupled to a thermal environment. Below we consider a harmonic oscillator, initially in the :math:`\left|10\right>` number state, and weakly coupled to a thermal environment characterized by an average particle expectation value of :math:`\left=2`. We calculate the evolution via master equation and Monte Carlo methods, and see that they converge to the steady-state solution. Here we choose to perform only a few Monte Carlo trajectories so we can distinguish this evolution from the master-equation solution. 171 | 172 | .. ipython:: 173 | 174 | In [1]: N = 20 # number of basis states to consider 175 | 176 | In [1]: a = destroy(N) 177 | 178 | In [1]: H = a.dag() * a 179 | 180 | In [1]: psi0 = basis(N, 10) # initial state 181 | 182 | In [1]: kappa = 0.1 # coupling to oscillator 183 | 184 | In [1]: c_op_list = [] 185 | 186 | In [1]: n_th_a = 2 # temperature with average of 2 excitations 187 | 188 | In [1]: rate = kappa * (1 + n_th_a) 189 | 190 | In [1]: c_op_list.append(sqrt(rate) * a) # decay operators 191 | 192 | In [1]: rate = kappa * n_th_a 193 | 194 | In [1]: c_op_list.append(sqrt(rate) * a.dag()) # excitation operators 195 | 196 | In [1]: final_state = steadystate(H, c_op_list) 197 | 198 | In [1]: fexpt = expect(a.dag() * a, final_state) 199 | 200 | In [1]: tlist = linspace(0, 50, 100) 201 | 202 | In [1]: mcdata = mcsolve(H, psi0, tlist, c_op_list, [a.dag() * a], ntraj=100) 203 | 204 | In [1]: medata = mesolve(H, psi0, tlist, c_op_list, [a.dag() * a]) 205 | 206 | In [1]: figure() 207 | 208 | In [1]: plot(tlist, mcdata.expect[0], tlist, medata.expect[0], lw=2) 209 | 210 | In [1]: axhline(y=fexpt, color='r', lw=1.5) # ss expt. value as horiz line (= 2) 211 | 212 | In [1]: ylim([0, 10]) 213 | 214 | In [1]: xlabel('Time', fontsize=14) 215 | 216 | In [1]: ylabel('Number of excitations', fontsize=14) 217 | 218 | In [1]: legend(('Monte-Carlo', 'Master Equation', 'Steady State')) 219 | 220 | In [1]: title('Decay of Fock state $\left|10\\rangle\\right.$' + 221 | ...: ' in a thermal environment with $\langle n\\rangle=2$') 222 | 223 | @savefig guide-steady1.png width=5.0in align=center 224 | In [1]: show() 225 | 226 | 227 | --------------------------------------------------------------------------------