Skip to content

Commit db80e1b

Browse files
Minor changes
1 parent 3a7382e commit db80e1b

File tree

2 files changed

+18
-39
lines changed

2 files changed

+18
-39
lines changed

src/qobj/quantum_object_evo.jl

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,9 @@ end
9292

9393
# Make the QuantumObjectEvolution, with the option to pre-multiply by a scalar
9494
function QuantumObjectEvolution(op_func_list::Tuple, α = true)
95-
op = _get_op_func_first(op_func_list)
95+
op, data = _generate_data(op_func_list, α)
9696
dims = op.dims
9797
type = op.type
98-
T = eltype(op)
99-
100-
data = _generate_data(T, op_func_list, α)
10198

10299
# Preallocate the SciMLOperator cache using a dense vector as a reference
103100
v0 = sparse_to_dense(similar(op.data, size(op, 1)))
@@ -109,12 +106,14 @@ end
109106
QuantumObjectEvolution(op::QuantumObject, α = true) =
110107
QuantumObjectEvolution(MatrixOperator* op.data), op.type, op.dims)
111108

112-
@generated function _get_op_func_first(op_func_list::Tuple)
109+
@generated function _generate_data(op_func_list::Tuple, α)
113110
op_func_list_types = op_func_list.parameters
114111
N = length(op_func_list_types)
115-
T = ()
112+
116113
dims_expr = ()
117114
first_op = nothing
115+
data_expr = :(0)
116+
118117
for i in 1:N
119118
op_func_type = op_func_list_types[i]
120119
if op_func_type <: Tuple
@@ -126,8 +125,8 @@ QuantumObjectEvolution(op::QuantumObject, α = true) =
126125
"The first element must be a Operator or SuperOperator, and the second element must be a function.",
127126
),
128127
)
128+
129129
data_type = op_type.parameters[1]
130-
T = (T..., eltype(data_type))
131130
dims_expr = (dims_expr..., :(op_func_list[$i][1].dims))
132131
if i == 1
133132
first_op = :(op_func_list[$i][1])
@@ -136,47 +135,34 @@ QuantumObjectEvolution(op::QuantumObject, α = true) =
136135
op_type = op_func_type
137136
(isoper(op_type) || issuper(op_type)) ||
138137
throw(ArgumentError("The element must be a Operator or SuperOperator."))
138+
139139
data_type = op_type.parameters[1]
140-
T = (T..., eltype(data_type))
141140
dims_expr = (dims_expr..., :(op_func_list[$i].dims))
141+
142142
if i == 1
143143
first_op = :(op_func_list[$i])
144144
end
145145
end
146+
data_expr = :($data_expr + _make_SciMLOperator(op_func_list[$i], α))
146147
end
147148

148-
length(unique(T)) == 1 || throw(ArgumentError("The types of the operators must be the same."))
149-
150149
quote
151150
dims = tuple($(dims_expr...))
152151

153152
length(unique(dims)) == 1 || throw(ArgumentError("The dimensions of the operators must be the same."))
154153

155-
return $first_op
154+
return $first_op, $data_expr
156155
end
157156
end
158157

159-
@generated function _generate_data(T, op_func_list::Tuple, α)
160-
op_func_list_types = op_func_list.parameters
161-
N = length(op_func_list_types)
162-
data_expr = :(0)
163-
for i in 1:N
164-
op_func_type = op_func_list_types[i]
165-
if op_func_type <: Tuple
166-
data_expr = :(
167-
$data_expr +
168-
ScalarOperator(zero(T), op_func_list[$i][2]) * MatrixOperator* op_func_list[$i][1].data)
169-
)
170-
else
171-
data_expr = :($data_expr + MatrixOperator* op_func_list[$i].data))
172-
end
173-
end
174-
175-
quote
176-
return $data_expr
177-
end
158+
function _make_SciMLOperator(op_func::Tuple, α)
159+
T = eltype(op_func[1])
160+
update_func = (a, u, p, t) -> op_func[2](p, t)
161+
return ScalarOperator(zero(T), update_func) * MatrixOperator* op_func[1].data)
178162
end
179163

164+
_make_SciMLOperator(op::QuantumObject, α) = MatrixOperator* op.data)
165+
180166
function (QO::QuantumObjectEvolution)(p, t)
181167
# We put 0 in the place of `u` because the time-dependence doesn't depend on the state
182168
update_coefficients!(QO.data, 0, p, t)

src/time_evolution/sesolve.jl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function _save_func_sesolve(integrator)
44
internal_params = integrator.p
55
progr = internal_params.progr
66

7-
if internal_params.is_empty_e_ops
7+
if !internal_params.is_empty_e_ops
88
e_ops = internal_params.e_ops
99
expvals = internal_params.expvals
1010

@@ -16,13 +16,6 @@ function _save_func_sesolve(integrator)
1616
return u_modified!(integrator, false)
1717
end
1818

19-
sesolve_ti_dudt!(du, u, p, t) = mul!(du, p.U, u)
20-
function sesolve_td_dudt!(du, u, p, t)
21-
mul!(du, p.U, u)
22-
H_t = p.H_t(t, p)
23-
return mul!(du, H_t, u, -1im, 1)
24-
end
25-
2619
function _generate_sesolve_kwargs_with_callback(t_l, kwargs)
2720
cb1 = PresetTimeCallback(t_l, _save_func_sesolve, save_positions = (false, false))
2821
kwargs2 =
@@ -132,7 +125,7 @@ function sesolveProblem(
132125
kwargs3 = _generate_sesolve_kwargs(e_ops, makeVal(progress_bar), t_l, kwargs2)
133126

134127
tspan = (t_l[1], t_l[end])
135-
return ODEProblem{true}(U, ϕ0, tspan, p; kwargs3...)
128+
return ODEProblem{true,FullSpecialize}(U, ϕ0, tspan, p; kwargs3...)
136129
end
137130

138131
@doc raw"""

0 commit comments

Comments
 (0)