def test_2_qubit_relations(self): """Tests relations for 2-qubit gates""" with self.subTest(msg="relation between cx, h and cz"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, "h", [1]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "h", [1]) cliff = _append_circuit(cliff, "cz", [0, 1]) self.assertEqual(cliff, cliff1) with self.subTest(msg="relation between cx and swap"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "cx", [1, 0]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "swap", [0, 1]) self.assertEqual(cliff, cliff1) with self.subTest(msg="relation between cx and x"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "x", [0]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "x", [0]) cliff = _append_circuit(cliff, "x", [1]) self.assertEqual(cliff, cliff1) with self.subTest(msg="relation between cx and z"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "z", [1]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "z", [0]) cliff = _append_circuit(cliff, "z", [1]) self.assertEqual(cliff, cliff1) with self.subTest(msg="relation between cx and s"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, "cx", [1, 0]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "s", [1]) cliff = _append_circuit(cliff, "cx", [0, 1]) cliff = _append_circuit(cliff, "cx", [1, 0]) cliff = _append_circuit(cliff, "sdg", [0]) self.assertEqual(cliff, cliff1)
def test_2_qubit_relations(self): """Tests relations for 2-qubit gates""" with self.subTest(msg='relation between cx, h and cz'): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, 'h', [1]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'h', [1]) cliff = _append_circuit(cliff, 'cz', [0, 1]) self.assertEqual(cliff, cliff1) with self.subTest(msg='relation between cx and swap'): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'cx', [1, 0]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'swap', [0, 1]) self.assertEqual(cliff, cliff1) with self.subTest(msg='relation between cx and x'): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'x', [0]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'x', [0]) cliff = _append_circuit(cliff, 'x', [1]) self.assertEqual(cliff, cliff1) with self.subTest(msg='relation between cx and z'): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'z', [1]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'z', [0]) cliff = _append_circuit(cliff, 'z', [1]) self.assertEqual(cliff, cliff1) with self.subTest(msg='relation between cx and s'): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, 'cx', [1, 0]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 's', [1]) cliff = _append_circuit(cliff, 'cx', [0, 1]) cliff = _append_circuit(cliff, 'cx', [1, 0]) cliff = _append_circuit(cliff, 'sdg', [0]) self.assertEqual(cliff, cliff1)
def test_2_qubit_identity_relations(self): """Tests identity relations for 2-qubit gates""" for gate_name in ("cx", "cz", "swap"): for qubits in ([0, 1], [1, 0]): with self.subTest(msg=f"append gate {gate_name} {qubits}"): cliff = Clifford(np.eye(4)) cliff1 = cliff.copy() cliff = _append_circuit(cliff, gate_name, qubits) cliff = _append_circuit(cliff, gate_name, qubits) self.assertEqual(cliff, cliff1)
def test_1_qubit_identity_relations(self): """Tests identity relations for 1-qubit gates""" for gate_name in ("x", "y", "z", "h"): with self.subTest(msg='identity for gate %s' % gate_name): cliff = Clifford([[1, 0], [0, 1]]) cliff1 = cliff.copy() cliff = _append_circuit(cliff, gate_name, [0]) cliff = _append_circuit(cliff, gate_name, [0]) self.assertEqual(cliff, cliff1) gates = ['s', 's', 'v'] inv_gates = ['sdg', 'sinv', 'w'] for gate_name, inv_gate in zip(gates, inv_gates): with self.subTest(msg='identity for gate %s' % gate_name): cliff = Clifford([[1, 0], [0, 1]]) cliff1 = cliff.copy() cliff = _append_circuit(cliff, gate_name, [0]) cliff = _append_circuit(cliff, inv_gate, [0]) self.assertEqual(cliff, cliff1)
def test_1_qubit_mult_relations(self): """Tests multiplicity relations for 1-qubit gates""" rels = [ 'x * y = z', 'x * z = y', 'y * z = x', 's * s = z', 'sdg * sdg = z', 'sinv * sinv = z', 'sdg * h = v', 'h * s = w' ] for rel in rels: with self.subTest(msg='relation %s' % rel): split_rel = rel.split() cliff = Clifford([[1, 0], [0, 1]]) cliff1 = cliff.copy() cliff = _append_circuit(cliff, split_rel[0], [0]) cliff = _append_circuit(cliff, split_rel[2], [0]) cliff1 = _append_circuit(cliff1, split_rel[4], [0]) self.assertEqual(cliff, cliff1)
def test_1_qubit_conj_relations(self): """Tests conjugation relations for 1-qubit gates""" rels = [ 'h * x * h = z', 'h * y * h = y', 's * x * sdg = y', 'w * x * v = y', 'w * y * v = z', 'w * z * v = x' ] for rel in rels: with self.subTest(msg='relation %s' % rel): split_rel = rel.split() cliff = Clifford([[1, 0], [0, 1]]) cliff1 = cliff.copy() cliff = _append_circuit(cliff, split_rel[0], [0]) cliff = _append_circuit(cliff, split_rel[2], [0]) cliff = _append_circuit(cliff, split_rel[4], [0]) cliff1 = _append_circuit(cliff1, split_rel[6], [0]) self.assertEqual(cliff, cliff1)
def test_1_qubit_mult_relations(self): """Tests multiplicity relations for 1-qubit gates""" rels = [ "x * y = z", "x * z = y", "y * z = x", "s * s = z", "sdg * sdg = z", "sinv * sinv = z", "sdg * h = v", "h * s = w", ] for rel in rels: with self.subTest(msg="relation %s" % rel): split_rel = rel.split() cliff = Clifford([[1, 0], [0, 1]]) cliff1 = cliff.copy() cliff = _append_circuit(cliff, split_rel[0], [0]) cliff = _append_circuit(cliff, split_rel[2], [0]) cliff1 = _append_circuit(cliff1, split_rel[4], [0]) self.assertEqual(cliff, cliff1)