Fixed failing doctests

This commit is contained in:
Nihal K P 2023-08-14 19:22:46 +05:30
parent 896c1b1fb1
commit f84031096c

View File

@ -27,7 +27,7 @@ def paulix_gate(input_realvalue: float, input_imaginaryvalue: float) -> list[flo
Usage : Usage :
>>> paulix_gate(2,3) >>> paulix_gate(2,3)
array([3 2]) array([3, 2])
""" """
paulix_matrix = np.array([[0, 1], [1, 0]]) paulix_matrix = np.array([[0, 1], [1, 0]])
complex_input = np.array([input_realvalue, input_imaginaryvalue]) complex_input = np.array([input_realvalue, input_imaginaryvalue])
@ -46,7 +46,7 @@ def pauliy_gate(input_realvalue: float, input_imaginaryvalue: float) -> list[flo
Usage : Usage :
>>> pauliy_gate(5,8) >>> pauliy_gate(5,8)
array([0.+8.j 0.-5.j]) array([0.+8.j, 0.-5.j])
""" """
i = complex(0, 1) i = complex(0, 1)
pauliy_matrix = [[0, i], [-1 * i, 0]] pauliy_matrix = [[0, i], [-1 * i, 0]]
@ -66,7 +66,7 @@ def pauliz_gate(input_realvalue: float, input_imaginaryvalue: float) -> list[flo
Usage : Usage :
>>> pauliz_gate(4,1) >>> pauliz_gate(4,1)
array([ 4 -1]) array([ 4, -1])
""" """
pauliz_matrix = np.array([[1, 0], [0, -1]]) pauliz_matrix = np.array([[1, 0], [0, -1]])
complex_input = np.array([input_realvalue, input_imaginaryvalue]) complex_input = np.array([input_realvalue, input_imaginaryvalue])
@ -108,7 +108,7 @@ def phasefactor_of_input(
Usage : Usage :
>>> phasefactor_of_input(4,7,45) >>> phasefactor_of_input(4,7,45)
array([1.39737084e+20+0.j 2.44539897e+20+0.j]) array([1.39737084e+20+0.j, 2.44539897e+20+0.j])
""" """
iota = cmath.exp(alpha) iota = cmath.exp(alpha)
phasefactor = [[iota, 0], [0, iota]] phasefactor = [[iota, 0], [0, iota]]
@ -132,7 +132,7 @@ def phaseshift_of_input(
Usage : Usage :
>>> phaseshift_of_input(3,9,30) >>> phaseshift_of_input(3,9,30)
array([3.00000000e+00+0.j 9.61782712e+13+0.j]) array([3.00000000e+00+0.j, 9.61782712e+13+0.j])
""" """
iota = cmath.exp(alpha) iota = cmath.exp(alpha)
phase = [[1, 0], [0, iota]] phase = [[1, 0], [0, iota]]
@ -152,8 +152,7 @@ def hadamard_gate(input_realvalue: float, input_imaginaryvalue: float) -> list[f
Usage : Usage :
>>> hadamard_gate(5,9) >>> hadamard_gate(5,9)
array([ 9.89949494 -2.82842712] array([ 9.89949494, -2.82842712])
[1.+0.j 0.+0.j 0.+0.j 7.+0.j])
""" """
root_of_2 = 1.0 / math.sqrt(2) root_of_2 = 1.0 / math.sqrt(2)
hadamard_gate_matrix = np.array( hadamard_gate_matrix = np.array(
@ -180,7 +179,7 @@ def controlled_not_gate_in_0ket(
Usage : Usage :
>>> controlled_not_gate_in_0ket(1,7,4,8) >>> controlled_not_gate_in_0ket(1,7,4,8)
array([7 1 4 8]) array([7, 1, 4, 8])
""" """
controlled_not_gate_0ket_matrix = np.array( controlled_not_gate_0ket_matrix = np.array(
[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] [[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
@ -214,7 +213,7 @@ def controlled_not_gate(
Usage : Usage :
>>> controlled_not_gate(6,3,7,5) >>> controlled_not_gate(6,3,7,5)
array([6 3 5 7]) array([6, 3, 5, 7])
""" """
controlled_not_gate_matrix = np.array( controlled_not_gate_matrix = np.array(
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]
@ -247,7 +246,7 @@ def inverted_controlled_not_gate(
Usage : Usage :
>>> inverted_controlled_not_gate(8,4,9,6) >>> inverted_controlled_not_gate(8,4,9,6)
array([8 6 9 4]) array([8, 6, 9, 4])
""" """
inverted_controlled_not_gate_matrix = np.array( inverted_controlled_not_gate_matrix = np.array(
[[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]] [[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]
@ -283,7 +282,8 @@ def controlled_phase_multiplication(
Usage : Usage :
>>> controlled_phase_multiplication(3,2,5,1,10) >>> controlled_phase_multiplication(3,2,5,1,10)
array([3.00000000e+00+0.j 2.00000000e+00+0.j 1.10132329e+05+0.j array([3.00000000e+00+0.j, 2.00000000e+00+0.j,
1.10132329e+05+0.j,
2.20264658e+04+0.j]) 2.20264658e+04+0.j])
""" """
iota = cmath.exp(alpha) iota = cmath.exp(alpha)
@ -318,7 +318,7 @@ def swap_gate(
Usage : Usage :
>>> swap_gate(5,1,3,7) >>> swap_gate(5,1,3,7)
array([5 3 1 7]) array([5, 3, 1, 7])
""" """
swap_gate_matrix = np.array( swap_gate_matrix = np.array(
[[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]] [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]
@ -356,7 +356,7 @@ def spin_of_input(
Usage : Usage :
>>> spin_of_input(6,3,45,1,8,3) >>> spin_of_input(6,3,45,1,8,3)
array([-16.93201614+10.23066476j -50.61991392 -1.46152354j]) array([-16.93201614+10.23066476j, -50.61991392 -1.46152354j])
""" """
i = complex(0, 1) i = complex(0, 1)
spin_matrix = [ spin_matrix = [