Skip to content
Merged
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
21 changes: 20 additions & 1 deletion src/interfaces/state.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ QuantumPropagators.Interfaces.supports_inplace) is `true` (read-write vector):

Note: When `supports_inplace(state)` is `true`, `similar(state)` is already
required to return the *same type* as `state` (see above). The vector interface
checks are weaker and complementary.
checks are weaker and complementary. However, in all cases:

* `convert(typeof(state), mutable_state)` for `mutable_state = similar(state)`
must be defined.

It is strongly recommended to always support immutable operations (also for
mutable states)
Expand Down Expand Up @@ -558,6 +561,22 @@ function check_state(
success = false
end

try
mutable_state = similar(state)
converted = convert(typeof(state), mutable_state)
if !(converted isa typeof(state))
quiet ||
@error "$(px)`convert($(typeof(state)), similar(state))` must return a `$(typeof(state))`, not $(typeof(converted))"
success = false
end
catch exc
quiet || @error(
"$(px)`convert(typeof(state), mutable_state)` for `mutable_state = similar(state)` must be defined.",
exception = (exc, catch_abbreviated_backtrace())
)
success = false
end

if supports_inplace(state)

try
Expand Down
Loading