Note

You can download this notebook here.

Separating Programs#

With Piquasso, one could easily separate programs into multiple with statements:

[1]:
import piquasso as pq
import numpy as np


with pq.Program() as preparation:
    pq.Q(0, 1) | pq.Squeezing2(r=1, phi=np.pi / 4)
    pq.Q(2, 3) | pq.Squeezing2(r=2, phi=np.pi / 3)

with pq.Program() as interferometer:
    pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 4, phi=np.pi / 3)
    pq.Q(1) | pq.Phaseshifter(phi=np.pi / 2)
    pq.Q(1, 2) | pq.Beamsplitter(theta=np.pi / 5, phi=np.pi / 6)

with pq.Program() as executable_program:
    pq.Q(all) | preparation

    pq.Q(0, 1, 2) | interferometer
    pq.Q(2, 3, 4) | interferometer

    pq.Q(3) | pq.HeterodyneMeasurement()


simulator = pq.GaussianSimulator(d=5)
result = simulator.execute(executable_program)
result
[1]:
<Result samples=[(-1.017200627783451, 1.5609890986162434)]>

Using this syntax, one could embed subprograms on different modes. In this example, the interferometer subprogram is embedded twice for two different sets of modes.