Skip to content

Commit 94a5a1c

Browse files
committed
docs: fix regex filters for floating-point numbers
Fix the doctest filters so that array of complex numbers are matched correctly, including the whitespace at the beginning of the line added by Julia in the output display.
1 parent 887290c commit 94a5a1c

3 files changed

Lines changed: 25 additions & 23 deletions

File tree

docs/src/examples/tdvp1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ starting with a state with alternating magnetisation,
2121

2222
```math
2323
\ket{\psi_0} = \ket{\spinup} \otimes \ket{\spindown} \otimes \ket{\spinup}
24-
\otimes \ket{\spindown} \otimes \dotsb {} ```
24+
\otimes \ket{\spindown} \otimes \dotsb {}
25+
```
2526

2627
Let's review what we need to set up in order to use the `tdvp1!` method. First
2728
of all, we define the state and Hamiltonian objects in Julia, with ITensor.
@@ -69,7 +70,6 @@ ExpValueCallback
6970
Operators: Sz(1), Sz(2) and Sz(3)
7071
No measurements performed
7172
72-
7373
```
7474

7575
The last argument of `ExpValueCallback` determines how frequently the

docs/src/examples/time_dependent_tdvp.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ julia> function time_dependent_exp(
9494
)
9595
ψₜ, info = exponentiate(H(current_time), time_step, ψ₀; kwargs...)
9696
return ψₜ, info
97-
end
98-
time_dependent_exp (generic function with 1 method)
99-
97+
end;
10098
```
10199

102100
The first argument `TimeDependentSum` is a struct, defined in `ITensorMPS` (but
@@ -124,9 +122,7 @@ julia> function time_dependent_solver(PHs::ProjMPOSum, time_step, ψ₀; kwargs.
124122
return time_dependent_exp(
125123
TimeDependentSum(fs, PHs), time_step, ψ₀; ishermitian=true, kwargs...
126124
)
127-
end
128-
time_dependent_solver (generic function with 1 method)
129-
125+
end;
130126
```
131127

132128
This function will be used inside `tdvp1!`, precisely in the `tdvp_site_update!`
@@ -152,7 +148,10 @@ Now we set the variables related to time, and the callback operator:
152148
```jldoctest time_dependent_tdvp
153149
julia> dt = 0.01; tmax = 2T;
154150
155-
julia> cb = ExpValueCallback("Nup(1,5),Ndn(1,5)", s, dt);
151+
julia> cb = ExpValueCallback("Nup(1,5),Ndn(1,5)", s, dt)
152+
ExpValueCallback
153+
Operators: Nup(1), Nup(5), Ndn(1) and Ndn(5)
154+
No measurements performed
156155
```
157156

158157
One last thing: during the execution of `time_dependent_exp`, inside the stack

docs/src/reference/callback_obj.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ julia> ITensors.op(::OpName"X", ::SiteType"Boson", s::Index) = 1/sqrt(2) * op("a
102102
Now we can use it in our callback by adding it to the list, for example:
103103

104104
```jldoctest callback_obj
105-
julia> cb = ExpValueCallback("N(1,2,3,4),X(1,2,3,4)", sites, 10dt);
105+
julia> cb = ExpValueCallback("N(1,2,3,4),X(1,2,3,4)", sites, 10dt)
106+
ExpValueCallback
107+
Operators: N(1), N(2), N(3), N(4), X(1), X(2), X(3) and X(4)
108+
No measurements performed
106109
107110
```
108111

@@ -114,7 +117,7 @@ the `"N(1,2,3,4),X(1,2,3,4)"` operators.
114117
Let's set up a Hamiltonian operator and run a quick simulation with TDVP1 (see
115118
the [TDVP1 tutorial](@ref "Standard TDVP1")):
116119

117-
```jldoctest callback_obj
120+
```jldoctest callback_obj; filter = r"id=\d+" => "id=###"
118121
julia> v = MPS(sites, n -> n == 1 ? "1" : "0");
119122
120123
julia> v = enlargelinks(v, 4);
@@ -137,7 +140,7 @@ julia> tdvp1!(v, H, dt, 10; callback=cb, progress=false);
137140

138141
By invoking `cb` we can see that there is new information:
139142

