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

QuantumPlaybook

Guides

  • QuantumPlaybook

Tech Notes

  • Addition of Numbers
  • Baker-Hausdorff Lemma
  • Chiral Fermion Random Circuit
  • Clifford Operators: How to Test
  • Commutation Relations for Qubits
  • Entanglement Distillation
  • Generalized Pauli Operators: Implementation
  • Hatano-Nelson-Kitaev Model: Monte Carlo Simulation
  • Hatano-Nelson Model: Monte Carlo Simulation
  • Kitaev Chain
  • Kitaev Random Circuit
  • Λ-Matter in a Cavity
  • Measurement of Total Pauli Z
  • Non-Unitary Dynamics of Quantum States
  • Partial Trace: Physical Meaning
  • Quantum Dot Systems
  • A Quantum Playbook
  • Magnetic Exchange Coupling
  • Solovay-Kitaev Algorithm
  • Spin Code
  • Symmetry Effects On Quantum Master Equations
  • Transmon: Quantum Phase Model
  • Transposition as a Supermap
  • Variational Quantum Classifier: Iris
  • Variational Quantum Classifier: Parity
  • Variational Quantum Eigensolver: Transverse-Field Ising Model

Symbols

  • BlochEnergy
  • BlochFunction
  • QuantumPlaybookCheckUpdate
  • QuantumPlaybookEdition
  • QuantumPlaybookUpdate
  • TransmonEnergy
  • TransmonExponent
  • TransmonFunction
  • TransmonHamiltonian
Variational Quantum Eigensolver: Transverse-Field Ising Model
Preliminary
Variational Quantum Circuit (Ansatz)
Setting Up the Model
Variational Solution in the Paramagnetic Phase
Elementary Quantum Circuit Layer
Variational Solution in the Ferromagnetic Phase
In this demonstration, we calculate the ground-state energy of the transverse-field Ising model,
H=J
n-1
Σ
k=1
Z
k
Z
k+1
+B
n
Σ
k=1
X
k

,
where
X
k
and
Z
k
are the Pauli
X
and
Z
operators, respectively, acting on qubit k,
J
is the exchange energy, and
B
is the dimensionless field in the transverse direction (that is, along the
x
-axis).
The model exhibits a quantum phase transition from the ferromagnetic (or ordered) phase (
B<1
) to the paramagnetic (or disordered) phase (
B<1
).
FindMinimum
Searches for a local mininum
QuantumCircuit
Quantum circuit model
Functions used in variational quantum eigensolver.
Preliminary
Make sure that the Q3 package is loaded.
In[27]:=
Needs["QuantumMob`Q3`"]
This function checks the calculated value against the true ground-state energy. It returns a pair
{val,error}
of the estimated ground-state energy
val
and the
error
relative to the true ground-state energy.
In[28]:=
checkResult[val_,true_]:=With[​​{error=Abs@PseudoDivide[val-true,true]},​​If[error>10*^-2,Message[checkResult::big]];​​{val,PercentForm@error}​​]​​checkResult::big="The error is too big!";
Setting Up the Model
Take a quantum register of
n
qubits. We refer to the register by symbol S.
In[30]:=
Let[Qubit,S]
In[31]:=
$n=4;​​kk=Range[$n];​​SS=S[kk,$]
Out[33]=
{
S
1
,
S
2
,
S
3
,
S
4
}
Take the Hamiltonian of transverse-field Ising model. We have put
J=1
. In other words, we measure energies in units of
J
. On the other hand,
B
is the dimensionless field in the transverse direction.
In[34]:=
Let[Real,B]​​HH=Total@ChainBy[Through[SS[3]],Multiply]+B*Total@Through[SS[1]]
Out[35]=
Z
S
1
Z
S
2
+
Z
S
2
Z
S
3
+
Z
S
3
Z
S
4
+B
X
S
1
+
X
S
2
+
X
S
3
+
X
S
4

