3636)
3737from qctrlopencontrols .exceptions import ArgumentsValueError
3838
39+ SIGMA_X = np .array ([[0.0 , 1.0 ], [1.0 , 0.0 ]])
40+ SIGMA_Y = np .array ([[0.0 , - 1.0j ], [1.0j , 0.0 ]])
41+ SIGMA_Z = np .array ([[1.0 , 0.0 ], [0.0 , - 1.0 ]])
42+
3943
4044def test_ramsey ():
4145
@@ -672,16 +676,13 @@ def test_attribute_values():
672676
673677def _pulses_produce_identity (sequence ):
674678 """
675- Tests if the pulses of a DDS sequence produce an identity in absence of noise.
679+ Tests if the pulses of a DDS sequence produce an identity or Z rotation in absence of noise.
676680 We check this by creating the unitary of each pulse and then multiplying them
677681 by each other to check the complete evolution.
678682 """
679- sigma_x = np .array ([[0.0 , 1.0 ], [1.0 , 0.0 ]])
680- sigma_y = np .array ([[0.0 , - 1.0j ], [1.0j , 0.0 ]])
681- sigma_z = np .array ([[1.0 , 0.0 ], [0.0 , - 1.0 ]])
682683
683684 # The unitary evolution due to an instantaneous pulse can be written as
684- # U = cos(|n|) I -i sin(|n|) *(n_x sigma_x + n_y sigma_y + n_z sigma_z )/|n|
685+ # U = cos(|n|) I -i sin(|n|) *(n_x SIGMA_x + n_y SIGMA_y + n_z SIGMA_z )/|n|
685686 # where n is a vector with components
686687 # n_x = rabi * cos(azimuthal)/2
687688 # n_y = rabi * sin(azimuthal)/2
@@ -697,9 +698,9 @@ def _pulses_produce_identity(sequence):
697698 mod_n = np .sqrt (n_x ** 2 + n_y ** 2 + n_z ** 2 )
698699 unitary = (
699700 np .cos (mod_n ) * np .identity (2 )
700- - 1.0j * (np .sin (mod_n ) * n_x / mod_n ) * sigma_x
701- - 1.0j * (np .sin (mod_n ) * n_y / mod_n ) * sigma_y
702- - 1.0j * (np .sin (mod_n ) * n_z / mod_n ) * sigma_z
701+ - 1.0j * (np .sin (mod_n ) * n_x / mod_n ) * SIGMA_X
702+ - 1.0j * (np .sin (mod_n ) * n_y / mod_n ) * SIGMA_Y
703+ - 1.0j * (np .sin (mod_n ) * n_z / mod_n ) * SIGMA_Z
703704 )
704705 matrix_product = np .matmul (unitary , matrix_product )
705706
@@ -708,7 +709,9 @@ def _pulses_produce_identity(sequence):
708709
709710 expected_matrix_product = np .identity (2 )
710711
711- return np .allclose (matrix_product , expected_matrix_product )
712+ return np .allclose (matrix_product , expected_matrix_product ) or np .allclose (
713+ SIGMA_Z .dot (matrix_product ), expected_matrix_product
714+ )
712715
713716
714717def test_if_ramsey_sequence_is_identity ():
@@ -762,7 +765,7 @@ def test_if_carr_purcell_sequence_with_even_pulses_is_identity():
762765def test_if_cpmg_sequence_with_odd_pulses_is_identity ():
763766 """
764767 Tests if the product of the pulses in a CPMG sequence with pre/post
765- pi/2-pulses is an identity, when the number of pulses is odd.
768+ pi/2-pulses and an extra Z rotation is an identity, when the number of pulses is odd.
766769 """
767770 odd_cpmg_sequence = new_predefined_dds (
768771 scheme = CARR_PURCELL_MEIBOOM_GILL ,
@@ -792,7 +795,7 @@ def test_if_cpmg_sequence_with_even_pulses_is_identity():
792795def test_if_uhrig_sequence_with_odd_pulses_is_identity ():
793796 """
794797 Tests if the product of the pulses in an Uhrig sequence with pre/post
795- pi/2-pulses is an identity, when the number of pulses is odd.
798+ pi/2-pulses and an extra Z rotation is an identity, when the number of pulses is odd.
796799 """
797800 odd_uhrig_sequence = new_predefined_dds (
798801 scheme = UHRIG_SINGLE_AXIS ,
@@ -924,7 +927,8 @@ def test_if_quadratic_sequence_with_even_pulses_is_identity():
924927def test_if_quadratic_sequence_with_odd_inner_pulses_is_identity ():
925928 """
926929 Tests if the product of the pulses in a quadratic sequence with pre/post
927- pi/2-pulses is an identity, when the total number of inner pulses is odd.
930+ pi/2-pulses and an extra rotation is an identity, when the total number
931+ of inner pulses is odd.
928932 """
929933 inner_odd_quadratic_sequence = new_predefined_dds (
930934 scheme = QUADRATIC ,
0 commit comments