Skip to content

Commit b4cda36

Browse files
committed
sMY and sMRY
1 parent 9663a0f commit b4cda36

File tree

1 file changed

+65
-36
lines changed

1 file changed

+65
-36
lines changed

src/backtrajectory.jl

Lines changed: 65 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ function backtrajectory(circuit::Vector{<:AbstractOperation}, n::Int)
1818
apply_right!(T, op)
1919
elseif op isa sMX
2020
push!(results, do_MX!(T, op))
21-
# elseif op isa sMY
22-
# push!(results, do_MY!(T, op))
21+
elseif op isa sMY
22+
push!(results, do_MY!(T, op))
2323
elseif op isa sMZ
2424
push!(results, do_MZ!(T, op))
25+
elseif op isa sMRX
26+
push!(results, do_MRX!(T, op))
27+
elseif op isa sMRY
28+
push!(results, do_MRY!(T, op))
29+
elseif op isa sMRZ
30+
push!(results, do_MRZ!(T, op))
2531
else
2632
error("Unsupported operation: $(typeof(op))")
2733
end
@@ -31,57 +37,78 @@ function backtrajectory(circuit::Vector{<:AbstractOperation}, n::Int)
3137
end
3238

3339

34-
# function do_MY!(T, op::sMY)
35-
# collapse_y!(T, op.qubit)
36-
# return eval_y_obs(T, q)
37-
# end
38-
39-
# function collapse_y!(T, q::Int)
40-
# if is_deterministic_y(T, q)
41-
# return
42-
# end
43-
44-
# apply!(T, sHadamardYZ(q); phases=true)
45-
# collapse_z!(T, q)
46-
# apply!(T, sHadamardYZ(q); phases=true)
47-
# end
48-
49-
# function eval_y_obs(T, q::Int)
50-
# result = T[q]
51-
# log_i = mul_right!(result, T[nqubits(T)+q])
52-
# log_i += 1
53-
# @assert log_i & 1 == 0
54-
# if log_i & 2
55-
# result.phase[]
56-
# end
57-
# return result
58-
# end
59-
6040
function do_MX!(T, op::sMX)
6141
collapse_x!(T, op.qubit)
6242
return phases(tab(T))[op.qubit] == 0x00 ? 1 : -1
6343
end
6444

65-
# function do_MRX!(T, op::sMRX)
66-
# collapse_x!(T, op.qubit)
67-
# result = phases(tab(T))[op.qubit] == 0x00 ? 1 : -1
68-
# # change the signs to zero
69-
# return result
70-
# end
45+
function do_MRX!(T, op::sMRX)
46+
collapse_x!(T, op.qubit)
47+
result = phases(tab(T))[op.qubit] == 0x00 ? 1 : -1
48+
phases(tab(T))[op.qubit] = 0x00
49+
phases(tab(T))[nqubits(T)+op.qubit] = 0x00
50+
return result
51+
end
7152

7253
function collapse_x!(T, q::Int)
7354
if is_deterministic_x(T, q)
7455
return
7556
end
76-
57+
7758
apply_right!(T, sHadamard(q))
7859
collapse_z!(T, q)
7960
apply_right!(T, sHadamard(q))
8061
end
8162

63+
function do_MY!(T, op::sMY)
64+
collapse_y!(T, op.qubit)
65+
return eval_y_obs(T, op.qubit).phase[] == 0x00 ? 1 : -1
66+
end
67+
68+
function do_MRY!(T, op::sMRY)
69+
collapse_y!(T, op.qubit)
70+
result = eval_y_obs(T, op.qubit).phase[] == 0x00 ? 1 : -1
71+
if result == -1
72+
phases(tab(T))[nqubits(T)+op.qubit] ⊻= 0x02
73+
end
74+
return result
75+
end
76+
77+
function collapse_y!(T, q::Int)
78+
if is_deterministic_y(T, q)
79+
return
80+
end
81+
82+
apply_right!(T, sHadamardYZ(q))
83+
collapse_z!(T, q)
84+
apply_right!(T, sHadamardYZ(q))
85+
end
86+
87+
function eval_y_obs(T, q::Int)
88+
result = T[q]
89+
@assert result.phase[] & 0x01 == 0
90+
og_result_sign = result.phase[]
91+
mul_right!(result, T[nqubits(T)+q]; phases=Val(true))
92+
log_i = result.phase[] + 1
93+
@assert log_i & 0x01 == 0
94+
if log_i & 2 != 0
95+
og_result_sign ⊻= 0x02
96+
end
97+
result.phase[] = og_result_sign
98+
return result
99+
end
100+
82101
function do_MZ!(T, op::sMZ)
83102
collapse_z!(T, op.qubit)
84-
return phases(tab(T))[op.qubit+nqubits(T)] == 0x00 ? 1 : -1
103+
return phases(tab(T))[nqubits(T)+op.qubit] == 0x00 ? 1 : -1
104+
end
105+
106+
function do_MRZ!(T, op::sMRZ)
107+
collapse_z!(T, op.qubit)
108+
result = phases(tab(T))[nqubits(T)+op.qubit] == 0x00 ? 1 : -1
109+
phases(tab(T))[op.qubit] = 0x00
110+
phases(tab(T))[nqubits(T)+op.qubit] = 0x00
111+
return result
85112
end
86113

87114
function collapse_z!(T, q::Int)
@@ -148,6 +175,8 @@ function backtrajectory(circuit::Vector{<:AbstractOperation})
148175
n = max(n, op.q1, op.q2)
149176
elseif op isa AbstractMeasurement
150177
n = max(n, op.qubit)
178+
elseif typeof(op) in [sMRX, sMRY, sMRZ]
179+
n = max(n, op.qubit)
151180
else
152181
error("Unsupported operation: $(typeof(op))")
153182
end

0 commit comments

Comments
 (0)