Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix time-evolution, yao0.8 #78

Merged
merged 2 commits into from
Aug 22, 2022
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/CUDApatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion src/register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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!"))
Expand Down Expand Up @@ -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,
Expand Down