コード例 #1
0
 def test_no_limits_with_negative(self):
     """Test that we're not enforcing a trial limit if set to negative."""
     backend = FakeYorktown()
     qc = QuantumCircuit(3)
     qc.h(0)
     cmap = CouplingMap(backend.configuration().coupling_map)
     implicit_max = len(cmap.graph.edge_list()) + 15
     properties = backend.properties()
     # Run without any limits set
     vf2_pass = VF2Layout(cmap,
                          properties=properties,
                          seed=42,
                          max_trials=0)
     property_set = {}
     with self.assertLogs("qiskit.transpiler.passes.layout.vf2_layout",
                          level="DEBUG") as cm:
         vf2_pass(qc, property_set)
     for output in cm.output:
         self.assertNotIn("is >= configured max trials", output)
     last_line = cm.output[-1]
     # The last line should be
     # DEBUG:qiskit.transpiler.passes.layout.vf2_layout: Trial n has score 0.122
     trials = int(last_line.split(" ")[1])
     self.assertGreater(trials, implicit_max)
     self.assertEqual(set(property_set["layout"].get_physical_bits()),
                      {3, 1, 0})
コード例 #2
0
    def test_time_limit_exceeded(self):
        """Test the pass stops after time_limit is reached."""
        backend = FakeYorktown()
        qr = QuantumRegister(2)
        qc = QuantumCircuit(qr)
        qc.x(qr)
        qc.measure_all()
        cmap = CouplingMap(backend.configuration().coupling_map)
        properties = backend.properties()
        vf2_pass = VF2Layout(cmap,
                             properties=properties,
                             seed=-1,
                             time_limit=0.0)
        property_set = {}
        with self.assertLogs("qiskit.transpiler.passes.layout.vf2_layout",
                             level="DEBUG") as cm:
            vf2_pass(qc, property_set)
        for output in cm.output:
            if output.startswith(
                    "DEBUG:qiskit.transpiler.passes.layout.vf2_layout:VF2Layout has taken"
            ) and output.endswith("which exceeds configured max time: 0.0"):
                break
        else:
            self.fail("No failure debug log message found")

        self.assertEqual(set(property_set["layout"].get_physical_bits()),
                         {2, 0})
コード例 #3
0
 def test_with_properties(self):
     """Test scores with properties."""
     backend = FakeYorktown()
     cmap = CouplingMap(backend.configuration().coupling_map)
     properties = backend.properties()
     vf2_pass = VF2Layout(cmap, properties=properties)
     qr = QuantumRegister(2)
     layout = Layout({qr[0]: 4, qr[1]: 2})
     bad_score = vf2_pass._score_layout(layout)
     self.assertAlmostEqual(0.4075, bad_score)
     better_layout = Layout({qr[0]: 1, qr[1]: 3})
     better_score = vf2_pass._score_layout(better_layout)
     self.assertAlmostEqual(0.0588, better_score)
コード例 #4
0
 def test_with_properties(self):
     """Test it finds the least noise perfect layout with no properties."""
     backend = FakeYorktown()
     qr = QuantumRegister(2)
     qc = QuantumCircuit(qr)
     qc.x(qr)
     qc.measure_all()
     cmap = CouplingMap(backend.configuration().coupling_map)
     properties = backend.properties()
     vf2_pass = VF2Layout(cmap, properties=properties)
     property_set = {}
     vf2_pass(qc, property_set)
     self.assertEqual(set(property_set["layout"].get_physical_bits()),
                      {1, 3})
コード例 #5
0
 def test_max_trials_exceeded(self):
     """Test it exits when max_trials is reached."""
     backend = FakeYorktown()
     qr = QuantumRegister(2)
     qc = QuantumCircuit(qr)
     qc.x(qr)
     qc.measure_all()
     cmap = CouplingMap(backend.configuration().coupling_map)
     properties = backend.properties()
     vf2_pass = VF2Layout(cmap,
                          properties=properties,
                          seed=-1,
                          max_trials=1)
     property_set = {}
     with self.assertLogs("qiskit.transpiler.passes.layout.vf2_layout",
                          level="DEBUG") as cm:
         vf2_pass(qc, property_set)
     self.assertIn(
         "DEBUG:qiskit.transpiler.passes.layout.vf2_layout:Trial 1 is >= configured max trials 1",
         cm.output,
     )
     self.assertEqual(set(property_set["layout"].get_physical_bits()),
                      {2, 0})