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
  • Example Repository Functions
  • Exploring Fundamentals of Quantum Theory
  • Quantum object abstraction
  • 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
Example Repository Functions
Gradient-Based Optimization Methods
Examples Custom Functions
Quantum Linear Solver
​
In this Tech Note, we document the implementation and utilization of essential functions used in the
Wolfram Language Example Repository
for Quantum Computing algorithms. The examples include the Quantum Natural Gradient Descent, Stochastic Parameter Shift Rule and more.
By providing a comprehensive overview and usage guidelines for these functions, we aim to introduce new and experienced users into quantum optimization techniques, quantum machine learning and quantum computing research.
In[92]:=
<<Wolfram`QuantumFramework`ExampleRepository`
Gradient-Based Optimization Methods
Quantum Linear Solver
The Variational Quantum Linear Solver (VQLS) is a hybrid quantum-classical technique designed to address Quantum Linear Systems Problems (QLSP). The main goal is to find linear solutions for systems as
m.x=b
.
In this Tech Note we will explain the applications and options of
QuantumLinearSolve
function implemented in the Wolfram Quantum Computation Framework to solve QLSP problems.
QuantumLinearSolve
[m,b,opts]
uses a hybrid optimization algorithm to find a quantum state described by the state vector
x
that satisfies
m.x=b
.
QuantumLinearSolve
[m,b,prop,opts]
solves
m.x=b
by including the specified properties
prop
.
We will briefly demonstrate how to apply all these functions in Wolfram quantum framework.

Example

Simple example
Generate a random 4×4 real matrix:
In[93]:=
m=RandomReal[{0,1},{4,4}];​​m//MatrixForm
Out[94]//MatrixForm=
0.596166
0.62566
0.816575
0.857365
0.287865
0.236078
0.491353
0.593494
0.786389
0.0297055
0.638947
0.00472644
0.736549
0.108758
0.314166
0.0812839
Generate a random complex vector of the length 4:
In[95]:=
b=RandomComplex[{-0.1-0.1I,0.1+0.1I},4]
Out[95]=
{0.0170825+0.049994,0.027093+0.091541,0.0806183-0.0000258573,-0.0829871-0.0489408}
Use them as input in the
QuantumLinearSolve
:
In[99]:=
QuantumLinearSolve[m,b]
Out[99]=
{-0.287755-0.110093,-0.0772302-0.274276,0.485296+0.146765,-0.185835+0.195234}
When running above code, you may see a progress box describing steps and estimated time.
Find the solution using
LinearSolve
:
In[100]:=
LinearSolve[m,b]
Out[100]=
{-0.287755-0.110093,-0.0772302-0.274276,0.485296+0.146764,-0.185835+0.195234}
Compare the results:
In[98]:=
%%-%//Abs
Out[98]=
{4.17675×
-8
10
,2.38047×
-7
10
,5.30811×
-8
10
,1.74998×
-7
10
}
Properties
You can request the components used during the calculation using a third property argument:
"Ansatz"
Returns only the QuantumState ansatz used to solve the QLSP.
"CircuitOperator"
Returns only the QuantumCircuitOperator variational circuit ψ used to solve the QLSP.
"GlobalPhase"
Includes in solution the calculated global phase 〈
ϕ

〉 between the optimized ψ and vector b problem.
"OptimizedParameters"
Return optimized values of defined parameters.
"Parameters"
Return systems defined parameters.
Show the ansatz quantum state used for parameter optimization"
In[101]:=
QuantumLinearSolve[m,b,"Ansatz"]
Out[101]=
QuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4

Show the quantum circuit used for parameter optimization:
In[102]:=
QuantumLinearSolve[m,b,"CircuitOperator"]
Out[102]=
Request more than one property:
In[103]:=
QuantumLinearSolve[m,b,{"Result","Ansatz","GlobalPhase"}]
Out[103]=
Result{-0.287755-0.110093,-0.0772302-0.274275,0.485296+0.146765,-0.185835+0.195234},AnsatzQuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4
,GlobalPhase
-0.23026347
-
0.46098513

±
0.00000014

Request them all using
All
as third argument:
In[6]:=
QuantumLinearSolve[m,b,All]
Out[6]=
Result{0.0594845+0.0894924,-0.420933-0.290229,-0.289422-0.169629,0.544499+0.292522},AnsatzQuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4
,CircuitOperatorQuantumCircuitOperator
​
,GlobalPhase
-0.20612061
+
0.43273420

±
0.00000005
,OptimizedParameters{ω.$1-0.694518,ω.$22.89257,ω.$31.81246,ω.$4-3.25301,ω.$50.0993645,ω.$6-1.6663,ω.$7-1.22972,ω.$82.38821},Parameters{ω.$1,ω.$2,ω.$3,ω.$4,ω.$5,ω.$6,ω.$7,ω.$8}

Options

"Ansatz"
Automatic
use specified ansatz instead of the one generated by the function
"GlobalPhaseAccuracy"
-5
10
expected accuracy for global phase estimation
AccuracyGoal
Automatic
number of digits of final accuracy sought
MaxIterations
Automatic
maximum number of iterations to use
Method
Automatic
method to use
PrecisionGoal
Automatic
number of digits of final precision sought
WorkingPrecision
MachinePrecision
the precision used in internal computations
Ansatz
You can specify the ansatz to be used as a
QuantumState
or
QuantumCircuitOperator
:
In[15]:=
ansatz=
QuantumState
[{α1,α2,α3,α4},{1,2},"Parameters"{α1,α2,α3,α4}];​​ansatz["Formula"]
Out[16]=
α1|00〉+α2|01〉+α3|10〉+α4|11〉
In[17]:=
m=RandomReal[{0,1},{4,4}]
Out[17]=
{{0.251149,0.632406,0.00760061,0.451067},{0.768939,0.771227,0.223159,0.103032},{0.553352,0.929828,0.0607338,0.399935},{0.778583,0.8705,0.598142,0.676169}}
In[18]:=
b=RandomReal[{0,1},4]
Out[18]=
{0.732115,0.567505,0.576803,0.848305}
In[19]:=
QuantumLinearSolve[m,b,"Ansatz"ansatz]
Out[19]=
{12.147+0.,-9.61246+0.,-10.0188+0.,8.50546+0.}
Compare the result with the classical method:
In[20]:=
LinearSolve[m,b]
Out[20]=
{12.147,-9.61247,-10.0188,8.50547}
In[21]:=
%-%%//Abs
Out[21]=
{2.77119×
-6
10
,2.35603×
-6
10
,2.31051×
-6
10
,1.90121×
-6
10
}
GlobalPhaseAccuracy
The
QuantumLinearSolve
function does an approximation to recover the result once the variational circuit ψ(ω) is close enough to the vector  problem such that
ψ≃
iϕ


. "GlobalPhaseAccuracy" option sets the accuracy of the global phase calculated.
In[22]:=
m=RandomReal[{0,1},{4,4}]
Let's indicate a high accuracy:
AccuracyGoal & PrecisionGoal
We can change them in order to get less precision but faster timing:
Compare both approximate results with the original result:
Method
Methods that are guaranteed to give a global minimum when they converge to a solution include:
Heuristic methods include:
Some methods may give suboptimal results for certain problems:
WorkingPrecision
Examples Custom Functions

© 2025 Wolfram. All rights reserved.

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