#NEWLINE# def test_measure_partial( ) : #NEWLINE# #INDENT# state = ( Qubit ( '01' ) + Qubit ( '10' ) ) #NEWLINE# assert ( measure_partial ( state , ( 0 , ) ) == [ ( Qubit ( '10' ) , Rational ( 1 , 2 ) ) , ( Qubit ( '01' ) , Rational ( 1 , 2 ) ) ] ) #NEWLINE# assert ( measure_partial ( state , ( 0 , ) ) == measure_partial ( state , ( 1 , ) ) [ : : ( - 1 ) ] ) #NEWLINE# state1 = ( ( ( sqrt ( 2 ) / sqrt ( 3 ) ) * Qubit ( '00001' ) ) + ( ( 1 / sqrt ( 3 ) ) * Qubit ( '11111' ) ) ) #NEWLINE# assert ( measure_partial ( state1 , ( 0 , ) ) == [ ( ( ( ( sqrt ( 2 ) / sqrt ( 3 ) ) * Qubit ( '00001' ) ) + ( ( 1 / sqrt ( 3 ) ) * Qubit ( '11111' ) ) ) , 1 ) ] ) #NEWLINE# assert ( measure_partial ( state1 , ( 1 , 2 ) ) == measure_partial ( state1 , ( 3 , 4 ) ) ) #NEWLINE# assert ( measure_partial ( state1 , ( 1 , 2 , 3 ) ) == [ ( Qubit ( '00001' ) , Rational ( 2 , 3 ) ) , ( Qubit ( '11111' ) , Rational ( 1 , 3 ) ) ] ) #NEWLINE# state2 = ( ( ( Qubit ( '1111' ) + Qubit ( '1101' ) ) + Qubit ( '1011' ) ) + Qubit ( '1000' ) ) #NEWLINE# assert ( measure_partial ( state2 , ( 0 , 1 , 3 ) ) == [ ( Qubit ( '1000' ) , Rational ( 1 , 4 ) ) , ( Qubit ( '1101' ) , Rational ( 1 , 4 ) ) , ( ( ( Qubit ( '1011' ) / sqrt ( 2 ) ) + ( Qubit ( '1111' ) / sqrt ( 2 ) ) ) , Rational ( 1 , 2 ) ) ] ) #NEWLINE# assert ( measure_partial ( state2 , ( 0 , ) ) == [ ( Qubit ( '1000' ) , Rational ( 1 , 4 ) ) , ( ( ( ( Qubit ( '1111' ) / sqrt ( 3 ) ) + ( Qubit ( '1101' ) / sqrt ( 3 ) ) ) + ( Qubit ( '1011' ) / sqrt ( 3 ) ) ) , Rational ( 3 , 4 ) ) ] )