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 Yao extension by properly transposing matrices #212

Merged
merged 6 commits into from
Oct 1, 2024
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 ext/TenetYaoBlocksExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Tenet.Quantum(circuit::AbstractBlock)
map(occupied_locs(gate)) do l
from, to = last(wire[l]), Tenet.nextindex!(gen)
push!(wire[l], to)
(from, to)
(to, from)
end,
)

Expand Down
32 changes: 32 additions & 0 deletions test/integration/YaoBlocks_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,36 @@

@test issetequal(sites(tn), [site"1", site"2", site"1'", site"2'"])
@test Tenet.ntensors(tn) == 2

@testset "GHZ Circuit" begin
circuit_GHZ = chain(n_qubits, put(1 => Yao.H), Yao.control(1, 2 => Yao.X), Yao.control(2, 3 => Yao.X))

quantum_circuit = Quantum(circuit_GHZ)

zeros = Quantum(Product(fill([1, 0], n_qubits))) #|000>
ones = Quantum(Product(fill([0, 1], n_qubits))) #|111>

expected_value = Tenet.contract(merge(zeros, quantum_circuit, ones')) # <111|circuit|000>
@test only(expected_value) ≈ 1 / √2

SV_Yao = apply!(zero_state(n_qubits), circuit_GHZ) # circuit|000>
@test only(statevec(ArrayReg(bit"111"))' * statevec(SV_Yao)) ≈ 1 / √2
end
mofeing marked this conversation as resolved.
Show resolved Hide resolved

@testset "two-qubit gate" begin
U = matblock(rand(ComplexF64, 4, 4); tag="U")
circuit = chain(2, put((1, 2) => U))
psi = zero_state(2)
apply!(psi, circuit)

quantum_circuit = Quantum(circuit)
zeros = Quantum(Product(fill([1, 0], 2))) #|00>
ones = Quantum(Product(fill([0, 1], 2))) #|11>

expected_value = Tenet.contract(merge(zeros, quantum_circuit, ones')) # <11|circuit|00>

SV_Yao = apply!(zero_state(2), circuit) # circuit|00>

@test only(expected_value) ≈ only(statevec(ArrayReg(bit"11"))' * statevec(SV_Yao))
end
end
Loading