140-
```jldoctest callback_obj
143+
```jldoctest callback_obj; filter = [r"9.99\d+" => "10.0", r"0.99\d+" => "1.0"]
141144
julia> cb
142145
ExpValueCallback
143146
Operators: N(1), N(2), N(3), N(4), X(1), X(2), X(3) and X(4)
@@ -152,25 +155,25 @@ The computed expectation values can be accessed by calling the `expvalues`
152155
method on the callback: the result is a dictionary where each local operator is
153156
assigned the series of its expectation values.
154157

155-
```jldoctest callback_obj
158+
```jldoctest callback_obj; filter = r"\[\d\.0\+0\.0im, .*" => "[#.0+0.0im, ###"
156159
julia> expvalues(cb)
157160
OrderedCollections.OrderedDict{LocalOperator, Vector{ComplexF64}} with 8 entries:
158-
N(1) => [1.0+0.0im, 0.332612+0.0im, 0.00109072+0.0im, 0.00850228+0.0im, 0.003
159-
X(1) => [0.0+0.0im, -1.13453e-6-4.60006e-23im, -3.93457e-6-2.03123e-22im, -2.
160-
N(2) => [0.0+0.0im, 0.497967+0.0im, 0.132586+0.0im, 0.0262118+0.0im, 0.003191
161-
X(2) => [0.0+0.0im, -1.61758e-6+6.61744e-23im, -2.2168e-6-2.60208e-18im, -2.1
162-
N(3) => [0.0+0.0im, 0.149637+0.0im, 0.416359+0.0im, 0.0131695+0.0im, 0.047656
163-
X(3) => [0.0+0.0im, -1.14256e-6+3.43722e-22im, -2.63261e-5-4.06683e-20im, -2.
164-
N(4) => [0.0+0.0im, 0.0184514+0.0im, 0.316095+0.0im, 0.227534+0.0im, 0.011087
165-
X(4) => [0.0+0.0im, 4.27215e-5-2.05802e-21im, 0.000124825-1.03762e-20im, 5.01
161+
N(1) => [1.0+0.0im, 0.332612+0.0im, 0.00109051+0.0im, 0.0085059+0.0im, 0.0034
162+
X(1) => [0.0+0.0im, -4.93851e-9-1.55657e-24im, 1.54546e-7-6.4159e-24im, 1.083
163+
N(2) => [0.0+0.0im, 0.497967-2.52076e-23im, 0.132589-7.85081e-19im, 0.0262158
164+
X(2) => [0.0+0.0im, -1.73335e-9-1.0679e-23im, 6.49531e-7+1.56158e-20im, 2.344
165+
N(3) => [0.0+0.0im, 0.149637-2.63998e-23im, 0.416356-2.54984e-23im, 0.0131673
166+
X(3) => [0.0+0.0im, -3.70391e-7+4.54031e-23im, -3.44816e-7-9.89546e-22im, 3.5
167+
N(4) => [0.0+0.0im, 0.0184914+7.90412e-20im, 0.316137-1.95008e-18im, 0.227405
168+
X(4) => [0.0+0.0im, -4.55872e-6+1.36907e-23im, 6.11274e-6-1.46214e-22im, 8.46
166169
167170
```
168171

169172
The time series for individual operators can be accessed via the `expvalues(cb,
170173
lop)` syntax, where `lop` is either a `LocalOperator` or a string that defines a
171174
single `LocalOperator`.
172175

173-
```jldoctest callback_obj
176+
```jldoctest callback_obj; filter = r"^(\s+)?[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)? [-+] [-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?im"m => "### + ###im"
174177
julia> expvalues(cb, LocalOperator(3 => "N"))
175178
11-element Vector{ComplexF64}:
176179
0.0 + 0.0im
@@ -205,7 +208,7 @@ Finally, we can access the time series relative to the state norm (which is the
205208
actual 2-norm of the state, the trace, or another relevant quantity depending on
206209
the chosen time-evolution algorithm).
207210

208-
```jldoctest callback_obj
211+
```jldoctest callback_obj; filter = r"^(\s+)?[-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)? [-+] [-+]?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?im"m => "### + ###im"
209212
julia> measurements_norm(cb)
210213
11-element Vector{ComplexF64}:
211214
1.0 + 0.0im

0 commit comments

Comments
 (0)