Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

QuantumFramework

Tutorials

  • Getting Started

Guides

  • Wolfram Quantum Computation Framework

Tech Notes

  • Bell's Theorem
  • Circuit Diagram
  • Exploring Fundamentals of Quantum Theory
  • QPU Service Connection
  • Quantum object abstraction
  • Quantum Optimization
  • Second Quantization Functions
  • Tensor Network
  • Quantum Computation

Symbols

  • EinsteinSummation
  • QuantumBasis
  • QuantumChannel
  • QuantumCircuitMultiwayGraph [EXPERIMENTAL]
  • QuantumCircuitOperator
  • QuantumDistance
  • QuantumEntangledQ
  • QuantumEntanglementMonotone
  • QuantumEvolve
  • QuantumMeasurement
  • QuantumMeasurementOperator
  • QuantumMeasurementSimulation
  • QuantumMPS [EXPERIMENTAL]
  • QuantumOperator
  • QuantumPartialTrace
  • QuantumPhaseSpaceTransform
  • QuantumShortcut [EXPERIMENTAL]
  • QuantumStateEstimate [EXPERIMENTAL]
  • QuantumState
  • QuantumTensorProduct
  • QuantumWignerMICTransform [EXPERIMENTAL]
  • QuantumWignerTransform [EXPERIMENTAL]
  • QuditBasis
  • QuditName
Second Quantization Functions
Bosonic states and operators
Quasi-probability Representations
Details and options
Quasi-probability representations: Applications and options
Basic usage
Advanced examples
​
In this Tech Note, we present the implementation of second quantization for bosons within the QuantumFramework, utilizing a truncated Fock space. This approach enables simple manipulation and representation of quantum states, which are essential for a wide range of calculations. By leveraging the core features of the QuantumFramework, we simplify the process of working with common quantum states and operators, facilitating diverse computational tasks in fundamental quantum mechanics and quantum optics.
In[2]:=
<<Wolfram`QuantumFramework`​​<<Wolfram`QuantumFramework`SecondQuantization`
Bosonic states and operators

Fock space size and utilities

SetFockSpaceSize
[size]
Sets size as the default truncation dimension , all the other definitions can use this default size
OperatorVariance
[ψ,op]
Variance of the operator op for a state ψ

States

FockState
[
n
,size]
n-th Fock state in a basis of dimension size
FockState
[{
n
1
,
n
2
,..},size]
Multimode Fock state with occupation numbers
n
i
, with each mode in a basis of dimension size
CoherentState
[size]​​
CoherentState
[size][α]
Parametric state representing a non-normalized coherent state in a basis of dimension size , the complex amplitude is a parameter
ThermalState
[nbar,size]
Thermal mixed state with average number of photons nbar in a basis of dimension size
CatState
[size]​​
CatState
[size][α,ϕ]
Parametric general cat state representing a superposition of coherent states in a basis of dimension size, the complex amplitude and the phase are parameters

Operators

AnnihilationOperator
[size, ord]
Bosonic annihilation operator in a truncated Fock spacewith basis dimension size and qudit order ord
DisplacementOperator
[α,size, ord]
Phase space displacement operator of a single mode with complex amplitude alpha , basis dimension size and qudit order ord
SqueezeOperator
[ξ,size,ord]
Squeeze operator of a single mode with complex parameter xi , basis dimension size and qudit order ord
QuadratureOperators
[size,ord]
X
1
and
X
2
position and momentum quadrature operators with basis dimension size and qudit order ord
PhaseShiftOperator
[θ,size,ord]
Phase space rotation operator with rotation angle θ, basis dimension size and qudit order ord
BeamSplitterOperator
[{θ,ϕ},size,ord]
Two mode beam-splitter operator, θ indicates the reflectivity, ϕ the relative phase in a basis of dimension size and qudit order ord
We will briefly demonstrate how to apply all these functions in Wolfram quantum framework.
Details and options

Operators Mathematical Definitions

DisplacementOperator
Exp[α
†
a
-
*
α
a]
SqueezeOperator
Exp
1
2
ξ
2
a
- ξ
†2
a

PhaseShiftOperator
Exp[ θ
†
a
a]
BeamSplitterOperator
Expθ
 ϕ

a
1
†
a
2
-
- ϕ

†
a
1
a
2

QuadratureOperators
X
1
:
1
2
(a+
†
a
)​​
X
2
:
1
2 
(a-
†
a
)
​

Ordering Option

Displacement and Squeeze operators can have different definitions based on operator ordering. We include the "Ordering" option to specify the order (weak , normal or anti normal ). Theoretically in a infinite dimensional space they are all equivalent , but in a truncated space these operators have numerical error, and depending on the calculation some choice of ordering can be more accurate.

Displacement operator ordering

By default when "Ordering" is not specified normal ordering is used, the formulas of the three orders are shown below:
DisplacementOperator
[..,"Ordering"st]
st can be "Normal", "Weak" or "Antinormal".​​​​For "Normal", one gets:​​
Exp[-|α
2
|
/2]Exp[α
†
a
]Exp[-αa]
​​​​For "Weak", one gets:​​
Exp[α
†
a
-αa]
​​​​For "Antinormal", one gets:​​
Exp[|α
2
|
/2]Exp[-αa]Exp[α
†
a
]

Squeeze operator ordering

By default when "Ordering" is not specified normal ordering is used, the formulas of the three orders are shown below:
SqueezeOperator
[…,"Ordering"st]
st
can be "Normal", "Antinormal" or "Weak". Given
ξ=
θ
r
​for "Normal", one gets:​
Exp[-
1
2
θ

Tanh[r]
†2
a
]Exp[-Log[Cosh[r]](
†
a
a+
1
2
)]Exp[
1
2
-θ

Tanh[r]
2
a
]
​​For "Weak", one gets:​
Exp[
1
2
(ξ
2
a
-ξ
†2
a
)]
​​For "Antinormal", one gets:​
Exp[
1
2
-θ

Tanh[r]
2
a
]Exp[Log[Cosh[r]](
†
a
a+
1
2
)]Exp[-
1
2
θ

Tanh[r]
†2
a
]

BeamSplitter operator: Method option

BeamSplitter operator supports two computing methods via the Method option. The default is MatrixExp that is based directly on matrix exponentiation algorithms, and Recurrence that employs an efficient recurrence relation algorithm for computing the matrix elements of the squeeze operator. Performance of the methods can vary depending if the angle arguments are passed as floating point number or exact/symbolic numbers.
Basic usage

Setting the space size

Set the default size to 20:
In[6]:=
SetFockSpaceSize[20];
Call AnnihilationOperator:
In[7]:=
AnnihilationOperator[]
Out[7]=
QuantumOperator
Pure map
​
Dimension: 20→20
Order: {1}→{1}

Calling it with no arguments, sets again the default size when loading the paclet which is 16:
In[8]:=
SetFockSpaceSize[];
Check the dimension when calling AnnihilationOperator again:
In[9]:=
AnnihilationOperator[]
Out[9]=
QuantumOperator
Pure map
​
Dimension: 16→16
Order: {1}→{1}


Annihilation operator usage

Define an annihilation operator with a given size and uses default order (1):
In[10]:=
AnnihilationOperator[8]
Out[10]=
QuantumOperator
Pure map
​
Dimension: 8→8
Order: {1}→{1}

Define an annihilation operator on the second mode with default truncation size:
In[11]:=
AnnihilationOperator[{2}]
Out[11]=
QuantumOperator
Pure map
​
Dimension: 16→16
Order: {2}→{2}

Define an annihilation operator with size 5 in the third order (or mode):
In[12]:=
AnnihilationOperator[5,{3}]
Out[12]=
QuantumOperator
Pure map
​
Dimension: 5→5
Order: {3}→{3}


Creation operator

Shortcut notation for annihilation operator:
Define creation operator just taking the adjoint(SuperDagger) of the annihilation operator, and apply it to a Fock state:
Or using "Dagger" property:

Multimode Fock State

Create a two mode Fock state with occupation numbers 2 and 12:
Check the formula:
Apply the annihilation operator to both modes using "Bend" property , state|1,11〉 is expected up to a global constant:
Equivalent result using QuantumState with strings arguments:
But this method will not work if one number is bigger than 9( it will interpret it as extra qudits):

Coherent state

Create a symbolic coherent state (not normalized):

Cat State

Photon distribution of the same state:

Displacement operator

Create displacement operator of size 40 with amplitude 3+ :
Create a coherent state displacing the vacuum:
Specify the order(mode) of the operator with default size, second mode in this case:

Phase shift operator

Specify the basis size and order:
Phase shift operator coincides with the "Z" gate for qudits when the angle is 2π/n (up to conjugation):

Squeeze operator

Create squeeze operator of default size with complex parameter 1+:
Plot the non-zero amplitudes of the state:

Beam-Splitter Operator

Transform the state |1,1〉 using the symmetric beam-splitter:
Specify the order (where the operator acts) and the basis dimension:
Use the "Recurrence" method passing exact numbers:

OperatorVariance

Calculate the variance of the quadrature operators for the ground state:
A Fock state has a definite number of photons so the variance of the number operator is zero:

Quadrature Operators

Ordering option

Amplitudes obtained from a known analytic formula:
Compute absolute errors:
Show the results:

Applications: States and operators

Mean number of photons

Create a random pure state:
Compute the mean number of photons using QuantumMeasurementOperator:
Using the probabilities in the diagonal of the density matrix:

Heisenberg evolution of annihilation operator

Define the Hamiltonian:
Constructing the evolution Super-operator:
Evolve the operator:
Compare the result to the known result of quantum mechanics:
Quasi-probability Representations
Two phase space quasi-probability representations are included Wigner and HusimiQ , which are used extensively in quantum mechanics and quantum optics. They are calculated numerically in a grid of phase space points and an interpolating function is returned. Glauber representation is not included because for a general state is not feasible to implement a numerical algorithm , due to the singularities of this representation.
We will briefly demonstrate how to apply all these functions in Wolfram quantum framework.

Examples

Ground state Wigner Representation:

Compute the representation in the square region from -4 to 4:
Visualize the function in 3D:

HusimiQ Representation of a Fock state

Visualize the density plot of the representation:
Quasi-probability representations: Applications and options

Expectation values

Wigner function of the Fock state |2〉:
Phase space integral:

Squeezed vacuum Wigner Representation

Plot the function, the non classical behavior of squeezed states regarding the quadratures is shown:

Options

Scaling of the representation for ground state

Pass the option setting the scaling parameter to 0.5:
Visualize the result:

Using GridSize

Calculating the value of the Wigner function of Fock state |2〉 at the origin, with a grid size of 140:
However, a grid size of 20 is not enough for this region and has a lot of numerical error:
The exact value from analytical expression is:
Compare absolute errors:
Advanced examples

Decay of a coherent state

Set up the value of the γ parameter:
Hamiltonian definition including photon loss:
State evolution:
Plot the mean number of photons as function of time:
Plot the fidelity respect to an analytical expression:
Show the results:

Optical balance

Considering the following master equation, we look for balance between a driving field Hamiltonian and the single photon loss mechanism:
Set up G parameter:
Random initial state:
Master equation set up:
Initial state:
Evolved state:
Photon number expectations and fidelity:

Jaynes-Cummings Model: Calculating the unitary

Define the basis and the relevant operators:
Going to the interaction picture at resonance, we get a time independent Hamiltonian:

Jaynes-Cummings Model: Evolving states

Fock State

Rabi oscillations when the field is initially in a Fock state
Find the probability of the atom being in the excited state:
Plot the result:

Coherent state: Collapse and revivals

Atom "thermalization" (atom interacting with a thermal state field)

Reduced density matrix of the atom:
Plot two components of the matrix:
Atom gets "thermalized", time average of the coherences → 0:

Jaynes-Cummings with dissipation

Parameter setting:
Hamiltonian definition:
Jump operators:
Helper definition to get the probability of finding the atom in the excited state in a time window:
Damped Rabi oscillations:

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com