global phase doesn't matter - the only thing is measuring

This commit is contained in:
Daniel Tsvetkov 2020-02-03 10:10:55 +01:00
parent bd2fced73e
commit 8811e7b8e3
2 changed files with 29 additions and 20 deletions

View File

@ -174,13 +174,13 @@ class State(Vector):
return theta, phi
def rotate_x(self, theta):
return self | Rx(theta)
return Rx(theta).on(self)
def rotate_y(self, theta):
return self | Ry(theta)
return Ry(theta).on(self)
def rotate_z(self, theta):
return self | Rz(theta)
return Rz(theta).on(self)
def __repr__(self):
if not self.name:
@ -529,34 +529,34 @@ Z = UnitaryOperator([[1, 0],
name="Z")
# TODO: These are not the rotations that are specified commonly e.g. in
# TODO: These are rotations that are specified commonly e.g. in
# https://www.quantum-inspire.com/kbase/rotation-operators/
# http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere-rotations.pdf
# and elsewhere.
# --------------
# Multiply the bellow ones by the following to get the commonly given
# X = [[1, -1j][-1j, 1]]
# Y = [[1, -1j][-1j, 1]]
# Z = [[1j, 0][1j, 0]]
# and elsewhere DO NOT equate X, Y and Z for theta=np.pi
# ??????????????????????????????????????????????????????
def Rx(theta):
return UnitaryOperator([[np.cos(theta / 2), np.sin(theta / 2)],
[np.sin(theta / 2), np.cos(theta / 2)]],
return UnitaryOperator([[np.cos(theta / 2), -1j * np.sin(theta / 2)],
[-1j * np.sin(theta / 2), np.cos(theta / 2)]],
name="Rx")
def Ry(theta):
return UnitaryOperator([[np.cos(theta / 2), -1j * np.sin(theta / 2)],
[1j * np.sin(theta / 2), np.cos(theta / 2)]],
return UnitaryOperator([[np.cos(theta / 2), -np.sin(theta / 2)],
[np.sin(theta / 2), np.cos(theta / 2)]],
name="Ry")
def Rz(theta):
return UnitaryOperator([[1j * np.power(np.e, -1j * theta / 2), 0],
[0, 1j * np.power(np.e, 1j * theta / 2)]],
return UnitaryOperator([[np.power(np.e, -1j * theta / 2), 0],
[0, np.power(np.e, 1j * theta / 2)]],
name="Rz")
# def unitary(alpha, vector:Vector, theta):
# return np.exp(1j * alpha)
H = UnitaryOperator([[1 / np.sqrt(2), 1 / np.sqrt(2)],
[1 / np.sqrt(2), -1 / np.sqrt(2)], ],
name="H")
@ -628,10 +628,19 @@ def test_unitary_hermitian():
assert_raises(TypeError, "Not a Unitary matrix", UnitaryMatrix, not_u_not_h)
def abs_squared(x):
return np.abs(x) ** 2
def testRotPauli():
assert Rx(np.pi) == X
assert Ry(np.pi) == Y
assert Rz(np.pi) == Z
# From http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere.pdf
# / slide 11:
# However, the only measurable quantities are the probabilities
# |α|**2 and |β|**2, so multiplying the state by an arbitrary factor
# exp(iγ) (a global phase) has no observable consequences
assert np.allclose(abs_squared(Rx(np.pi).m), abs_squared(X.m))
assert np.allclose(abs_squared(Ry(np.pi).m), abs_squared(Y.m))
assert np.allclose(abs_squared(Rz(np.pi).m), abs_squared(Z.m))
def test():
@ -1007,6 +1016,6 @@ def test_quantum_processor():
if __name__ == "__main__":
test()
pp(_p.get_bloch_coordinates())
# pp(_p.get_bloch_coordinates())
# test_to_from_angles()
# test_quantum_processor()

BIN
papers/bloch-sphere.pdf Normal file

Binary file not shown.