{ "cells": [ { "cell_type": "markdown", "id": "phase-space-title", "metadata": {}, "source": [ "# Wigner and Husimi-Q Functions\n", "\n", "This tutorial evaluates phase-space distributions for a finite Fock-space state and plots them with the built-in Matplotlib helpers." ] }, { "cell_type": "code", "execution_count": null, "id": "phase-space-imports", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import openquantumsim as oqs" ] }, { "cell_type": "code", "execution_count": null, "id": "phase-space-compute", "metadata": {}, "outputs": [], "source": [ "space = oqs.FockSpace(30, label=\"cavity\")\n", "alpha = 1.0 + 0.5j\n", "rho = oqs.ket2dm(oqs.coherent(space, alpha))\n", "\n", "x, p = oqs.phase_space_grid(xlim=(-5.0, 5.0), points=201)\n", "W = oqs.wigner(rho, x, p)\n", "Q = oqs.q_function(rho, x, p)\n", "W.shape, Q.shape" ] }, { "cell_type": "code", "execution_count": null, "id": "phase-space-wigner-plot", "metadata": {}, "outputs": [], "source": [ "ax = oqs.plot_wigner(rho, x, p)\n", "ax.set_title(\"Coherent-state Wigner function\")" ] }, { "cell_type": "code", "execution_count": null, "id": "phase-space-q-plot", "metadata": {}, "outputs": [], "source": [ "ax = oqs.plot_q_function(rho, x, p)\n", "ax.set_title(\"Coherent-state Husimi Q function\")" ] }, { "cell_type": "markdown", "id": "phase-space-array-note", "metadata": {}, "source": [ "The numeric arrays `W` and `Q` are ordinary NumPy arrays, so they can be passed to custom plotting, fitting, or export pipelines." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 5 }