def test_raise_if_gate_equiv_parameter_mismatch(self): """Verify we raise if adding a circuit and gate with different sets of parameters.""" eq_lib = EquivalenceLibrary() theta = Parameter('theta') phi = Parameter('phi') gate = OneQubitOneParamGate(theta) equiv = QuantumCircuit(1) equiv.p(phi, 0) with self.assertRaises(CircuitError): eq_lib.add_equivalence(gate, equiv) with self.assertRaises(CircuitError): eq_lib.set_entry(gate, [equiv])
def test_set_entry(self): """Verify setting an entry overrides any previously added.""" eq_lib = EquivalenceLibrary() gate = OneQubitZeroParamGate() first_equiv = QuantumCircuit(1) first_equiv.h(0) eq_lib.add_equivalence(gate, first_equiv) second_equiv = QuantumCircuit(1) second_equiv.append(U2Gate(0, np.pi), [0]) eq_lib.set_entry(gate, [second_equiv]) entry = eq_lib.get_entry(gate) self.assertEqual(len(entry), 1) self.assertEqual(entry[0], second_equiv)
def test_set_entry(self): """Verify we find only equivalences from top when explicitly set.""" base = EquivalenceLibrary() gate = OneQubitZeroParamGate() first_equiv = QuantumCircuit(1) first_equiv.h(0) base.add_equivalence(gate, first_equiv) eq_lib = EquivalenceLibrary(base=base) second_equiv = QuantumCircuit(1) second_equiv.append(U2Gate(0, np.pi), [0]) eq_lib.set_entry(gate, [second_equiv]) entry = eq_lib.get_entry(gate) self.assertEqual(len(entry), 1) self.assertEqual(entry[0], second_equiv)