Skip to content

Commit 87369e5

Browse files
committed
Add comparison with propagator
1 parent 7c89900 commit 87369e5

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

tutorials-v5/time-evolution/023_dysolve_propagator.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Let's start by importing the necessary packages.
2626

2727
```python
2828
from qutip.solver.dysolve_propagator import DysolvePropagator, dysolve_propagator
29-
from qutip import qeye, sigmax, sigmay, sigmaz, tensor, about
29+
from qutip.solver.propagator import propagator
30+
from qutip import qeye, sigmax, sigmay, sigmaz, tensor, CoreOptions, about
3031
```
3132

3233
### One qubit example using `DysolvePropagator`
@@ -39,7 +40,7 @@ X = sigmax()
3940
omega = 10.0
4041
```
4142

42-
Some options can be defined. `max_order` will be the order of approximation used when calculating a propagator. The higher this integer is, the more precise the results will be (at a cost of taking more time to calculate). `a_tol` is simply the absolute tolerance used in the calculations. Finally, a time propagator can be computed using subpropagators of time increment `max_dt`. Let's say `max_dt` is set to 0.25, then the propagator $U(1, 0)$ will come from the multiplication of supropagators $U(0.25, 0)$, $U(0.5, 0.25)$, $U(0.75, 0.5)$ and $U(1, 0.75)$. This allows for more precise results when the evolution is over a long period of time. In our case, let's keep `a_tol` and `max_dt` to their default value, but let's change `max_order`.
43+
Some options can be defined. `max_order` will be the order of approximation used when calculating a propagator. The higher this integer is, the more precise the results will be (at a cost of taking more time to calculate). `a_tol` is simply the absolute tolerance used in the calculations. Finally, a time propagator can be computed using subpropagators of time increment `max_dt`. Let's say `max_dt` is set to 0.25, then the propagator $U(1, 0)$ will come from the multiplication of the supropagators $U(0.25, 0)$, $U(0.5, 0.25)$, $U(0.75, 0.5)$ and $U(1, 0.75)$. This allows for more precise results when the evolution is over a long period of time. In our case, let's keep `a_tol` and `max_dt` to their default value, but let's change `max_order`.
4344

4445
```python
4546
options = {'max_order': 5}
@@ -59,7 +60,23 @@ t_f = 1
5960
U = dy(t_f, t_i)
6061
```
6162

62-
This returns a single time propagator $U(t_f, t_i)$.
63+
This returns a single time propagator $U(t_f = 1, t_i = -1)$. To verify that the $U$ is correct, let's compare it to what `propagator` would return.
64+
65+
```python
66+
# Solve using propagator
67+
def X_coeff(t, omega):
68+
return np.cos(omega * t)
69+
70+
H = [H_0, [X, X_coeff]]
71+
args = {'omega': omega}
72+
prop = propagator(
73+
H, [t_i, t_f], args=args, options={"atol": 1e-10, "rtol": 1e-8}
74+
)
75+
76+
# Comparison
77+
with CoreOptions(atol=1e-10, rtol=1e-6):
78+
assert U == prop[1]
79+
```
6380

6481
### Two qubits example with `dysolve_propagator`
6582

@@ -81,6 +98,24 @@ times = [-0.1, 0, 0.1]
8198
Us = dysolve_propagator(H_0, X, omega, times)
8299
```
83100

101+
Again, let's compare the results with `propagator`.
102+
103+
```python
104+
# Solve using propagator
105+
def X_coeff(t, omega):
106+
return np.cos(omega * t)
107+
108+
H = [H_0, [X, X_coeff]]
109+
args = {'omega': omega}
110+
props = propagator(
111+
H, times, args=args, options={"atol": 1e-10, "rtol": 1e-8}
112+
)
113+
114+
# Comparison
115+
with CoreOptions(atol=1e-10, rtol=1e-6):
116+
assert Us == props
117+
```
118+
84119
### About
85120

86121
```python

0 commit comments

Comments
 (0)