This module defines and implements several utility functions and language extensions that complement StrawberryFields. These include:

  • NumPy state functions

    These functions allow the calculation of various quantum states in either the Fock basis (a one-dimensional array indexed by Fock state) or the Gaussian basis (returning a vector of means and covariance matrix). These state calculations are NOT done in the simulators, but rather in NumPy.

    These are useful for generating states for use in calculating the fidelity of simulations.

  • Random functions

    These functions generate random numbers and matrices corresponding to various quantum states and operations.

  • Decorators

    The operation decorator allows functions containing quantum operations acting on a qumode to be used as an operation itself within a Program context.

  • Program functions

    These functions act on Program instances, returning or extracting information from the quantum circuit.


cat_state(a[, p, fock_dim])

Returns the cat state

coherent_state(a[, basis, fock_dim, hbar])

Returns the coherent state

displaced_squeezed_state(a, r, phi[, basis, …])

Returns the squeezed coherent state

extract_channel(prog, cutoff_dim[, …])

Numerical array representation of the channel corresponding to a quantum circuit.

extract_unitary(prog, cutoff_dim[, …])

Numerical array representation of a unitary quantum circuit.

fock_state(n[, fock_dim])

Returns the Fock state


True iff all the operations in the program can be represented as quantum channels.


True iff all the operations in the program are unitary.


Normally distributed array of random complex numbers.

random_covariance(N[, hbar, pure, block_diag])

Random covariance matrix.

random_interferometer(N[, real])

Random unitary matrix representing an interferometer.

random_symplectic(N[, passive, block_diag, …])

Random symplectic matrix representing a Gaussian transformation.

squeezed_cov(r, phi[, hbar])

Returns the squeezed covariance matrix of a squeezed state

squeezed_state(r, p[, basis, fock_dim, hbar])

Returns the squeezed state

vacuum_state([basis, fock_dim, hbar])

Returns the vacuum state



Groups a sequence of gates into a single operation to be used within a Program context.