If you have Piquasso installed, open a file or a terminal, and just type
import numpy as np import piquasso as pq with pq.Program() as program: pq.Q(0) | pq.Displacement(alpha=1 + 1j) # Displace the state on mode 0 pq.Q(0, 1) | pq.Beamsplitter( theta=0, phi=np.pi / 2 ) # Use a beamsplitter gate on modes 0, 1 pq.Q(0) | pq.HomodyneMeasurement(phi=0) # Measurement on mode 0.
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 denotes the qumodes on which the instructions should be executed, the right hand side is for the actual operation, like
pq.Displacement (stands for a displacement operation), which takes a complex argument as shown.
Roughly the program translates to
Apply a displacement on mode 0. The displacement operation accepts
alphaas a parameter. The Gaussian state will be displaced by the value:
alphain the phase space on the specified mode.
Apply a beamsplitter gate on the modes 0, 1.
Perform a homodyne measurement on mode 0 with \(\phi=0\) which means measuring the \(x\) quadrature only.
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.
simulator = pq.GaussianSimulator( d=3, config=pq.Config(hbar=2) ) # Prepare a Gaussian vacuum state result = simulator.execute(program, shots=10) # Apply the program with 3 shots.
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.
[(3.4168422332862773, 16320.785088021246), (5.28128128234147, -21939.087578297764), (2.6823464556990437, -25680.93750083845), (1.9785214520668555, 20348.415213075612), (1.2914635648176238, -17285.401277892888), (2.088533421656983, -9988.585801845871), (3.1637825527284926, -8113.647825153105), (4.528800501260955, -12323.444626716877), (1.11948414913764, 964.0918692249029), (0.9422318222516874, -10503.374296293043)]