{ "cells": [ { "cell_type": "markdown", "id": "a66a4f7d", "metadata": {}, "source": [ "# Getting Started\n", "\n", "If you have Piquasso installed, open a file or a terminal, and just type" ] }, { "cell_type": "code", "execution_count": 7, "id": "3abcce3d", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import piquasso as pq\n", "\n", "\n", "# Program definition\n", "with pq.Program() as program:\n", " # Prepare a Gaussian vacuum state\n", " pq.Q() | pq.Vacuum()\n", "\n", " # Displace the state on mode 0\n", " pq.Q(0) | pq.Displacement(r=np.sqrt(2), phi=np.pi / 4)\n", "\n", " # Use a beamsplitter gate on modes 0, 1\n", " pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 3, phi=np.pi / 2)\n", "\n", " # Measurement on mode 0\n", " pq.Q(0) | pq.HomodyneMeasurement(phi=0)" ] }, { "cell_type": "markdown", "id": "0a093cd2", "metadata": {}, "source": [ "to create your first program in Piquasso. The instructions of the program are positioned in the `with` statement. On the left hand side, the [pq.Q](https://piquasso.readthedocs.io/en/latest/api/mode.html) denotes the qumodes on which the instructions should be executed, the right hand side is for the actual operation, like [pq.Displacement](https://piquasso.readthedocs.io/en/latest/instructions/gates.html#piquasso.instructions.gates.Displacement) (stands for a displacement operation), which takes a complex argument as shown.\n", "\n", "Roughly the program translates to\n", "\n", "- Apply a displacement on mode 0. The displacement operation accepts `alpha` as a parameter. The Gaussian state will be displaced by the value: `alpha` in the phase space on the specified mode.\n", "\n", "- Apply a beamsplitter gate on the modes 0, 1.\n", "\n", "- Perform a homodyne measurement on mode 0 with $\\phi=0$ which means measuring the $x$ quadrature only.\n", "\n", "To execute your program, create a simulator to simulate your program with. For this example, we use `GaussianSimulator`. One should specify the number of modes, on which the state is initialized. You can also specify $\\hbar$ for your simulation in the simulator." ] }, { "cell_type": "code", "execution_count": 8, "id": "09e048be", "metadata": {}, "outputs": [], "source": [ "# Creating the Gaussian simulator\n", "simulator = pq.GaussianSimulator(d=3, config=pq.Config(hbar=2))\n", "\n", "# Apply the program with 10 shots.\n", "result = simulator.execute(program, shots=10)" ] }, { "cell_type": "markdown", "id": "14175450", "metadata": {}, "source": [ "After finishing the execution, you should be able to see the results of the simulation, which are phase space position and momentum expectation values. The generated samples are a list of tuples that has a length corresponding to the number of shots. Each tuple correspnds to the position and momentum measurements." ] }, { "cell_type": "code", "execution_count": 9, "id": "8d872f86", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(0.4501947999792735, 12926.564725438904),\n", " (-0.5527901177646664, -10463.793136424274),\n", " (3.3685776813034023, 4016.3864717219553),\n", " (1.814450431718634, -16682.40871883702),\n", " (2.224714901610408, 4630.904436029417),\n", " (0.6879338275741113, -9247.094354633904),\n", " (0.6489117030747604, -3578.776764500346),\n", " (0.6805547169379911, 6816.377249688921),\n", " (-2.680094354941116, -11525.839109496135),\n", " (0.5785633198987801, 32082.76477619564)]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result.samples" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }