Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/grad_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ end

_exp_prop_convert_state(::GradVector) = Vector{ComplexF64}


function Base.convert(
::Type{GradVector{num_controls,T2}},
Ψ̃::GradVector{num_controls,T1}
) where {T1,T2,num_controls}
# Used, e.g., for Cheby initialization
return GradVector{num_controls,T2}(
convert(T2, Ψ̃.state),
T2[convert(T2, Ψ′) for Ψ′ in Ψ̃.grad_states]
)
end


supports_inplace(::Type{GradVector{N,T}}) where {N,T} = supports_inplace(T)

supports_vector_interface(::Type{GradVector{N,T}}) where {N,T} =
Expand Down
14 changes: 13 additions & 1 deletion test/test_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using QuantumControl.Interfaces: check_generator
using QuantumPropagators.Interfaces:
check_state, check_operator, supports_matrix_interface, supports_vector_interface
using QuantumGradientGenerators: GradGenerator, GradVector, GradgenOperator
using StaticArrays: SVector, SMatrix
using StaticArrays: SVector, SMatrix, MVector
using LinearAlgebra: norm, dot, mul!, I


Expand All @@ -31,6 +31,18 @@ end

@test norm(2.2 * Ψ̃ - Ψ̃ * 2.2) < 1e-14

Ψ̃2 = similar(Ψ̃)
@test Ψ̃2 isa GradVector{2,<:MVector}

# We've had propagators use code like
#
# v0::ST = similar(Ψ::ST)
#
# which relies on being able to convert mutable types back to their
# immutable version
Ψ̃3 = convert(typeof(Ψ̃), Ψ̃2)
@test typeof(Ψ̃3) == typeof(Ψ̃)

end


Expand Down
Loading