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 return theta, phi
def rotate_x(self, theta): def rotate_x(self, theta):
return self | Rx(theta) return Rx(theta).on(self)
def rotate_y(self, theta): def rotate_y(self, theta):
return self | Ry(theta) return Ry(theta).on(self)
def rotate_z(self, theta): def rotate_z(self, theta):
return self | Rz(theta) return Rz(theta).on(self)
def __repr__(self): def __repr__(self):
if not self.name: if not self.name:
@ -529,34 +529,34 @@ Z = UnitaryOperator([[1, 0],
name="Z") 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/ # https://www.quantum-inspire.com/kbase/rotation-operators/
# http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere-rotations.pdf # http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere-rotations.pdf
# and elsewhere. # and elsewhere DO NOT equate X, Y and Z for theta=np.pi
# -------------- # ??????????????????????????????????????????????????????
# 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]]
def Rx(theta): def Rx(theta):
return UnitaryOperator([[np.cos(theta / 2), np.sin(theta / 2)], return UnitaryOperator([[np.cos(theta / 2), -1j * np.sin(theta / 2)],
[np.sin(theta / 2), np.cos(theta / 2)]], [-1j * np.sin(theta / 2), np.cos(theta / 2)]],
name="Rx") name="Rx")
def Ry(theta): def Ry(theta):
return UnitaryOperator([[np.cos(theta / 2), -1j * np.sin(theta / 2)], return UnitaryOperator([[np.cos(theta / 2), -np.sin(theta / 2)],
[1j * np.sin(theta / 2), np.cos(theta / 2)]], [np.sin(theta / 2), np.cos(theta / 2)]],
name="Ry") name="Ry")
def Rz(theta): def Rz(theta):
return UnitaryOperator([[1j * np.power(np.e, -1j * theta / 2), 0], return UnitaryOperator([[np.power(np.e, -1j * theta / 2), 0],
[0, 1j * np.power(np.e, 1j * theta / 2)]], [0, np.power(np.e, 1j * theta / 2)]],
name="Rz") name="Rz")
# def unitary(alpha, vector:Vector, theta):
# return np.exp(1j * alpha)
H = UnitaryOperator([[1 / np.sqrt(2), 1 / np.sqrt(2)], H = UnitaryOperator([[1 / np.sqrt(2), 1 / np.sqrt(2)],
[1 / np.sqrt(2), -1 / np.sqrt(2)], ], [1 / np.sqrt(2), -1 / np.sqrt(2)], ],
name="H") name="H")
@ -628,10 +628,19 @@ def test_unitary_hermitian():
assert_raises(TypeError, "Not a Unitary matrix", UnitaryMatrix, not_u_not_h) assert_raises(TypeError, "Not a Unitary matrix", UnitaryMatrix, not_u_not_h)
def abs_squared(x):
return np.abs(x) ** 2
def testRotPauli(): def testRotPauli():
assert Rx(np.pi) == X # From http://www.vcpc.univie.ac.at/~ian/hotlist/qc/talks/bloch-sphere.pdf
assert Ry(np.pi) == Y # / slide 11:
assert Rz(np.pi) == Z # 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(): def test():
@ -1007,6 +1016,6 @@ def test_quantum_processor():
if __name__ == "__main__": if __name__ == "__main__":
test() test()
pp(_p.get_bloch_coordinates()) # pp(_p.get_bloch_coordinates())
# test_to_from_angles() # test_to_from_angles()
# test_quantum_processor() # test_quantum_processor()

BIN
papers/bloch-sphere.pdf Normal file

Binary file not shown.