Fock Simulators

Warning

The ordering of the Fock basis is increasing with particle numbers, and in each particle number conserving subspace, anti-lexicographic ordering is used.

Example for 3 modes:

\[\ket{000}, \ket{100}, \ket{010}, \ket{001}, \ket{200}, \ket{110}, \ket{101}, \ket{020}, \ket{011}, \ket{002}, \dots\]

General Fock Simulator

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

Performs photonic simulations using Fock representation.

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

Example usage:

import numpy as np
import piquasso as pq


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

    pq.Q(0)   | pq.Squeezing(r=0.1)
    pq.Q(1)   | pq.Squeezing(r=0.2)

    pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 3)

    pq.Q(0) | pq.Attenuator(theta=0.01)
    pq.Q(1) | pq.Attenuator(theta=0.02)

    pq.Q(0) | pq.Kerr(xi=0.05)

simulator = pq.FockSimulator(d=2, config=pq.Config(cutoff=7))
result = simulator.execute(program)
Supported preparations:

Vacuum, Create, Annihilate, DensityMatrix.

Supported gates:

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

Supported measurements:

ParticleNumberMeasurement.

Supported channels:

Attenuator

create_initial_state(d=None)

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 | None = 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. If it is None, the simulator will execute the program once, returning the exact probability distribution instead of samples. Defaults to 1.

Raises:

InvalidParameter – When shots is not a positive integer or not None.

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 | None = 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. If it is None, the simulator will execute the program once, returning the exact probability distribution instead of samples. Defaults to 1.

Raises:
  • InvalidParameter – When shots is not a positive integer or not None.

  • InvalidSimulation – When the number of modes cannot be inferred and d was not provided during simulator initialization.

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.

Pure Fock Simulator

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

Performs photonic simulations using Fock representation with pure states.

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

Example usage:

import numpy as np
import piquasso as pq


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

    pq.Q(0)   | pq.Squeezing(r=0.1)
    pq.Q(1)   | pq.Squeezing(r=0.2)

    pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 3)

    pq.Q(0) | pq.Kerr(xi=0.05)

simulator = pq.PureFockSimulator(d=2, config=pq.Config(cutoff=7))
result = simulator.execute(program)
Supported preparations:

Vacuum, Create, Annihilate, StateVector.

Supported gates:

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

Supported measurements:

ParticleNumberMeasurement.

Supported channels:

Attenuator.

create_initial_state(d=None)

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 | None = 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. If it is None, the simulator will execute the program once, returning the exact probability distribution instead of samples. Defaults to 1.

Raises:

InvalidParameter – When shots is not a positive integer or not None.

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 | None = 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. If it is None, the simulator will execute the program once, returning the exact probability distribution instead of samples. Defaults to 1.

Raises:
  • InvalidParameter – When shots is not a positive integer or not None.

  • InvalidSimulation – When the number of modes cannot be inferred and d was not provided during simulator initialization.

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.