Skip to content

Commit fd2026b

Browse files
committed
adapt new add_spider! interface
1 parent e1d9beb commit fd2026b

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

src/ZX/algorithms/circuit_extraction.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function ancilla_extraction(zxg::Union{ZXGraph, ZXCircuit})
3030
v = ins[i]
3131
@inbounds u = neighbors(nzxg, v)[1]
3232
if !is_hadamard(nzxg, u, v)
33-
insert_spider!(nzxg, u, v, SpiderType.Z)
33+
insert_spider!(nzxg, u, v, SpiderType.Z, zero(phase(nzxg, v)), [EdgeType.SIM, EdgeType.SIM])
3434
end
3535
end
3636

@@ -212,7 +212,7 @@ function circuit_extraction(zxg::Union{ZXGraph{T, P}, ZXCircuit{T, P}}) where {T
212212
for v1 in Ins
213213
@inbounds v2 = neighbors(nzxg, v1)[1]
214214
if !is_hadamard(nzxg, v1, v2)
215-
insert_spider!(nzxg, v1, v2, SpiderType.Z)
215+
insert_spider!(nzxg, v1, v2, SpiderType.Z, zero(phase(nzxg, v2)), [EdgeType.SIM, EdgeType.SIM])
216216
end
217217
end
218218
@inbounds frontier = [neighbors(nzxg, v)[1] for v in Outs]

src/ZX/implementations/zx_circuit/circuit_interface.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ function _push_single_qubit_gate!(circ::ZXCircuit{T, P}, loc::T;
1515
@assert spider_type(circ, out_id) === SpiderType.Out "Output spider at location $loc is not of type Out."
1616
@inbounds bound_id = neighbors(circ, out_id)[1]
1717
et = edge_type(circ, bound_id, out_id)
18-
v = insert_spider!(circ, bound_id, out_id, stype, phase)
19-
set_edge_type!(circ, v, bound_id, et)
20-
set_edge_type!(circ, v, out_id, EdgeType.SIM)
18+
v = insert_spider!(circ, bound_id, out_id, stype, phase, [et, EdgeType.SIM])
2119
return v
2220
end
2321

@@ -27,9 +25,7 @@ function _push_first_single_qubit_gate!(circ::ZXCircuit{T, P}, loc::T;
2725
@assert spider_type(circ, in_id) === SpiderType.In "Input spider at location $loc is not of type In."
2826
@inbounds bound_id = neighbors(circ, in_id)[1]
2927
et = edge_type(circ, in_id, bound_id)
30-
v = insert_spider!(circ, in_id, bound_id, stype, phase)
31-
set_edge_type!(circ, bound_id, v, et)
32-
set_edge_type!(circ, v, in_id, EdgeType.SIM)
28+
v = insert_spider!(circ, in_id, bound_id, stype, phase, [EdgeType.SIM, et])
3329
return v
3430
end
3531

src/ZX/rules/hedge.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ end
1919
function rewrite!(::HEdgeRule, zxg::ZXGraph{T, P}, vs::Vector{T}) where {T, P}
2020
@inbounds v1, v2 = vs
2121
rem_edge!(zxg, v1, v2)
22-
u = add_spider!(zxg, SpiderType.H, zero(P), [v1, v2])
23-
set_edge_type!(zxg, v1, u, EdgeType.SIM)
24-
set_edge_type!(zxg, u, v2, EdgeType.SIM)
22+
add_spider!(zxg, SpiderType.H, zero(P), [v1, v2], [EdgeType.SIM, EdgeType.SIM])
2523
return zxg
2624
end

src/ZX/rules/pivot_boundary.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ end
4343
function rewrite!(::PivotBoundaryRule, zxg::ZXGraph{T, P}, vs::Vector{T}) where {T, P}
4444
u, v, b = vs
4545
et = edge_type(zxg, v, b)
46-
new_v = insert_spider!(zxg, v, b)[1]
47-
w = insert_spider!(zxg, v, new_v)
48-
set_edge_type!(zxg, b, new_v, et)
46+
new_v = insert_spider!(zxg, v, b, SpiderType.Z, zero(P), [EdgeType.SIM, et])
47+
w = insert_spider!(zxg, v, new_v, SpiderType.Z, zero(P), [EdgeType.HAD, EdgeType.HAD])
4948
set_phase!(zxg, new_v, phase(zxg, v))
5049
set_phase!(zxg, v, zero(P))
5150
rewrite!(Pivot1Rule(), zxg, Match{T}([min(u, v), max(u, v)]))
@@ -61,15 +60,14 @@ function rewrite!(::PivotBoundaryRule, circ::ZXCircuit{T, P}, vs::Vector{T}) whe
6160
v_master = neighbors(circ.master, v_bound_master)[1]
6261
# TODO: add edge type here for simple edges
6362
if is_hadamard(circ, new_v, b)
64-
w_master = insert_spider!(circ.master, v_bound_master, v_master, SpiderType.Z)[1]
63+
w_master = insert_spider!(circ.master, v_bound_master, v_master, SpiderType.Z, zero(P),
64+
[EdgeType.HAD, EdgeType.HAD])
6565
else
6666
# TODO: add edge type here for simple edges
67-
w_master = insert_spider!(circ.master, v_bound_master, v_master, SpiderType.X)[1]
67+
w_master = insert_spider!(circ.master, v_bound_master, v_master, SpiderType.X, zero(P),
68+
[EdgeType.SIM, EdgeType.SIM])
6869
end
6970
circ.phase_ids[w] = (w_master, 1)
70-
end
71-
72-
if !isnothing(circ.master)
7371
circ.phase_ids[new_v] = circ.phase_ids[v]
7472
delete!(circ.phase_ids, v)
7573
end

0 commit comments

Comments
 (0)