Gaussian Simulator

class GaussianSimulator(d: int, config: Config | None = None, connector: BaseConnector | None = None)

Performs photonic simulations using Gaussian representation.

The simulation (when executed) results in an instance of GaussianState.

Example usage:

import numpy as np
import piquasso as pq

from scipy.stats import unitary_group

d = 5

U = unitary_group.rvs(d)

with pq.Program() as program:
    pq.Q() | pq.Vacuum()

    for i in range(5):
        pq.Q(i) | pq.Squeezing(r=i*0.1)

    pq.Q(all) | pq.Interferometer(U)

    pq.Q(all) | pq.ParticleNumberMeasurement()

simulator = pq.GaussianSimulator(d=5)
result = simulator.execute(program, shots=100)
Supported preparations:

Vacuum, Mean, Covariance, Thermal.

Supported gates:

Interferometer, Beamsplitter, Phaseshifter, MachZehnder, Fourier, GaussianTransform, Squeezing, QuadraticPhase, Squeezing2, ControlledX, ControlledZ, Displacement, PositionDisplacement, MomentumDisplacement, Graph.

Supported measurements:

HomodyneMeasurement, HeterodyneMeasurement, GeneraldyneMeasurement, ParticleNumberMeasurement, ThresholdMeasurement.

Supported channels:

DeterministicGaussianChannel, Attenuator.

create_initial_state()

Creates an initial state with no instructions executed.

Note

This is not necessarily a vacuum state.

Returns:

The initial state of the simulation.

Return type:

State

execute(program: Program, shots: int = 1, initial_state: State | None = None) Result

Executes the specified program.

Parameters:
  • program (Program) – The program to execute.

  • initial_state (State, optional) – A state to execute the instructions on. Defaults to the state created by create_initial_state().

  • shots (int, optional) – The number of times the program should execute. Defaults to 1.

Raises:

InvalidParameter – When shots is not a positive integer.

Returns:

The result of the simulation containing the resulting state and samples if any measurement is specified in program.

Return type:

Result

execute_instructions(instructions: List[Instruction], initial_state: State | None = None, shots: int = 1) Result

Executes the specified instruction list.

Parameters:
  • instructions (List[Instruction]) – The instructions to execute.

  • initial_state (State, optional) – A state to execute the instructions on. Defaults to the state created by create_initial_state().

  • shots (int, optional) – The number of times the program should be execute. Defaults to 1.

Raises:

InvalidParameter – When shots is not a positive integer.

Returns:

The result of the simulation containing the resulting state and samples if any measurement is specified in instructions.

Return type:

Result

validate(program: Program) None

Validates the specified program.

Raises:
  • InvalidInstruction – When invalid instructions are defined in the program.

  • InvalidSimulation – When the instructions are valid, but the simulator couldn’t execute the specified program.

Parameters:

program (Program) – The program to validate.