Skip to content

Commit

Permalink
Removed unnecessary type parameters and type piracy (#80)
Browse files Browse the repository at this point in the history
* Removed type piracy and unnecessary type parameters

* removed deprecated call to `repeat`

* restored newlines at end of files

* Removed expect(::Scale, ::CuDensityMatrix)

because it was exactly the same logic as expect(::Scale, ::DensityMatrix)
  • Loading branch information
jlbosse authored May 18, 2023
1 parent 3d4fa58 commit e3d9de2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/instructs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ for RG in [:Rx, :Ry, :Rz]
::Val{$(QuoteNode(RG))},
locs::Tuple{Int},
theta::Number
) where {T, N}
) where {T}
YaoArrayRegister.instruct!(Val(2), state, Val($(QuoteNode(RG))), locs, (), (), theta)
return state
end
Expand Down
6 changes: 2 additions & 4 deletions src/register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,12 @@ 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,
reg::CuDensityMatrix,
::AllLocs;
nshots::Int = 1,
rng::AbstractRNG = Random.GLOBAL_RNG,
) = YaoArrayRegister._measure(rng, basis(reg), Array(reg |> probs), nshots)
) = YaoArrayRegister._measure(rng, basis(reg), Array(reg |> probs), nshots)

7 changes: 4 additions & 3 deletions test/register.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ end
@test size(res) == (32,)
@test res2 == res

reg = repeat(ArrayReg([1,-1+0im]/sqrt(2.0)), 10) |> cu
reg = clone(ArrayReg([1,-1+0im]/sqrt(2.0)), 10) |> cu
@test measure!(X, reg) |> mean -1
reg = repeat(ArrayReg([1.0,0+0im]), 1000)
reg = clone(ArrayReg([1.0,0+0im]), 1000)
@test abs(measure!(X, reg) |> mean) < 0.1
end

Expand Down Expand Up @@ -135,4 +135,5 @@ end
reg = cughz_state(3; nbatch=b)
@test cpu(reg) ghz_state(3; nbatch=b) && reg isa AbstractCuArrayReg
end
end
end

0 comments on commit e3d9de2

Please sign in to comment.