Elementary Quantum Circuit Layer
A variational quantum circuit is usually constructed by accumulating layers of quantum circuits. Here, we construct an elementary quantum circuit layer to be used repeatedly later.
The variational parameters are denoted by
a[layer,qubit,μ]
.
In[36]:=
Let[Real,a]
Construct a basic layer of quantum circuit.
In[37]:=
Clear[rot,layer]​​rot[k_]=QuantumCircuit@Table[EulerRotation[Pi*a[k,q,{1,2,3}],S[q,$]],{q,$n}];​​cnt=QuantumCircuit[​​CNOT@@@Partition[SS,2],​​CNOT@@@Partition[Rest@SS,2]​​];​​layer[k_Integer]=QuantumCircuit[rot[k],cnt];​​layer[kk:{___Integer}]:=QuantumCircuit@@Riffle[Table[layer[k],{k,kk}],"Separator"]
For example, here is a variational quantum circuit with two layers. Although all boxes are denoted by the same label
U
E
, they represent different Euler rotations with different sets of Euler angles
{a[layer,qubit,1],a[layer,qubit,2],a[layer,qubit,3]}
.
In[42]:=
layer[{1,2}]
Out[42]=
Variational Quantum Circuit (Ansatz)
Here, we construct a variational quantum circuit by accumulating the quantum circuit layers defined above.
The number of layers.
In[43]:=
$L=2;
Construct a variational quantum circuit.
In[44]:=
try=QuantumCircuit[Ket[SS],layer[Range@$L]]
Out[44]=
The above quantum circuit involves
L×n×3
variational parameters
a
l,q,μ
for layer
l
, qubit
q
, and
μ=1,2,3
.
In[45]:=
aa=a[Range@$L,kk,{1,2,3}]
Out[45]=
{
a
1,1,1
,
a
1,1,2
,
a
1,1,3
,
a
1,2,1
,
a
1,2,2
,
a
1,2,3
,
a
1,3,1
,
a
1,3,2
,
a
1,3,3
,
a
1,4,1
,
a
1,4,2
,
a
1,4,3
,
a
2,1,1
,
a
2,1,2
,
a
2,1,3
,
a
2,2,1
,
a
2,2,2
,
a
2,2,3
,
a
2,3,1
,
a
2,3,2
,
a
2,3,3
,
a
2,4,1
,
a
2,4,2
,
a
2,4,3
}
This is to randomly initialize the parameters.
In[46]:=
a0=Flatten@RandomReal[{0,1}Pi,{$L,$n,3}]
Out[46]=
{0.414375,0.617868,2.1155,0.287714,0.125207,1.92398,2.55085,1.91707,1.64815,0.906177,1.1128,0.839937,0.0212202,0.014589,2.34616,2.05437,2.90629,0.551612,0.532189,2.17853,0.629491,0.318403,2.85779,2.16347}
Evaluate the quantum circuit to express it in the vector form.
In[47]:=
EchoTiming[out=Matrix[try,SS];]
⌚
0.472176
Variational Solution in the Paramagnetic Phase
Now, we are ready to solve the variational problem by defining the objective function and minimizing the function over the variational parameter. Here, we first solve the problem in the paramagnetic phase.
Construct the objective function, which in this case is the expectation value of the Hamiltonian.
In[48]:=
Block[​​{B=5.},(*Paramagneticphase*)​​EchoTiming[mat=Matrix[HH,SS]];​​Echo[groundStateEnergy=Min@Eigenvalues[mat],"Ground-state energy"];​​EchoTiming[avg=Re[Conjugate[out].mat.out]];​​]
⌚
0.002129
»
Ground-state energy-20.1501
⌚
0.097482
A variable to take trace of the value of objective function at each iteration step.
In[49]:=
data={};
Iteratively calculate the ground-state energy by minimizing the expectation value of the Hamiltonian.
In[50]:=
{val,sol}=FindMinimum[avg,Transpose@{aa,a0},​​StepMonitor(​​AppendTo[data,avg];​​PrintTemporary["Expectation value: ",avg]​​),​​Method"IPOPT"];
Check the result. The first value is the estimation of the ground-state energy and the second number is the relative error.
In[51]:=
checkResult[val,groundStateEnergy]
Out[51]=
{-20.1,0.2488%}
This shows the convergence behavior of the above iteration method.
Variational Solution in the Ferromagnetic Phase
Here, we solve the variational problem by minimizing the expectation value of the Hamiltonian in the paramagnetic phase.
Construct the objective function, which in this case is the expectation value of the Hamiltonian.
A variable to take trace of the value of objective function at each iteration step.
Iteratively calculate the ground-state energy by minimizing the expectation value of the Hamiltonian.
Check the result. The first value is the estimation of the ground-state energy and the second number is the relative error.
This shows the convergence behavior of the above iteration method.

© 2025 Wolfram. All rights reserved.

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