You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This notebook will get you started with HOQST by introducing you to the functionality for solving colsed-system equations.
7
+
## Closed-system Examples
8
+
This notebook will get you started with HOQST by introducing you to the functionality for solving closed-system equations.
9
9
10
-
### Define the Hamiltonin
11
-
The first step is to define an Hamiltonian. In this tutorial we focus on a 2-level system with the following Hamiltonian
10
+
### Define the Hamiltonian
11
+
The first step is to define a Hamiltonian. In this tutorial, we focus on a 2-level system with the following Hamiltonian:
12
12
13
13
$$H(s) = - \sigma_z$$
14
14
15
-
where $s= t/t_f$ is the dimensionless time and $t_f$ is the total evolution time. We use a constant Hamiltonian so the simulation results can be trivially confirmed. The syntax is the same for timedependent Hamiltonians. Let's first define the Hamiltonian by:
15
+
where $s= t/t_f$ is the dimensionless time and $t_f$ is the total evolution time. We use the constant Hamiltonian so that the simulation results can be trivially confirmed. The syntax is the same for time-dependent Hamiltonians. Let's first define the Hamiltonian by:
16
16
17
17
```julia
18
18
using QuantumAnnealingTools, OrdinaryDiffEq, Plots
@@ -29,7 +29,7 @@ with size: (2, 2)
29
29
30
30
31
31
32
-
In this example, we use the `DenseHamiltonian`object. The syntax is the same for other type of Hamiltonians.
32
+
In this example, we use the `DenseHamiltonian`[type](https://docs.julialang.org/en/v1/manual/types/#man-types). It means the underlying data structure of this Hamiltonian type is [Julia array](https://docs.julialang.org/en/v1/manual/arrays/). There exists a different Hamiltonian type named `SparseHamiltonian` that relies on [sparse array](https://docs.julialang.org/en/v1/stdlib/SparseArrays/) as its internal data structure. Sparsity can only provide performance improvement when the system size is large. So, as a rule of thumb, users should only consider using `SparseHamiltonian` when the system size is larger than 10 qubits.
33
33
34
34
The closed-system evolution is completely specified by the Hamiltonian and the initial state. We can combine them into a single `Annealing` object by:
35
35
@@ -65,25 +65,25 @@ We start with the Schrodinger equation
To solve the this differential equation, we need to choose a proper algortihm. HOQST relies on `OrdinaryDiffEq.jl` as the lowlevel solver, which support a large collection of [algorithms](https://docs.sciml.ai/latest/solvers/ode_solve/). We do not guarantee compatibilities to every solver in this list. Users can try specific algorithms if they are interested. We provide a list of algorithms we tested and recommended here:
68
+
To solve this differential equation, we need to choose a proper algorithm. HOQST relies on `OrdinaryDiffEq.jl` as the low-level solver, which supports a large collection of [algorithms](https://docs.sciml.ai/latest/solvers/ode_solve/). We do not guarantee compatibilities to every solver in this list. Users can try specific algorithms if they are interested. We provide a list of algorithms we tested and recommended here:
69
69
70
70
1. The default Tsitouras 5/4 Runge-Kutta method(Tsit5()).
71
71
72
72
This is the default method in `OrdinaryDiffEq` and works well in most cases.
73
73
74
-
2. A secondorder A-B-L-S-stable one-step ESDIRK method(TRBDF2()).
74
+
2. A second-order A-B-L-S-stable one-step ESDIRK method(TRBDF2()).
75
75
76
-
This is the method widely used in large scale classical circuit simulations. Because this method has order of 2, it is recommended to use smaller error tolerance comparing with other higherorder methods.
76
+
This is the method widely used in large scale classical circuit simulations. Because this is a second-order method, it is recommended to use smaller error tolerance comparing with other higher-order methods.
77
77
78
78
3. A simple linear exponential method(LinearExponential()).
79
79
80
-
This method simply discretize the Hamiltonian and do matrix exponential for each interval.
80
+
This method discretizes the Hamiltonian and does the matrix exponential for each interval.
This method belongs to the adaptive exponential Runge-Kutta method family.
85
85
86
-
It is important to notice that, method 3 and 4 are exponential methods which would preserve the norm of the state vectors. To solve our the Schrodinger equation we use the function `solve_schrodinger`.
86
+
It is important to notice that methods 3 and 4 are exponential methods that are supposed to preserve the state vectors' norm. To solve the Schrodinger equation, we use the function `solve_schrodinger`:
In the above code block, the keyword arguments `abstol` and `reltol` are the absolute and relative error tolerances for [step size control](https://diffeq.sciml.ai/stable/basics/common_solver_opts/) in adaptive stepsize ODE algorithms. They are usually chosen by trial-and-error in real applications.
102
+
100
103
We plot the observable $\langle X \rangle$ during the evolution.
101
104
```julia
105
+
# this code block shows how to plot the expectation value of X
The package also contains several other closed-system solvers.
128
134
#### Von Neumann equation
129
-
Von Neumann equation is the "Schrodinger" equation for density matrices
135
+
The Von Neumann equation is the "Schrodinger" equation for density matrices:
130
136
131
137
$$\dot{\rho} = -it_f[H(s), \rho] \ .$$
132
138
133
-
Even though Von Neumann equation is equivalent to the Schrodinger equation, it is sometimes numerically more stable than the Schrodinger equation. Users is encouraged to try to solve it using different algorithms.
139
+
Even though the Von Neumann equation is equivalent to the Schrodinger equation, it is sometimes numerically more stable than the Schrodinger equation. Users are encouraged to try to solve it using different algorithms.
@@ -315,7 +321,7 @@ using `solve_unitary`. The ODE form of the problem is
315
321
316
322
$$\dot{U} = -i t_f H(s) U \ .$$
317
323
318
-
Again, although this is in principle equivalent to Schrondinger/Von Neumann equation, the unitary becomes handy in certain cases, e.g. when solving the Redfeild equation.
324
+
Although this is in principle equivalent to Schrodinger/Von Neumann equation, the unitary becomes handy in certain cases, e.g., when solving the Redfield equation.
Copy file name to clipboardexpand all lines: notebook/introduction/01-closed_system.ipynb
+9-9
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
{
4
4
"cell_type": "markdown",
5
5
"source": [
6
-
"## Close System Examples\nThis notebook will get you started with HOQST by introducing you to the functionality for solving colsed-system equations.\n\n### Define the Hamiltonin\nThe first step is to define an Hamiltonian. In this tutorial we focus on a 2-level system with the following Hamiltonian\n\n$$H(s) = - \\sigma_z$$\n\nwhere $s= t/t_f$ is the dimensionless time and $t_f$ is the total evolution time. We use a constant Hamiltonian so the simulation results can be trivially confirmed. The syntax is the same for timedependent Hamiltonians. Let's first define the Hamiltonian by:"
6
+
"## Closed-system Examples\nThis notebook will get you started with HOQST by introducing you to the functionality for solving closed-system equations.\n\n### Define the Hamiltonian\nThe first step is to define a Hamiltonian. In this tutorial, we focus on a 2-level system with the following Hamiltonian:\n\n$$H(s) = - \\sigma_z$$\n\nwhere $s= t/t_f$ is the dimensionless time and $t_f$ is the total evolution time. We use the constant Hamiltonian so that the simulation results can be trivially confirmed. The syntax is the same for time-dependent Hamiltonians. Let's first define the Hamiltonian by:"
7
7
],
8
8
"metadata": {}
9
9
},
@@ -19,7 +19,7 @@
19
19
{
20
20
"cell_type": "markdown",
21
21
"source": [
22
-
"In this example, we use the `DenseHamiltonian` object. The syntax is the same for other type of Hamiltonians.\n\nThe closed-system evolution is completely specified by the Hamiltonian and the initial state. We can combine them into a single `Annealing` object by:"
22
+
"In this example, we use the `DenseHamiltonian` [type](https://docs.julialang.org/en/v1/manual/types/#man-types). It means the underlying data structure of this Hamiltonian type is [Julia array](https://docs.julialang.org/en/v1/manual/arrays/). There exists a different Hamiltonian type named `SparseHamiltonian` that relies on [sparse array](https://docs.julialang.org/en/v1/stdlib/SparseArrays/) as its internal data structure. Sparsity can only provide performance improvement when the system size is large. So, as a rule of thumb, users should only consider using `SparseHamiltonian` when the system size is larger than 10 qubits. \n\nThe closed-system evolution is completely specified by the Hamiltonian and the initial state. We can combine them into a single `Annealing` object by:"
23
23
],
24
24
"metadata": {}
25
25
},
@@ -35,7 +35,7 @@
35
35
{
36
36
"cell_type": "markdown",
37
37
"source": [
38
-
"The initial state in above code block is\n$$\\lvert \\phi(0) \\rangle = \\lvert + \\rangle \\ .$$\n\nWe will consider three variants of the closed-system equations in this tutorial.\n\n### Schrodinger equation\nWe start with the Schrodinger equation\n\\begin{equation}\n \\lvert \\dot{\\phi} \\rangle = -i t_f H(s) \\lvert \\phi \\rangle \\ .\n\\end{equation}\n\nTo solve the this differential equation, we need to choose a proper algortihm. HOQST relies on `OrdinaryDiffEq.jl` as the low level solver, which support a large collection of [algorithms](https://docs.sciml.ai/latest/solvers/ode_solve/). We do not guarantee compatibilities to every solver in this list. Users can try specific algorithms if they are interested. We provide a list of algorithms we tested and recommended here:\n\n1. The default Tsitouras 5/4 Runge-Kutta method(Tsit5()).\n\n This is the default method in `OrdinaryDiffEq` and works well in most cases.\n\n2. A second order A-B-L-S-stable one-step ESDIRK method(TRBDF2()).\n\n This is the method widely used in large scale classical circuit simulations. Because this method has order of 2, it is recommended to use smaller error tolerance comparing with other higher order methods.\n \n3. A simple linear exponential method(LinearExponential()).\n\n This method simply discretize the Hamiltonian and do matrix exponential for each interval.\n \n4. Adaptive exponential Rosenbrock methods(Exprb32()/Exprb43()).\n\n This method belongs to the adaptive exponential Runge-Kutta method family.\n \nIt is important to notice that, method 3 and 4 are exponential methods which would preserve the norm of the state vectors. To solve our the Schrodinger equation we use the function `solve_schrodinger`."
38
+
"The initial state in above code block is\n$$\\lvert \\phi(0) \\rangle = \\lvert + \\rangle \\ .$$\n\nWe will consider three variants of the closed-system equations in this tutorial.\n\n### Schrodinger equation\nWe start with the Schrodinger equation\n\\begin{equation}\n \\lvert \\dot{\\phi} \\rangle = -i t_f H(s) \\lvert \\phi \\rangle \\ .\n\\end{equation}\n\nTo solve this differential equation, we need to choose a proper algorithm. HOQST relies on `OrdinaryDiffEq.jl` as the low-level solver, which supports a large collection of [algorithms](https://docs.sciml.ai/latest/solvers/ode_solve/). We do not guarantee compatibilities to every solver in this list. Users can try specific algorithms if they are interested. We provide a list of algorithms we tested and recommended here:\n\n1. The default Tsitouras 5/4 Runge-Kutta method(Tsit5()).\n\n This is the default method in `OrdinaryDiffEq` and works well in most cases.\n\n2. A second-order A-B-L-S-stable one-step ESDIRK method(TRBDF2()).\n\n This is the method widely used in large scale classical circuit simulations. Because this is a second-order method, it is recommended to use smaller error tolerance comparing with other higher-order methods.\n \n3. A simple linear exponential method(LinearExponential()).\n\n This method discretizes the Hamiltonian and does the matrix exponential for each interval.\n \n4. Adaptive exponential Rosenbrock methods(Exprb32()/Exprb43()).\n\n This method belongs to the adaptive exponential Runge-Kutta method family.\n \nIt is important to notice that methods 3 and 4 are exponential methods that are supposed to preserve the state vectors' norm. To solve the Schrodinger equation, we use the function `solve_schrodinger`:"
39
39
],
40
40
"metadata": {}
41
41
},
@@ -51,23 +51,23 @@
51
51
{
52
52
"cell_type": "markdown",
53
53
"source": [
54
-
"We plot the observable $\\langle X \\rangle$ during the evolution."
54
+
"In the above code block, the keyword arguments `abstol` and `reltol` are the absolute and relative error tolerances for [step size control](https://diffeq.sciml.ai/stable/basics/common_solver_opts/) in adaptive stepsize ODE algorithms. They are usually chosen by trial-and-error in real applications. \n\nWe plot the observable $\\langle X \\rangle$ during the evolution."
"# this code block shows how to plot the expectation value of X\nt_list = range(0,tf,length=100)\ntsit = []\ntrbdf = []\nlinexp = []\nexprb32 = []\nfor s in t_list\n # sol_tsit(s)'*σx*sol_tsit(s) calculates the \n # expectation value <ψ(s)|X|ψ(s)>\n push!(tsit, real(sol_tsit(s)'*σx*sol_tsit(s)))\n push!(trbdf, real(sol_trbdf(s)'*σx*sol_trbdf(s)))\n push!(linexp, real(sol_linexp(s)'*σx*sol_linexp(s)))\n push!(exprb32, real(sol_exprb32(s)'*σx*sol_exprb32(s)))\nend\nscatter(t_list[1:3:end], tsit[1:3:end], label=\"Tsit\", marker=:+, markersize=8)\nscatter!(t_list[2:3:end], trbdf[2:3:end], label=\"TRBDF\")\nscatter!(t_list[3:3:end], linexp[3:3:end], label=\"LinExp\", marker=:d)\nplot!(t_list, exprb32, label=\"Exprb\", linestyle=:dash)\nxlabel!(\"t (ns)\")\nylabel!(\"<X>\")\ntitle!(\"Free Evolution\")"
63
63
],
64
64
"metadata": {},
65
65
"execution_count": null
66
66
},
67
67
{
68
68
"cell_type": "markdown",
69
69
"source": [
70
-
"### Other close system equations\nThe package also contains several other closed-system solvers.\n#### Von Neumann equation\nVon Neumann equation is the \"Schrodinger\" equation for density matrices\n\n$$\\dot{\\rho} = -it_f[H(s), \\rho] \\ .$$\n\nEven though Von Neumann equation is equivalent to the Schrodinger equation, it is sometimes numerically more stable than the Schrodinger equation. Users is encouraged to try to solve it using different algorithms."
70
+
"### Other close system equations\nThe package also contains several other closed-system solvers.\n#### Von Neumann equation\nThe Von Neumann equation is the \"Schrodinger\" equation for density matrices:\n\n$$\\dot{\\rho} = -it_f[H(s), \\rho] \\ .$$\n\nEven though the Von Neumann equation is equivalent to the Schrodinger equation, it is sometimes numerically more stable than the Schrodinger equation. Users are encouraged to try to solve it using different algorithms."
71
71
],
72
72
"metadata": {}
73
73
},
@@ -83,7 +83,7 @@
83
83
{
84
84
"cell_type": "markdown",
85
85
"source": [
86
-
"As shown below, the solution given by the solver is the density matrix instead of state vector:"
86
+
"As shown below, the solution given by the solver is the density matrix instead of the state vector:"
87
87
],
88
88
"metadata": {}
89
89
},
@@ -131,7 +131,7 @@
131
131
{
132
132
"cell_type": "markdown",
133
133
"source": [
134
-
"We can again plot the $\\langle X \\rangle$ for different methods"
134
+
"We can again plot the $\\langle X \\rangle$ for different methods:"
135
135
],
136
136
"metadata": {}
137
137
},
@@ -147,7 +147,7 @@
147
147
{
148
148
"cell_type": "markdown",
149
149
"source": [
150
-
"#### Unitary\nLastly, we can also solve the unitary\n\n$$U(s) = T_+ \\exp\\bigg\\{ -i t_f \\int_0^s H(s') \\mathrm{d}s' \\bigg\\}$$\n\nusing `solve_unitary`. The ODE form of the problem is\n\n$$\\dot{U} = -i t_f H(s) U \\ .$$\n\nAgain, although this is in principle equivalent to Schrondinger/Von Neumann equation, the unitary becomes handy in certain cases, e.g. when solving the Redfeild equation."
150
+
"#### Unitary\nLastly, we can also solve the unitary\n\n$$U(s) = T_+ \\exp\\bigg\\{ -i t_f \\int_0^s H(s') \\mathrm{d}s' \\bigg\\}$$\n\nusing `solve_unitary`. The ODE form of the problem is\n\n$$\\dot{U} = -i t_f H(s) U \\ .$$\n\nAlthough this is in principle equivalent to Schrodinger/Von Neumann equation, the unitary becomes handy in certain cases, e.g., when solving the Redfield equation."
0 commit comments