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

convert ZXDiagram to tensor network #16

Closed
Roger-luo opened this issue May 26, 2020 · 3 comments
Closed

convert ZXDiagram to tensor network #16

Roger-luo opened this issue May 26, 2020 · 3 comments

Comments

@Roger-luo
Copy link
Member

No description provided.

@Roger-luo Roger-luo added this to the v0.1 milestone May 26, 2020
@Roger-luo Roger-luo removed this from the v0.1 milestone Jun 28, 2020
@GiggleLiu
Copy link
Member

GiggleLiu commented Aug 29, 2020

Might be useful in the future.

function ztensor(nleg::Int, α::T) where T<:Number
    shape = (fill(2, nleg)...,)
    factor = exp(im*α)
    out = zeros(typeof(factor), shape...)
    out[1] = one(typeof(factor))
    out[fill(2, nleg)...] = factor
    out
end

function xtensor(nleg::Int, α::T) where T<:Number
    pos = [1, 1]/sqrt(2)
    neg = [1, -1]/sqrt(2)
    shape = (fill(2, nleg)...,)
    reshape(reduce(kron, fill(pos, nleg)) + exp(im*α)*reduce(kron, fill(neg, nleg)), shape)
end

function htensor(nleg::Int, α::T) where T<:Number
    shape = (fill(2, nleg)...,)
    factor = exp(im*α)
    out = fill(one(typeof(factor)), shape)
    out[fill(2, nleg)...] = factor
    return out
end

@GiggleLiu
Copy link
Member

GiggleLiu commented Aug 29, 2020

The correspondence with Yao.jl

θ = 0.5
@test mat(Rz(θ) * phase/2))  ztensor(2, θ)
@test mat(Rx(θ) * phase/2))  xtensor(2, θ)
@test mat(H) .* sqrt(2)  htensor(2, π)
@test mat(shift(θ))  ztensor(2, θ)

Some identities

θ = 0.5
@test mat(Rz(θ) * Yao.phase/2))  ztensor(2, θ)
@test mat(shift(θ))  ztensor(2, θ)
@test mat(Rx(θ) * Yao.phase/2))  xtensor(2, θ)
@test mat(H) .* sqrt(2)  htensor(2, π)
@test mat(T)  ztensor(2, π/4)
@test mat(ConstGate.S)  ztensor(2, π/2)
@test mat(chain(ConstGate.Sdag, X, ConstGate.S))  mat(Y)
@test mat(T)  mat(Rz/4) * Yao.phase/8))
@test mat(ConstGate.S)  mat(Rz/2) * Yao.phase/4))

For more, see https://github.com/QuantumBFS/YaoZX.jl

@exAClior
Copy link
Collaborator

exAClior commented Aug 6, 2023

This is implemented in #93 albeit for zxw diagram. I will close this for now.

@exAClior exAClior closed this as completed Aug 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants