Skip to content

Commit

Permalink
fix time-evolution, yao0.8 (#78)
Browse files Browse the repository at this point in the history
Co-authored-by: Rogerluo <rogerluo.rl18@gmail.com>
  • Loading branch information
GiggleLiu and Roger-luo committed Aug 22, 2022
1 parent 4b7d759 commit 81f570b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
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

2 comments on commit 81f570b

@Roger-luo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Released via Ion

@JuliaRegistrator register branch=master

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/66719

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.5 -m "<description of version>" 81f570b8adaea23231953e62af05f402b9a4e31b
git push origin v0.3.5

Please sign in to comment.