def test_2_qubit_identities(self): """Tests identities for 2-qubit gates""" # CX01 * CX10 * CX01 = CX10 * CX01 * CX10 elem1 = CNOTDihedral(2) elem1.cnot(0, 1) elem1.cnot(1, 0) elem1.cnot(0, 1) elem2 = CNOTDihedral(2) elem2.cnot(1, 0) elem2.cnot(0, 1) elem2.cnot(1, 0) self.assertEqual(elem1, elem2, 'Error: 2-qubit SWAP identity does not hold') # CS01 = CS10 (symmetric) elem1 = CNOTDihedral(2) elem1.phase(1, 0) elem1.phase(1, 1) elem1.cnot(0, 1) elem1.phase(7, 1) elem1.cnot(0, 1) elem2 = CNOTDihedral(2) elem2.phase(1, 1) elem2.phase(1, 0) elem2.cnot(1, 0) elem2.phase(7, 0) elem2.cnot(1, 0) self.assertEqual(elem1, elem2, 'Error: 2-qubit CS identity does not hold') # TI*CS*TdgI = CS" elem3 = CNOTDihedral(2) elem3.phase(1, 0) elem3.phase(1, 0) elem3.phase(1, 1) elem3.cnot(0, 1) elem3.phase(7, 1) elem3.cnot(0, 1) elem3.phase(7, 0) self.assertEqual(elem1, elem3, 'Error: 2-qubit CS identity does not hold') # IT*CS*ITdg = CS elem4 = CNOTDihedral(2) elem4.phase(1, 1) elem4.phase(1, 0) elem4.phase(1, 1) elem4.cnot(0, 1) elem4.phase(7, 1) elem4.cnot(0, 1) elem4.phase(7, 1) self.assertEqual(elem1, elem4, 'Error: 2-qubit CS identity does not hold') # XX*CS*XX*SS = CS elem5 = CNOTDihedral(2) elem5.flip(0) elem5.flip(1) elem5.phase(1, 0) elem5.phase(1, 1) elem5.cnot(0, 1) elem5.phase(7, 1) elem5.cnot(0, 1) elem5.flip(0) elem5.flip(1) elem5.phase(2, 0) elem5.phase(2, 1) self.assertEqual(elem1, elem5, 'Error: 2-qubit CS identity does not hold') # CSdg01 = CSdg10 (symmetric) elem1 = CNOTDihedral(2) elem1.phase(7, 0) elem1.phase(7, 1) elem1.cnot(0, 1) elem1.phase(1, 1) elem1.cnot(0, 1) elem2 = CNOTDihedral(2) elem2.phase(7, 1) elem2.phase(7, 0) elem2.cnot(1, 0) elem2.phase(1, 0) elem2.cnot(1, 0) self.assertEqual(elem1, elem2, 'Error: 2-qubit CSdg identity does not hold') # XI*CS*XI*ISdg = CSdg elem3 = CNOTDihedral(2) elem3.flip(0) elem3.phase(1, 0) elem3.phase(1, 1) elem3.cnot(0, 1) elem3.phase(7, 1) elem3.cnot(0, 1) elem3.flip(0) elem3.phase(6, 1) self.assertEqual(elem1, elem3, 'Error: 2-qubit CSdg identity does not hold') # IX*CS*IX*SdgI = CSdg elem4 = CNOTDihedral(2) elem4.flip(1) elem4.phase(1, 0) elem4.phase(1, 1) elem4.cnot(0, 1) elem4.phase(7, 1) elem4.cnot(0, 1) elem4.flip(1) elem4.phase(6, 0) self.assertEqual(elem1, elem4, 'Error: 2-qubit CSdg identity does not hold') # relations for CZ elem1 = CNOTDihedral(2) elem1.phase(1, 0) elem1.phase(1, 1) elem1.cnot(0, 1) elem1.phase(7, 1) elem1.cnot(0, 1) elem1.phase(1, 0) elem1.phase(1, 1) elem1.cnot(0, 1) elem1.phase(7, 1) elem1.cnot(0, 1) elem2 = CNOTDihedral(2) elem2.phase(7, 0) elem2.phase(7, 1) elem2.cnot(0, 1) elem2.phase(1, 1) elem2.cnot(0, 1) elem2.phase(7, 0) elem2.phase(7, 1) elem2.cnot(0, 1) elem2.phase(1, 1) elem2.cnot(0, 1) elem3 = CNOTDihedral(2) elem3.phase(1, 1) elem3.phase(1, 0) elem3.cnot(1, 0) elem3.phase(7, 0) elem3.cnot(1, 0) elem3.phase(1, 1) elem3.phase(1, 0) elem3.cnot(1, 0) elem3.phase(7, 0) elem3.cnot(1, 0) elem4 = CNOTDihedral(2) elem4.phase(7, 1) elem4.phase(7, 0) elem4.cnot(1, 0) elem4.phase(1, 0) elem4.cnot(1, 0) elem4.phase(7, 1) elem4.phase(7, 0) elem4.cnot(1, 0) elem4.phase(1, 0) elem4.cnot(1, 0) # CZ = TdgTdg * CX * T^2I * CX * TdgTdg elem5 = CNOTDihedral(2) elem5.phase(7, 1) elem5.phase(7, 0) elem5.cnot(1, 0) elem5.phase(2, 0) elem5.cnot(1, 0) elem5.phase(7, 1) elem5.phase(7, 0) self.assertEqual(elem1, elem2, 'Error: 2-qubit CZ identity does not hold') self.assertEqual(elem1, elem3, 'Error: 2-qubit CZ identity does not hold') self.assertEqual(elem1, elem4, 'Error: 2-qubit CZ identity does not hold') self.assertEqual(elem1, elem5, 'Error: 2-qubit CZ identity does not hold') # relations for CX elem1 = CNOTDihedral(2) elem1.cnot(0, 1) # TI*CX*TdgI = CX elem2 = CNOTDihedral(2) elem2.phase(1, 0) elem2.cnot(0, 1) elem2.phase(7, 0) # IZ*CX*ZZ = CX elem3 = CNOTDihedral(2) elem3.phase(4, 1) elem3.cnot(0, 1) elem3.phase(4, 0) elem3.phase(4, 1) # IX*CX*IX = CX elem4 = CNOTDihedral(2) elem4.flip(1) elem4.cnot(0, 1) elem4.flip(1) # XI*CX*XX = CX elem5 = CNOTDihedral(2) elem5.flip(0) elem5.cnot(0, 1) elem5.flip(0) elem5.flip(1) self.assertEqual(elem1, elem2, 'Error: 2-qubit CX identity does not hold') self.assertEqual(elem1, elem3, 'Error: 2-qubit CX identity does not hold') self.assertEqual(elem1, elem4, 'Error: 2-qubit CX identity does not hold') self.assertEqual(elem1, elem5, 'Error: 2-qubit CX identity does not hold') # IT*CX01*CX10*TdgI = CX01*CX10 elem1 = CNOTDihedral(2) elem1.cnot(0, 1) elem1.cnot(1, 0) elem2 = CNOTDihedral(2) elem2.phase(1, 1) elem2.cnot(0, 1) elem2.cnot(1, 0) elem2.phase(7, 0) self.assertEqual(elem1, elem2, 'Error: 2-qubit CX01*CX10 identity does not hold')
def test_1_qubit_identities(self): """Tests identities for 1-qubit gates""" # T*X*T = X elem1 = CNOTDihedral(1) elem1.phase(1, 0) elem1.flip(0) elem1.phase(1, 0) elem2 = CNOTDihedral(1) elem2.flip(0) self.assertEqual(elem1, elem2, 'Error: 1-qubit identity does not hold') # X*T*X = Tdg elem1 = CNOTDihedral(1) elem1.flip(0) elem1.phase(1, 0) elem1.flip(0) elem2 = CNOTDihedral(1) elem2.phase(7, 0) self.assertEqual(elem1, elem2, 'Error: 1-qubit identity does not hold') # T*X*Tdg = S*X elem1 = CNOTDihedral(1) elem1.phase(1, 0) elem1.flip(0) elem1.phase(7, 0) elem2 = CNOTDihedral(1) elem2.phase(2, 0) elem2.flip(0) self.assertEqual(elem1, elem2, 'Error: 1-qubit identity does not hold')