Note
You can download this notebook
here.
Boson Sampling#
If one wants to run the Boson Sampling algorithm, it is easy to do by using pq.SamplingSimulator. A simple example is given as follows:
[2]:
import numpy as np
import piquasso as pq
with pq.Program() as program:
pq.Q(all) | pq.StateVector([0, 1, 1, 0])
pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 3, phi=np.pi / 4)
pq.Q(2, 3) | pq.Beamsplitter(theta=np.pi / 2, phi=np.pi / 3)
pq.Q(all) | pq.ParticleNumberMeasurement()
simulator = pq.SamplingSimulator(d=4)
result = simulator.execute(program, shots=5)
print(result.samples)
[(1, 0, 0, 1), (0, 1, 0, 1), (1, 0, 0, 1), (0, 1, 0, 1), (1, 0, 0, 1)]
One may also directly providde an interferometer by pq.Interferometer.
[7]:
from scipy.stats import unitary_group
d = 7
interferometer_matrix = unitary_group.rvs(d)
with pq.Program() as program:
pq.Q(all) | pq.StateVector([2, 0, 1, 1, 0, 3, 1])
pq.Q(all) | pq.Interferometer(interferometer_matrix)
pq.Q(all) | pq.ParticleNumberMeasurement()
simulator = pq.SamplingSimulator(d=d)
result = simulator.execute(program, shots=20)
print(result.samples)
[(4, 1, 0, 0, 2, 0, 1), (2, 0, 0, 0, 1, 5, 0), (2, 0, 1, 1, 2, 2, 0), (0, 5, 0, 1, 1, 0, 1), (4, 1, 0, 1, 1, 1, 0), (1, 3, 0, 2, 0, 1, 1), (4, 1, 0, 0, 2, 1, 0), (3, 1, 0, 0, 3, 1, 0), (3, 0, 0, 2, 2, 1, 0), (0, 3, 0, 0, 3, 1, 1), (1, 0, 2, 0, 4, 1, 0), (2, 0, 3, 0, 2, 1, 0), (2, 0, 0, 5, 1, 0, 0), (2, 0, 0, 1, 3, 1, 1), (0, 2, 0, 5, 1, 0, 0), (1, 3, 0, 1, 1, 1, 1), (0, 0, 1, 0, 6, 1, 0), (0, 0, 0, 0, 6, 2, 0), (0, 1, 2, 0, 5, 0, 0), (2, 0, 0, 0, 3, 1, 2)]