def test_filter_least_busy_reservation(self):
        """Test filtering by least busy function, with reservations."""
        backend = reservations = None
        for backend in self.dependencies.provider.backends(
                simulator=False,
                operational=True,
                status_msg="active",
                instance=self.dependencies.instance,
        ):
            reservations = backend.reservations()
            if reservations:
                break

        if not reservations:
            self.skipTest("Test case requires reservations.")

        reserv = reservations[0]
        now = datetime.now(tz=tz.tzlocal())
        window = 60
        if reserv.start_datetime > now:
            window = (reserv.start_datetime - now).seconds * 60
        self.assertRaises(IBMError, least_busy, [backend], window)

        self.assertEqual(least_busy([backend], None), backend)

        backs = [backend]
        for back in self.dependencies.provider.backends(
                simulator=False,
                operational=True,
                status_msg="active",
                instance=self.dependencies.instance,
        ):
            if back.name != backend.name:
                backs.append(back)
                break
        self.assertTrue(least_busy(backs, window))
    def test_filter_least_busy_paused(self):
        """Test filtering by least busy function, with paused backend."""
        backends = self.dependencies.provider.backends(
            instance=self.dependencies.instance)
        if len(backends) < 2:
            self.skipTest("Test needs at least 2 backends.")
        paused_backend = backends[0]
        paused_status = paused_backend.status()
        paused_status.status_msg = "internal"
        paused_status.pending_jobs = 0
        paused_backend.status = mock.MagicMock(return_value=paused_status)

        least_busy_backend = least_busy(backends)
        self.assertTrue(least_busy_backend)
        self.assertNotEqual(least_busy_backend.name, paused_backend.name)
        self.assertEqual(least_busy_backend.status().status_msg, "active")
Exemplo n.º 3
0
        def _wrapper(self, *args, **kwargs):
            dependencies: IntegrationTestDependencies = kwargs["dependencies"]
            provider: IBMProvider = dependencies.provider
            if backend_name:
                _backend = provider.get_backend(name=backend_name,
                                                instance=dependencies.instance)
            else:
                _backend = least_busy(
                    provider.backends(
                        simulator=simulator,
                        instance=dependencies.instance,
                        min_num_qubits=min_num_qubits,
                    ))
            if not _backend:
                raise Exception("Unable to find a suitable backend.")

            kwargs["backend"] = _backend
            func(self, *args, **kwargs)
    def test_pulse_job_result(self):
        """Test deserializing a pulse job result."""
        backends = self.dependencies.provider.backends(
            open_pulse=True,
            operational=True,
            instance=self.dependencies.instance)
        if not backends:
            raise SkipTest("Skipping pulse test since no pulse backend found.")

        backend = least_busy(backends)
        quantum_circuit = QuantumCircuit(1, 1)
        quantum_circuit.x(0)
        quantum_circuit.measure([0], [0])
        sched = schedule(transpile(quantum_circuit, backend=backend),
                         backend=backend)
        job = backend.run(sched)
        result = job.result()

        # Known keys that look like a serialized object.
        good_keys = ("header.backend_version", "backend_version")
        self._verify_data(result.to_dict(), good_keys)
 def test_filter_least_busy(self):
     """Test filtering by least busy function."""
     backends = self.dependencies.provider.backends(
         instance=self.dependencies.instance)
     least_busy_backend = least_busy(backends)
     self.assertTrue(least_busy_backend)