some fixes to krisi's project
This commit is contained in:
parent
6ae883d818
commit
908efa9b76
@ -58,7 +58,7 @@ def test_krisi_measurement_2():
|
|||||||
|
|
||||||
def test_krisi_measurement_3():
|
def test_krisi_measurement_3():
|
||||||
iterations = 400
|
iterations = 400
|
||||||
beta = np.pi * 0.62
|
beta = np.pi + 0.62
|
||||||
|
|
||||||
CASE_ID_ID = "id_id"
|
CASE_ID_ID = "id_id"
|
||||||
CASE_ID_ORT = "id_ort"
|
CASE_ID_ORT = "id_ort"
|
||||||
@ -67,14 +67,14 @@ def test_krisi_measurement_3():
|
|||||||
|
|
||||||
case_choices = [CASE_ID_ID, CASE_ID_ORT, CASE_ORT_ID, CASE_ORT_ORT]
|
case_choices = [CASE_ID_ID, CASE_ID_ORT, CASE_ORT_ID, CASE_ORT_ORT]
|
||||||
|
|
||||||
b_0 = State(1 / np.sqrt(2) * (s("|100>") - s("|010>")))
|
b_0 = State((1 / np.sqrt(2)) * (s("|100>") + s("|010>")))
|
||||||
b_1 = State(1 / np.sqrt(2) * (s("|011>") - s("|101>")))
|
b_1 = State((1 / np.sqrt(2)) * (s("|011>") + s("|101>")))
|
||||||
basis = [
|
basis = [
|
||||||
s("|000>"),
|
s("|000>"),
|
||||||
State(np.cos(beta) * b_0 + np.sin(beta) * s("|001>")),
|
State(np.cos(beta) * b_0 + np.sin(beta) * s("|001>")),
|
||||||
State(-np.sin(beta) * b_0 + np.cos(beta) * s("|001>")),
|
State(-np.sin(beta) * b_0 + np.cos(beta) * s("|001>")),
|
||||||
b_0,
|
State((1 / np.sqrt(2)) * (s("|100>") - s("|010>"))),
|
||||||
b_1,
|
State((1 / np.sqrt(2)) * (s("|011>") - s("|101>"))),
|
||||||
State(np.cos(beta) * b_1 + np.sin(beta) * s("|001>")),
|
State(np.cos(beta) * b_1 + np.sin(beta) * s("|001>")),
|
||||||
State(-np.sin(beta) * b_1 + np.cos(beta) * s("|001>")),
|
State(-np.sin(beta) * b_1 + np.cos(beta) * s("|001>")),
|
||||||
s("|111>"),
|
s("|111>"),
|
||||||
@ -107,16 +107,18 @@ def test_krisi_measurement_3():
|
|||||||
q2 = State.from_bloch_angles(theta1, phi1)
|
q2 = State.from_bloch_angles(theta1, phi1)
|
||||||
|
|
||||||
q1q2_st = State(q1*q2)
|
q1q2_st = State(q1*q2)
|
||||||
meas1 = q1q2_st.measure(basis=bell_basis)
|
# meas1 = q1q2_st.measure(basis=bell_basis)
|
||||||
if meas1 == '11':
|
# if meas1 == '11':
|
||||||
return 'discarded'
|
# return 'discarded'
|
||||||
|
|
||||||
# TODO:
|
P_minus = b_psi_m.x(b_psi_m)
|
||||||
# P_minus = b_psi_m.x(b_psi_m)
|
|
||||||
P_s = b_psi_p.x(b_psi_p) + b_phi_m.x(b_phi_m) + b_phi_p.x(b_phi_p)
|
P_s = b_psi_p.x(b_psi_p) + b_phi_m.x(b_phi_m) + b_phi_p.x(b_phi_p)
|
||||||
|
|
||||||
meas = MeasurementOperator(P_s.m).on(q1q2_st)
|
# vec = MeasurementOperator(P_minus.m).on(q1q2_st)
|
||||||
post_state = State(State.normalize(meas))
|
# if np.all(vec.m.transpose() == np.zeros(4)):
|
||||||
|
# return 'identical'
|
||||||
|
vec2 = MeasurementOperator(P_s.m).on(q1q2_st)
|
||||||
|
post_state = State(State.normalize(vec2))
|
||||||
|
|
||||||
if case == CASE_ID_ID:
|
if case == CASE_ID_ID:
|
||||||
assert post_state == q1q2_st
|
assert post_state == q1q2_st
|
||||||
@ -124,7 +126,7 @@ def test_krisi_measurement_3():
|
|||||||
assert post_state != q1q2_st
|
assert post_state != q1q2_st
|
||||||
|
|
||||||
q3 = State.from_bloch_angles(theta2, phi2)
|
q3 = State.from_bloch_angles(theta2, phi2)
|
||||||
meas = State(State.normalize(post_state * q3)).measure(basis=basis)
|
meas = State(post_state * q3).measure(basis=basis)
|
||||||
|
|
||||||
# # TODO: This part measures the first two qubits in Bell basis, then:
|
# # TODO: This part measures the first two qubits in Bell basis, then:
|
||||||
# # 1. constructs a new pure state
|
# # 1. constructs a new pure state
|
||||||
|
6
lib.py
6
lib.py
@ -353,8 +353,10 @@ class State(Vector):
|
|||||||
else:
|
else:
|
||||||
# TODO: This may be wrong
|
# TODO: This may be wrong
|
||||||
# normalize the weights
|
# normalize the weights
|
||||||
weights = list(np.array(weights) / sum(weights))
|
weights_sum = np.sum(weights)
|
||||||
assert np.isclose(sum(weights), 1.0)
|
if not np.isclose(weights_sum, 1.0):
|
||||||
|
weights = list(np.array(weights) / weights_sum)
|
||||||
|
assert np.isclose(np.sum(weights), 1.0)
|
||||||
|
|
||||||
format_str = self.get_fmt_of_element()
|
format_str = self.get_fmt_of_element()
|
||||||
choices = empty_choices + [format_str.format(i) for i in
|
choices = empty_choices + [format_str.format(i) for i in
|
||||||
|
Loading…
Reference in New Issue
Block a user