Note

You can download this notebook
here.

# Gaussian Boson Sampling#

Gaussian Boson Sampling can be performed as shown by the following example:

```
[1]:
```

```
import numpy as np
import piquasso as pq
d = 5
shots = 5
A = np.array(
[
[0, 1, 0, 1, 1],
[1, 0, 0, 0, 1],
[0, 0, 0, 1, 0],
[1, 0, 1, 0, 1],
[1, 1, 0, 1, 0],
]
)
with pq.Program() as gaussian_boson_sampling:
pq.Q(all) | pq.Graph(A)
pq.Q(all) | pq.ParticleNumberMeasurement()
simulator = pq.GaussianSimulator(d=d)
result = simulator.execute(gaussian_boson_sampling, shots=shots)
print("Samples:", result.samples)
```

```
Samples: [(3, 1, 2, 4, 4), (0, 1, 0, 0, 1), (0, 0, 0, 0, 0), (2, 2, 0, 4, 4), (0, 0, 0, 1, 1)]
```

The generated samples could be used to acquire some denser subgraphs of the generated graph with

```
[2]:
```

```
print("Subgraphs:", result.to_subgraph_nodes())
```

```
Subgraphs: [[0, 0, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4], [1, 4], [], [0, 0, 1, 1, 3, 3, 3, 3, 4, 4, 4, 4], [3, 4]]
```