def test_analysis_pass_property_set(self): """Call an analysis pass without a scheduler (PropertySet dict)""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr, name='MyCircuit') property_set = PropertySet({'another_property': 'another_value'}) pass_e = PassE_AP_NR_NP('value') with self.assertLogs('LocalLogger', level='INFO') as cm: result = pass_e(circuit, property_set) self.assertMessageLog(cm, ['run analysis pass PassE_AP_NR_NP', 'set property as value']) self.assertEqual(property_set, PropertySet({'another_property': 'another_value', 'property': 'value'})) self.assertIsInstance(property_set, PropertySet) self.assertEqual(circuit, result)
def test_callback(self): """Test the callback parameter.""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr, name='MyCircuit') circuit.h(qr[0]) circuit.h(qr[0]) circuit.h(qr[0]) expected_start = QuantumCircuit(qr) expected_start.u2(0, np.pi, qr[0]) expected_start.u2(0, np.pi, qr[0]) expected_start.u2(0, np.pi, qr[0]) expected_start_dag = circuit_to_dag(expected_start) expected_end = QuantumCircuit(qr) expected_end.u2(0, np.pi, qr[0]) expected_end_dag = circuit_to_dag(expected_end) calls = [] def callback(**kwargs): out_dict = kwargs out_dict['dag'] = copy.deepcopy(kwargs['dag']) calls.append(out_dict) passmanager = PassManager() passmanager.append(Unroller(['u2'])) passmanager.append(Optimize1qGates()) transpile(circuit, FakeRueschlikon(), pass_manager=passmanager, callback=callback) self.assertEqual(len(calls), 2) self.assertEqual(len(calls[0]), 5) self.assertEqual(calls[0]['count'], 0) self.assertEqual(calls[0]['pass_'].name(), 'Unroller') self.assertEqual(expected_start_dag, calls[0]['dag']) self.assertIsInstance(calls[0]['time'], float) self.assertEqual(calls[0]['property_set'], PropertySet()) self.assertEqual('MyCircuit', calls[0]['dag'].name) self.assertEqual(len(calls[1]), 5) self.assertEqual(calls[1]['count'], 1) self.assertEqual(calls[1]['pass_'].name(), 'Optimize1qGates') self.assertEqual(expected_end_dag, calls[1]['dag']) self.assertIsInstance(calls[0]['time'], float) self.assertEqual(calls[0]['property_set'], PropertySet()) self.assertEqual('MyCircuit', calls[1]['dag'].name)
def test_analysis_pass_property_set(self): """Call an analysis pass without a scheduler (PropertySet dict)""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr, name="MyCircuit") property_set = PropertySet({"another_property": "another_value"}) pass_e = PassE_AP_NR_NP("value") with self.assertLogs("LocalLogger", level="INFO") as cm: result = pass_e(circuit, property_set) self.assertMessageLog( cm, ["run analysis pass PassE_AP_NR_NP", "set property as value"]) self.assertEqual( property_set, PropertySet({ "another_property": "another_value", "property": "value" })) self.assertIsInstance(property_set, PropertySet) self.assertEqual(circuit, result)
def test_analysis_pass_remove_property(self): """Call an analysis pass that removes a property without a scheduler""" qr = QuantumRegister(1, 'qr') circuit = QuantumCircuit(qr, name='MyCircuit') property_set = {'to remove': 'value to remove', 'to none': 'value to none'} pass_e = PassN_AP_NR_NP('to remove', 'to none') with self.assertLogs('LocalLogger', level='INFO') as cm: result = pass_e(circuit, property_set) self.assertMessageLog(cm, ['run analysis pass PassN_AP_NR_NP', 'property to remove deleted', 'property to none noned']) self.assertEqual(property_set, PropertySet({'to none': None})) self.assertIsInstance(property_set, dict) self.assertEqual(circuit, result)
def test_analysis_pass_remove_property(self): """Call an analysis pass that removes a property without a scheduler""" qr = QuantumRegister(1, "qr") circuit = QuantumCircuit(qr, name="MyCircuit") property_set = { "to remove": "value to remove", "to none": "value to none" } pass_e = PassN_AP_NR_NP("to remove", "to none") with self.assertLogs("LocalLogger", level="INFO") as cm: result = pass_e(circuit, property_set) self.assertMessageLog( cm, [ "run analysis pass PassN_AP_NR_NP", "property to remove deleted", "property to none noned", ], ) self.assertEqual(property_set, PropertySet({"to none": None})) self.assertIsInstance(property_set, dict) self.assertEqual(circuit, result)
def setUp(self): self.pset = PropertySet()
def setUp(self): super().setUp() self.pass_ = CommutationAnalysis() self.pset = self.pass_.property_set = PropertySet()
def setUp(self): self.com_pass_ = CommutationAnalysis() self.pass_ = CommutativeCancellation() self.pset = self.pass_.property_set = PropertySet()
def setUp(self): super().setUp() self.pset = PropertySet()
def setUp(self): self.pass_ = FixedPoint('property') self.pset = self.pass_.property_set = PropertySet() self.dag = None # The pass do not read the DAG.