From 40ce5d09224fab03b6ab38f12e9b38d15e08d62a Mon Sep 17 00:00:00 2001 From: Michael Goerz Date: Tue, 24 Feb 2026 17:03:09 -0500 Subject: [PATCH] Add extension for ArrayInterface --- Project.toml | 7 +++++++ ...ntumGradientGeneratorsArrayInterfaceExt.jl | 20 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ext/QuantumGradientGeneratorsArrayInterfaceExt.jl diff --git a/Project.toml b/Project.toml index 536461a..3d4d4bb 100644 --- a/Project.toml +++ b/Project.toml @@ -9,7 +9,14 @@ QuantumControl = "8a270532-f23f-47a8-83a9-b33d10cad486" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +[weakdeps] +ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9" + +[extensions] +QuantumGradientGeneratorsArrayInterfaceExt = "ArrayInterface" + [compat] +ArrayInterface = "7.0" LinearAlgebra = "1" QuantumControl = ">=0.11.0" Random = "1" diff --git a/ext/QuantumGradientGeneratorsArrayInterfaceExt.jl b/ext/QuantumGradientGeneratorsArrayInterfaceExt.jl new file mode 100644 index 0000000..97ca68f --- /dev/null +++ b/ext/QuantumGradientGeneratorsArrayInterfaceExt.jl @@ -0,0 +1,20 @@ +module QuantumGradientGeneratorsArrayInterfaceExt + +import ArrayInterface +import QuantumGradientGenerators: GradVector +import QuantumControl.QuantumPropagators.Interfaces: supports_vector_interface + +# The following methods are necessary for `check_state`, because `similar` +# can return a `GradVector`, and the results of `similar` must be a mutable +# array. + +ArrayInterface.ismutable(::Type{GradVector{N,T}}) where {N,T} = + ArrayInterface.ismutable(T) && supports_vector_interface(T) + + +# Direct access to the elements of a `GradVector` is possible, but should be +# discouraged + +ArrayInterface.fast_scalar_indexing(::Type{<:GradVector}) = false + +end