Skip to content

Commit

Permalink
Merge pull request #15 from QuantumBFS/add_valscale_support
Browse files Browse the repository at this point in the history
Fixed expect(::ScaleBlock) if the factor is `Val{<number>}`
  • Loading branch information
jlbosse authored Sep 2, 2024
2 parents 8b840d0 + d2af835 commit 2a72bf6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FLOYao"
uuid = "6d9310a3-f1d0-41b7-8edb-11c1cf57cd2d"
authors = ["janlukas.bosse <[email protected]> and contributors"]
version = "1.4.2"
version = "1.4.3"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion src/expect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ for BT in [:AbstractAdd, :(KronBlock{2}), :(PutBlock{2,1,ZGate})]
end
end

Yao.expect(op::Scale, reg::MajoranaReg) = op.alpha * Yao.expect(op.content, reg)
Yao.expect(op::Scale, reg::MajoranaReg) = Yao.factor(op) * Yao.expect(Yao.content(op), reg)
#
# ----------------------
# Calculating fidelities
Expand Down
15 changes: 10 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,21 @@ end
θ = π/8
xxg = kron(nq, 1 => X, 2 => Y)
rg = rot(xxg, θ)
push!(circuit, rg)
push!(circuit, rg)
push!(circuit, put(nq, 3=>Rz(0.5)))
push!(circuit, rg)
push!(circuit, rg)

θ = π/5
xxg = kron(nq, 2 => X, 3 => Z, 4 => Y)
rg = rot(xxg, θ)
rz = put(nq, 3 => Rz(θ))
push!(circuit, rg)
push!(circuit, rg)
push!(circuit, put(nq, 3=>Rz(0.5)))
push!(circuit, put(nq, (2,3) => FSWAP))
push!(circuit, put(nq, 1=>Z))
push!(circuit, put(nq, 4=>X))
push!(circuit, rg)
push!(circuit, rz)
push!(circuit, rg)
push!(circuit, rz)

ham = put(nq, 1=>Z) + 2kron(nq, 1=>X, 2=>Z, 3=>Z, 4=>X) + 3.5put(nq, 2=>Z)
mreg = FLOYao.zero_state(nq)
Expand All @@ -265,6 +265,11 @@ end
aeval = expect(ham[end], areg)
@test meval aeval

op = -kron(nq, 2=>X, 3=>X)
meval = expect(op, mreg)
aeval = expect(op, areg)
@test meval aeval

# test kronblocks inside put blocks
ham = put(nq, 2:3 => kron(2, 1 => X, 2 => Y)) + 2put(nq, 1:2 => kron(2, 1 => X, 2 => Y))
meval = expect(ham, mreg)
Expand Down

0 comments on commit 2a72bf6

Please sign in to comment.