From 81f570b8adaea23231953e62af05f402b9a4e31b Mon Sep 17 00:00:00 2001 From: Jinguo Liu Date: Mon, 22 Aug 2022 09:13:46 +0800 Subject: [PATCH] fix time-evolution, yao0.8 (#78) Co-authored-by: Rogerluo --- Project.toml | 2 +- src/CUDApatch.jl | 4 ++++ src/register.jl | 8 +++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index fbc3e4d..08fe9c4 100644 --- a/Project.toml +++ b/Project.toml @@ -17,7 +17,7 @@ Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c" [compat] BitBasis = "0.8" CUDA = "3.10" -LuxurySparse = "0.6, 0.7" +LuxurySparse = "0.7" Reexport = "0.2, 1" StaticArrays = "0.12, 1" StatsBase = "0.33" diff --git a/src/CUDApatch.jl b/src/CUDApatch.jl index 1fd05dc..e898db2 100644 --- a/src/CUDApatch.jl +++ b/src/CUDApatch.jl @@ -58,3 +58,7 @@ function getindex(A::AbstractVector, B::DenseCuArray{<:Integer}) end YaoBlocks.AD.as_scalar(x::DenseCuArray) = Array(x)[] + +# patch for ExponentialUtilities +YaoBlocks.ExponentialUtilities.compatible_multiplicative_operand(::CuArray, source::AbstractArray) = CuArray(source) +YaoBlocks.ExponentialUtilities.compatible_multiplicative_operand(::CuArray, source::CuArray) = source \ No newline at end of file diff --git a/src/register.jl b/src/register.jl index d36b1dc..7e7d1f2 100644 --- a/src/register.jl +++ b/src/register.jl @@ -7,7 +7,7 @@ cpu(reg::DensityMatrix{D}) where D = DensityMatrix{D}(Array(reg.state)) const AbstractCuArrayReg{D, T, MT} = AbstractArrayReg{D, T, MT} where MT<:DenseCuArray const CuArrayReg{D, T, MT} = ArrayReg{D, T, MT} where MT<:DenseCuArray const CuBatchedArrayReg{D, T, MT} = BatchedArrayReg{D, T, MT} where MT<:DenseCuArray -const CuDensityMatrix{D, T, MT} = DensityMatrix{D, T, MT} where MT<:DenseCuArray +const CuDensityMatrix{D, T, MT} = DensityMatrix{D, T, MT} where MT<:DenseCuMatrix function batch_normalize!(s::DenseCuArray, p::Real=2) p!=2 && throw(ArgumentError("p must be 2!")) @@ -273,9 +273,15 @@ for FUNC in [:measure!, :measure!] end =# +function YaoBlocks.expect(op::AbstractAdd, dm::CuDensityMatrix) + sum(x->expect(x, dm), subblocks(op)) +end function YaoBlocks.expect(op::AbstractBlock, dm::CuDensityMatrix{D}) where D return tr(apply(ArrayReg{D}(dm.state), op).state) end +function expect(op::Scale, reg::DensityMatrix) + factor(op) * expect(content(op), reg) +end measure( ::ComputationalBasis,