Skip to content

Commit dcc0ed2

Browse files
committed
fix scalar
1 parent ccbb5c4 commit dcc0ed2

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Application/to_eincode.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function z_tensor(n::Int, factor::Number)
1515
shape = (fill(2, n)...,)
1616
out = zeros(ComplexF64, shape...)
1717
out[1] = 1
18-
out[fill(2, n)...] = factor
18+
out[fill(2, n)...] += factor
1919
return out
2020
end
2121

src/ZX/rules/scalar.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ end
2727

2828
function rewrite!(::ScalarRule, zxg::Union{ZXGraph{T, P}, ZXDiagram{T, P}}, vs::Vector{T}) where {T, P}
2929
@inbounds v = vs[1]
30-
# TODO: track global scalar
30+
p = phase(zxg, v)
31+
if is_zero_phase(p)
32+
add_power!(zxg, 2)
33+
elseif is_pi_phase(p)
34+
add_power!(zxg, -Inf)
35+
elseif p == Phase(1//2)
36+
add_power!(zxg, 1)
37+
add_global_phase!(zxg, Phase(1//4))
38+
elseif p == Phase(3//2)
39+
add_power!(zxg, 1)
40+
add_global_phase!(zxg, Phase(-1//4))
41+
else
42+
@warn "Ignoring non-Clifford scalar spider with phase $p"
43+
end
3144
rem_spider!(zxg, v)
3245
return zxg
3346
end

0 commit comments

Comments
 (0)