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

  • 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
Quantum Optimization
Variational Circuits
Quantum Natural Gradient Descent
Ansatz Circuits
Quantum Linear Solver
Variational Quantum Eigensolver
Examples Custom Functions
In this Tech Note, we document the implementation and utilization of essential functions used in the
Wolfram Language Example Repository
for Quantum Optimization algorithms.
By providing a comprehensive overview and usage guidelines for these functions, we aim to introduce new and experienced users into quantum optimization techniques and quantum computing research.
In[1]:=
<<Wolfram`QuantumFramework`​​<<Wolfram`QuantumFramework`QuantumOptimization`
Variational Circuits
Ansatz Circuits
Variational Quantum Eigensolver
The variational quantum eigensolver (VQE) is a hybrid algorithm that combines classical and quantum computing to determine the ground state energy of a Hamiltonian. It utilizes quantum algorithms to calculate expected energy values and classical optimization techniques for minimizing that energy.
VQE plays a crucial role in quantum optimization, particularly in solving complex problems in quantum chemistry and materials science. By enabling efficient simulations of intricate systems, VQE can address optimization tasks that are challenging for classical methods alone.
Given a Hamiltonian operator H, this method consist of two main components:
◼
  • A variational circuit ansatz
    V(θ)
    .
  • ◼
  • A cost function
    ℒ=〈ϕ(θ)|H|ϕ(θ)〉
    , where
    |ϕ(θ)〉=V(θ)|0〉
    .
  • The method involves iteratively adjusting θ to minimize the average energy or cost function .

    Application

    In order to understand how to proceed with the VQE algorithm, let's drive the a variational state
    |ϕ(θ)〉
    to the ground state of the following Hamiltonian:
    In[3]:=
    H=
    QuantumOperator
    ["X"+"Z"]
    Out[3]=
    QuantumOperator
    Pure map
    ​
    Dimension: 2→2
    Order: {1}→{1}
    
    Define the ansatz circuit V(θ):
    In[27]:=
    V=
    QuantumCircuitOperator
    [{"0","RX"[θ1]{1},"RY"[θ2]{1}},"Parameters"{θ1,θ2}];​​"Diagram"//V
    Out[28]=
    Calculate
    |ϕ(θ)〉
    from the ansatz circuit V:
    In[69]:=
    ϕ=V[];​​"Formula"//ϕ
    Out[70]=
    Cos
    θ1
    2
    Cos
    θ2
    2
    +Sin
    θ1
    2
    Sin
    θ2
    2
    |0〉+-Cos
    θ2
    2
    Sin
    θ1
    2
    +Cos
    θ1
    2
    Sin
    θ2
    2
    |1〉
    Implement the cost function ℒ as stated before:
    In[8]:=
    ℒ[θ1_,θ2_]=ComplexExpand["Scalar"//
    †
    ϕ
    @H@ϕ];​​ℒ[θ1,θ2]//Simplify
    Out[9]=
    Cos[θ1](Cos[θ2]+Sin[θ2])
    Calculate the ground state eigenvalue of H by minimizing :
    In[10]:=
    MinValue[ℒ[θ1,θ2],{θ1,θ2}]
    Out[10]=
    -
    2

    Visualizations

    In order to visualize the optimization process, we need to get all the parameter values during the evolution, in this case we will use a simple gradient descent method:
    In[20]:=
    initialPosition={0.1,0.1};
    In[21]:=
    params=GradientDescent[ℒ,initialPosition];
    It would be also useful to calculate all the cost function values during each step of the parameter evolution:
    In[22]:=
    costs=ℒ@@@params;
    Cost curve
    We can visualize the evolution of our optimization during time in an Cost Curve, also known as Loss Curve:
    In[23]:=
    ListLinePlotcosts,
    
    Out[23]=
    Parameter Space
    We can visualize the evolution of our optimization in the parameter space in a Contour Plot:
    In[24]:=
    ContourPlotℒ[θ1,θ2],
    
    Out[24]=
    Gradient Vector Plot
    The stream plot of the gradient of our cost function can provide insight into the behavior of the evolution as observed in its parameter space:
    In[25]:=
    StreamPlotEvaluate[-Grad[ℒ[θ1,θ2],{θ1,θ2}]],
    
    Out[25]=
    Quantum Natural Gradient Descent
    Quantum Linear Solver
    Examples Custom Functions
    ""

    © 2025 Wolfram. All rights reserved.

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