def test_circuit_extract_produces_circuit(self): random.seed(SEED) g = cliffordT(6, 60, 0.15) clifford_simp(g, quiet=True) circuit_extract(g) # This should not result in an exception Circuit.from_graph(g)
def test_circuit_extract_preserves_semantics(self): random.seed(SEED) g = cliffordT(5, 70, 0.15) t = g.to_tensor() clifford_simp(g, quiet=True) circuit_extract(g) t2 = Circuit.from_graph(g).to_tensor() self.assertTrue(compare_tensors(t,t2))
def test_cliffords_preserves_graph_semantics(self): random.seed(SEED) g = cliffords(5,30) c = Circuit.from_graph(g) g2 = c.to_graph() t = tensorfy(g) t2 = tensorfy(g2) self.assertTrue(compare_tensors(t,t2))
def test_teleport_reduce(self): """Tests whether teleport_reduce preserves semantics on a set of circuits that have been broken before.""" for i,s in enumerate([qasm_1,qasm_2,qasm_3,qasm_4]): with self.subTest(i=i): c = qasm(s) g = c.to_graph() c2 = Circuit.from_graph(teleport_reduce(g)) self.assertTrue(c.verify_equality(c2))
def test_cliffordT_preserves_graph_semantics(self): random.seed(SEED) g = cliffordT(4, 20, 0.2) c = Circuit.from_graph(g) g2 = c.to_graph() t = tensorfy(g, False) t2 = tensorfy(g2, False) self.assertTrue(compare_tensors(t, t2, False))
def build_random_parity_map(qubits, n_cnots, circuit=None): """ Builds a random parity map. :param qubits: The number of qubits that participate in the parity map :param n_cnots: The number of CNOTs in the parity map :param circuit: A (list of) circuit object(s) that implements a row_add() method to add the generated CNOT gates [optional] :return: a 2D numpy array that represents the parity map. """ if circuit is None: circuit = [] if not isinstance(circuit, list): circuit = [circuit] g = generate_cnots(qubits=qubits, depth=n_cnots) c = Circuit.from_graph(g) matrix = Mat2.id(qubits) for gate in c.gates: matrix.row_add(gate.control, gate.target) for c in circuit: c.row_add(gate.control, gate.target) return matrix.data
def test_to_graph_and_back(self): g = self.c.to_graph() c2 = Circuit.from_graph(g) self.assertEqual(self.c.qubits, c2.qubits) self.assertListEqual(self.c.gates,c2.gates)