Example #1
0
    def test_set_parameters(self):
        """Test parameters setting."""
        for n_qubits in range(10, 100, 30):
            with self.subTest(n_qubits=n_qubits):
                fake_backend = ConfigurableFakeBackend(
                    "Tashkent",
                    n_qubits=n_qubits,
                    version="0.0.1",
                    basis_gates=["u1"],
                    qubit_t1=99.0,
                    qubit_t2=146.0,
                    qubit_frequency=5.0,
                    qubit_readout_error=0.01,
                    single_qubit_gates=["u1"],
                )

                properties = fake_backend.properties()
                self.assertEqual(properties.backend_version, "0.0.1")
                self.assertEqual(properties.backend_name, "Tashkent")
                self.assertEqual(len(properties.qubits), n_qubits)
                self.assertEqual(len(properties.gates), n_qubits)

                configuration = fake_backend.configuration()
                self.assertEqual(configuration.backend_version, "0.0.1")
                self.assertEqual(configuration.backend_name, "Tashkent")
                self.assertEqual(configuration.n_qubits, n_qubits)
                self.assertEqual(configuration.basis_gates, ["u1"])
Example #2
0
    def test_defaults(self):
        """Test backend defaults."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=10)
        defaults = fake_backend.defaults()

        self.assertEqual(len(defaults.cmd_def), 54)
        self.assertEqual(len(defaults.meas_freq_est), 10)
        self.assertEqual(len(defaults.qubit_freq_est), 10)
Example #3
0
    def test_configuration(self):
        """Test backend configuration."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=10)
        configuration = fake_backend.configuration()

        self.assertEqual(configuration.n_qubits, 10)
        self.assertEqual(configuration.meas_map, [list(range(10))])
        self.assertEqual(len(configuration.hamiltonian["qub"]), 10)
        self.assertEqual(len(configuration.hamiltonian["vars"]), 33)
        self.assertEqual(len(configuration.u_channel_lo), 13)
        self.assertEqual(len(configuration.meas_lo_range), 10)
        self.assertEqual(len(configuration.qubit_lo_range), 10)
Example #4
0
    def test_with_coupling_map(self):
        """Test backend generation with coupling map."""
        target_coupling_map = [[0, 1], [1, 2], [2, 3]]
        fake_backend = ConfigurableFakeBackend(
            "Tashkent", n_qubits=4, coupling_map=target_coupling_map)
        cmd_def = fake_backend.defaults().cmd_def
        configured_cmap = fake_backend.configuration().coupling_map
        controlled_not_qubits = [
            cmd.qubits for cmd in cmd_def if cmd.name == "cx"
        ]

        self.assertEqual(controlled_not_qubits, target_coupling_map)
        self.assertEqual(configured_cmap, target_coupling_map)
class GeneratedFakeBackendsTest(QiskitTestCase):
    """Generated fake backends test."""
    def setUp(self) -> None:
        self.backend = ConfigurableFakeBackend("Tashkent", n_qubits=4)

    @unittest.skip("Skipped until qiskit-aer#741 is fixed and released")
    @unittest.skipUnless(optionals.HAS_AER,
                         "qiskit-aer is required to run this test")
    def test_transpile_schedule_and_assemble(self):
        """Test transpile, schedule and assemble on generated backend."""
        qc = get_test_circuit()

        circuit = transpile(qc, backend=self.backend)
        self.assertTrue(isinstance(circuit, QuantumCircuit))
        self.assertEqual(circuit.num_qubits, 4)

        experiments = schedule(circuits=circuit, backend=self.backend)
        self.assertTrue(isinstance(experiments, Schedule))
        self.assertGreater(experiments.duration, 0)

        qobj = assemble(experiments, backend=self.backend)
        self.assertTrue(isinstance(qobj, PulseQobj))
        self.assertEqual(qobj.header.backend_name, "Tashkent")
        self.assertEqual(len(qobj.experiments), 1)

        job = self.backend.run(qobj)
        result = job.result()
        self.assertTrue(result.success)
        self.assertEqual(len(result.results), 1)
Example #6
0
    def test_default_parameters(self):
        """Test default parameters."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=10)

        properties = fake_backend.properties()
        self.assertEqual(len(properties.qubits), 10)
        self.assertEqual(properties.backend_version, "0.0.0")
        self.assertEqual(properties.backend_name, "Tashkent")

        configuration = fake_backend.configuration()
        self.assertEqual(configuration.backend_version, "0.0.0")
        self.assertEqual(configuration.backend_name, "Tashkent")
        self.assertEqual(configuration.n_qubits, 10)
        self.assertEqual(configuration.basis_gates,
                         ["id", "u1", "u2", "u3", "cx"])
        self.assertTrue(configuration.local)
        self.assertTrue(configuration.open_pulse)
Example #7
0
    def test_measure_all(self):
        """Test utility function - measure."""
        with pulse.build(self.backend) as schedule:
            regs = pulse.measure_all()

        self.assertEqual(regs, [pulse.MemorySlot(0), pulse.MemorySlot(1)])
        reference = macros.measure_all(self.backend)

        self.assertScheduleEqual(schedule, reference)

        backend_100q = ConfigurableBackend("100q", 100)
        with pulse.build(backend_100q) as schedule:
            regs = pulse.measure_all()

        reference = backend_100q.defaults().instruction_schedule_map.get(
            "measure", list(range(100))
        )

        self.assertScheduleEqual(schedule, reference)
Example #8
0
    def test_coupling_map_generation(self):
        """Test generation of default coupling map."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=10)
        cmap = fake_backend.configuration().coupling_map
        target = [
            [0, 1],
            [0, 4],
            [1, 2],
            [1, 5],
            [2, 3],
            [2, 6],
            [3, 7],
            [4, 5],
            [4, 8],
            [5, 6],
            [5, 9],
            [6, 7],
            [8, 9],
        ]
        for couple in cmap:
            with self.subTest(coupling=couple):
                self.assertTrue(couple in target)

        self.assertEqual(len(target), len(cmap))
Example #9
0
    def test_gates(self):
        """Test generated gates."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=4)
        properties = fake_backend.properties()

        self.assertEqual(len(properties.gates), 22)

        fake_backend = ConfigurableFakeBackend("Tashkent",
                                               n_qubits=4,
                                               basis_gates=["u1", "u2", "cx"])
        properties = fake_backend.properties()

        self.assertEqual(len(properties.gates), 14)
        self.assertEqual(len([g for g in properties.gates if g.gate == "cx"]),
                         6)
 def setUp(self) -> None:
     self.backend = ConfigurableFakeBackend("Tashkent", n_qubits=4)
Example #11
0
    def test_get_name_with_method(self):
        """Get backend name."""
        fake_backend = ConfigurableFakeBackend("Tashkent", n_qubits=4)

        self.assertEqual(fake_backend.name(), "Tashkent")