Esempio n. 1
0
class FakeBackendSimple(BackendV2):
    """A fake simple backend that wraps BasicAer to implement run()."""
    def __init__(self):
        super().__init__(
            None,
            name="FakeSimpleV2",
            description="A fake simple BackendV2 example",
            online_date=datetime.datetime.utcnow(),
            backend_version="0.0.1",
        )
        self._lam = Parameter("lambda")
        self._target = Target(num_qubits=20)
        self._target.add_instruction(SXGate())
        self._target.add_instruction(XGate())
        self._target.add_instruction(RZGate(self._lam))
        self._target.add_instruction(CXGate())
        self._target.add_instruction(Measure())
        self._runner = QasmSimulatorPy()

    @property
    def target(self):
        return self._target

    @property
    def max_circuits(self):
        return None

    @classmethod
    def _default_options(cls):
        return QasmSimulatorPy._default_options()

    def run(self, run_input, **options):
        self._runner._options = self._options
        return self._runner.run(run_input, **options)
Esempio n. 2
0
 def test_update_from_instruction_schedule_map_new_instruction_no_name_map(self):
     target = Target()
     inst_map = InstructionScheduleMap()
     inst_map.add("sx", 0, self.custom_sx_q0)
     inst_map.add("sx", 1, self.custom_sx_q1)
     with self.assertRaises(ValueError):
         target.update_from_instruction_schedule_map(inst_map)
Esempio n. 3
0
 def test_update_from_instruction_schedule_map_add_instruction(self):
     target = Target()
     inst_map = InstructionScheduleMap()
     inst_map.add("sx", 0, self.custom_sx_q0)
     inst_map.add("sx", 1, self.custom_sx_q1)
     target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()})
     self.assertEqual(inst_map, target.instruction_schedule_map())
Esempio n. 4
0
    def test_extra_props_str(self):
        target = Target(description="Extra Properties")

        class ExtraProperties(InstructionProperties):
            """An example properties subclass."""

            def __init__(
                self,
                duration=None,
                error=None,
                calibration=None,
                tuned=None,
                diamond_norm_error=None,
            ):
                super().__init__(duration=duration, error=error, calibration=calibration)
                self.tuned = tuned
                self.diamond_norm_error = diamond_norm_error

        cx_props = {
            (3, 4): ExtraProperties(
                duration=270.22e-9, error=0.00713, tuned=False, diamond_norm_error=2.12e-6
            ),
        }
        target.add_instruction(CXGate(), cx_props)
        expected = """Target: Extra Properties
Number of qubits: 5
Instructions:
	cx
		(3, 4):
			Duration: 2.7022e-07 sec.
			Error Rate: 0.00713
"""
        self.assertEqual(expected, str(target))
Esempio n. 5
0
 def __init__(self):
     super().__init__(
         None,
         name="FakeV2",
         description="A fake BackendV2 example",
         online_date=datetime.datetime.utcnow(),
         backend_version="0.0.1",
     )
     self._target = Target()
     self._theta = Parameter("theta")
     self._phi = Parameter("phi")
     self._lam = Parameter("lambda")
     rx_props = {
         (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
         (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
     }
     self._target.add_instruction(RXGate(self._theta), rx_props)
     rx_30_props = {
         (0, ): InstructionProperties(duration=1.23e-8, error=0.00018115),
         (1, ): InstructionProperties(duration=1.52e-8, error=0.00012115),
     }
     self._target.add_instruction(RXGate(np.pi / 6),
                                  rx_30_props,
                                  name="rx_30")
     u_props = {
         (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
         (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
     }
     self._target.add_instruction(UGate(self._theta, self._phi, self._lam),
                                  u_props)
     cx_props = {
         (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115),
     }
     self._target.add_instruction(CXGate(), cx_props)
     measure_props = {
         (0, ): InstructionProperties(duration=6e-6, error=5e-6),
         (1, ): InstructionProperties(duration=1e-6, error=9e-6),
     }
     self._target.add_instruction(Measure(), measure_props)
     ecr_props = {
         (1, 0): InstructionProperties(duration=4.52e-9,
                                       error=0.0000132115),
     }
     self._target.add_instruction(ECRGate(), ecr_props)
     self.options.set_validator("shots", (1, 4096))
     self._qubit_properties = {
         0:
         QubitProperties(t1=63.48783e-6,
                         t2=112.23246e-6,
                         frequency=5.17538e9),
         1:
         QubitProperties(t1=73.09352e-6,
                         t2=126.83382e-6,
                         frequency=5.26722e9),
     }
Esempio n. 6
0
 def test_target_too_small_for_circuit(self):
     """Test error is raised when target is too small for circuit."""
     target = Target()
     target.add_instruction(
         CXGate(),
         {edge: None
          for edge in CouplingMap.from_line(3).get_edges()})
     dag = circuit_to_dag(QuantumCircuit(5))
     layout_pass = DenseLayout(target=target)
     with self.assertRaises(TranspilerError):
         layout_pass.run(dag)
Esempio n. 7
0
 def setUp(self):
     super().setUp()
     self.cmap20 = FakeTokyo().configuration().coupling_map
     self.target_19 = Target()
     rng = np.random.default_rng(12345)
     instruction_props = {
         edge: InstructionProperties(duration=rng.uniform(1e-7, 1e-6),
                                     error=rng.uniform(1e-4, 1e-3))
         for edge in CouplingMap.from_heavy_hex(3).get_edges()
     }
     self.target_19.add_instruction(CXGate(), instruction_props)
 def test_target(self):
     """Test target is respected by the unroll 3q or more pass."""
     target = Target(num_qubits=3)
     target.add_instruction(CCXGate())
     qc = QuantumCircuit(3)
     qc.ccx(0, 1, 2)
     qc.append(RCCXGate(), [0, 1, 2])
     unroll_pass = Unroll3qOrMore(target=target)
     res = unroll_pass(qc)
     self.assertIn("ccx", res.count_ops())
     self.assertNotIn("rccx", res.count_ops())
Esempio n. 9
0
 def __init__(self, bidirectional=True):
     super().__init__(
         None,
         name="Fake5QV2",
         description="A fake BackendV2 example",
         online_date=datetime.datetime.utcnow(),
         backend_version="0.0.1",
     )
     self._target = Target()
     self._theta = Parameter("theta")
     self._phi = Parameter("phi")
     self._lam = Parameter("lambda")
     u_props = {
         (0,): InstructionProperties(duration=5.23e-8, error=0.00038115),
         (1,): InstructionProperties(duration=4.52e-8, error=0.00032115),
         (2,): InstructionProperties(duration=5.23e-8, error=0.00038115),
         (3,): InstructionProperties(duration=4.52e-8, error=0.00032115),
         (4,): InstructionProperties(duration=4.52e-8, error=0.00032115),
     }
     self._target.add_instruction(UGate(self._theta, self._phi, self._lam), u_props)
     cx_props = {
         (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115),
         (3, 4): InstructionProperties(duration=5.23e-7, error=0.00098115),
     }
     if bidirectional:
         cx_props[(1, 0)] = InstructionProperties(duration=6.23e-7, error=0.00099115)
         cx_props[(4, 3)] = InstructionProperties(duration=7.23e-7, error=0.00099115)
     self._target.add_instruction(CXGate(), cx_props)
     measure_props = {
         (0,): InstructionProperties(duration=6e-6, error=5e-6),
         (1,): InstructionProperties(duration=1e-6, error=9e-6),
         (2,): InstructionProperties(duration=6e-6, error=5e-6),
         (3,): InstructionProperties(duration=1e-6, error=9e-6),
         (4,): InstructionProperties(duration=1e-6, error=9e-6),
     }
     self._target.add_instruction(Measure(), measure_props)
     ecr_props = {
         (1, 2): InstructionProperties(duration=4.52e-9, error=0.0000132115),
         (2, 3): InstructionProperties(duration=4.52e-9, error=0.0000132115),
     }
     if bidirectional:
         ecr_props[(2, 1)] = InstructionProperties(duration=5.52e-9, error=0.0000232115)
         ecr_props[(3, 2)] = InstructionProperties(duration=5.52e-9, error=0.0000232115)
     self._target.add_instruction(ECRGate(), ecr_props)
     self.options.set_validator("shots", (1, 4096))
     self._qubit_properties = {
         0: QubitProperties(t1=63.48783e-6, t2=112.23246e-6, frequency=5.17538e9),
         1: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
         2: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
         3: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
         4: QubitProperties(t1=73.09352e-6, t2=126.83382e-6, frequency=5.26722e9),
     }
Esempio n. 10
0
 def test_single_gate_block_outside_local_basis_with_target(self):
     """Test that a gate in basis but outside valid qubits is treated as outside basis with target."""
     qc = QuantumCircuit(2)
     target = Target(num_qubits=2)
     # Add ideal cx to (1, 0) only
     target.add_instruction(CXGate(), {(1, 0): None})
     qc.cx(0, 1)
     consolidate_block_pass = ConsolidateBlocks(target=target)
     pass_manager = PassManager()
     pass_manager.append(Collect2qBlocks())
     pass_manager.append(consolidate_block_pass)
     expected = QuantumCircuit(2)
     expected.unitary(np.array([[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]), [0, 1])
     self.assertEqual(expected, pass_manager.run(qc))
Esempio n. 11
0
 def test_single_gate_block_outside_basis_with_target(self):
     """Test a gate outside basis defined in target gets converted."""
     qc = QuantumCircuit(2)
     target = Target(num_qubits=2)
     # Add ideal basis gates to all qubits
     target.add_instruction(CXGate())
     qc.swap(0, 1)
     consolidate_block_pass = ConsolidateBlocks(target=target)
     pass_manager = PassManager()
     pass_manager.append(Collect2qBlocks())
     pass_manager.append(consolidate_block_pass)
     expected = QuantumCircuit(2)
     expected.unitary(np.array([[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]), [0, 1])
     self.assertEqual(expected, pass_manager.run(qc))
Esempio n. 12
0
 def test_ideal_target_no_coupling(self):
     """Test pass fails as expected if a target without edge constraints exists."""
     qr = QuantumRegister(5, "q")
     circuit = QuantumCircuit(qr)
     circuit.cx(qr[0], qr[3])
     circuit.cx(qr[3], qr[4])
     circuit.cx(qr[3], qr[1])
     circuit.cx(qr[0], qr[2])
     dag = circuit_to_dag(circuit)
     target = Target(num_qubits=19)
     target.add_instruction(CXGate())
     layout_pass = DenseLayout(target=target)
     with self.assertRaises(TranspilerError):
         layout_pass.run(dag)
Esempio n. 13
0
 def test_single_gate_block_outside_target_with_matching_basis_gates(self):
     """Ensure the target is the source of truth with basis_gates also set."""
     qc = QuantumCircuit(2)
     target = Target(num_qubits=2)
     # Add ideal cx to (1, 0) only
     target.add_instruction(SwapGate())
     qc.swap(0, 1)
     consolidate_block_pass = ConsolidateBlocks(
         basis_gates=["id", "cx", "rz", "sx", "x"], target=target)
     pass_manager = PassManager()
     pass_manager.append(Collect2qBlocks())
     pass_manager.append(consolidate_block_pass)
     expected = QuantumCircuit(2)
     expected.swap(0, 1)
     self.assertEqual(expected, pass_manager.run(qc))
Esempio n. 14
0
 def __init__(self):
     super().__init__(
         None,
         name="FakeSimpleV2",
         description="A fake simple BackendV2 example",
         online_date=datetime.datetime.utcnow(),
         backend_version="0.0.1",
     )
     self._lam = Parameter("lambda")
     self._target = Target(num_qubits=20)
     self._target.add_instruction(SXGate())
     self._target.add_instruction(XGate())
     self._target.add_instruction(RZGate(self._lam))
     self._target.add_instruction(CXGate())
     self._target.add_instruction(Measure())
     self._runner = QasmSimulatorPy()
Esempio n. 15
0
 def setUp(self):
     super().setUp()
     self.pulse_target = Target(
         dt=3e-7, granularity=2, min_length=4, pulse_alignment=8, aquire_alignment=8
     )
     with pulse.build(name="sx_q0") as self.custom_sx_q0:
         pulse.play(pulse.Constant(100, 0.1), pulse.DriveChannel(0))
     with pulse.build(name="sx_q1") as self.custom_sx_q1:
         pulse.play(pulse.Constant(100, 0.2), pulse.DriveChannel(1))
     sx_props = {
         (0,): InstructionProperties(
             duration=35.5e-9, error=0.000413, calibration=self.custom_sx_q0
         ),
         (1,): InstructionProperties(
             duration=35.5e-9, error=0.000502, calibration=self.custom_sx_q1
         ),
     }
     self.pulse_target.add_instruction(SXGate(), sx_props)
Esempio n. 16
0
 def test_instruction_schedule_map_ideal_sim_backend(self):
     ideal_sim_target = Target(num_qubits=3)
     theta = Parameter("theta")
     phi = Parameter("phi")
     lam = Parameter("lambda")
     for inst in [
             UGate(theta, phi, lam),
             RXGate(theta),
             RYGate(theta),
             RZGate(theta),
             CXGate(),
             ECRGate(),
             CCXGate(),
             Measure(),
     ]:
         ideal_sim_target.add_instruction(inst, {None: None})
     inst_map = ideal_sim_target.instruction_schedule_map()
     self.assertEqual(InstructionScheduleMap(), inst_map)
Esempio n. 17
0
 def test_coupling_map_and_target(self):
     """Test that a Target is used instead of a CouplingMap if both are specified."""
     cmap = CouplingMap([[0, 1], [1, 2]])
     target = Target()
     target.add_instruction(CXGate(), {
         (0, 1): None,
         (1, 2): None,
         (1, 0): None
     })
     qr = QuantumRegister(3, "qr")
     circuit = QuantumCircuit(qr)
     circuit.cx(qr[0], qr[1])  # qr0-> qr1
     circuit.cx(qr[1], qr[2])  # qr1-> qr2
     circuit.cx(qr[1], qr[0])  # qr1-> qr0
     dag = circuit_to_dag(circuit)
     pass_ = VF2Layout(cmap, seed=-1, max_trials=1, target=target)
     pass_.run(dag)
     self.assertLayout(dag, target.build_coupling_map(), pass_.property_set)
Esempio n. 18
0
 def test_5q_circuit_19q_target_without_noise(self):
     """Test layout works finds a dense 5q subgraph in a 19q heavy hex target with no noise."""
     qr = QuantumRegister(5, "q")
     circuit = QuantumCircuit(qr)
     circuit.cx(qr[0], qr[3])
     circuit.cx(qr[3], qr[4])
     circuit.cx(qr[3], qr[1])
     circuit.cx(qr[0], qr[2])
     dag = circuit_to_dag(circuit)
     instruction_props = {
         edge: None
         for edge in CouplingMap.from_heavy_hex(3).get_edges()
     }
     noiseless_target = Target()
     noiseless_target.add_instruction(CXGate, instruction_props)
     pass_ = DenseLayout(target=noiseless_target)
     pass_.run(dag)
     layout = pass_.property_set["layout"]
     self.assertEqual(layout[qr[0]], 1)
     self.assertEqual(layout[qr[1]], 13)
     self.assertEqual(layout[qr[2]], 0)
     self.assertEqual(layout[qr[3]], 9)
     self.assertEqual(layout[qr[4]], 3)
Esempio n. 19
0
 def test_instruction_supported_multiple_parameters(self):
     target = Target(1)
     target.add_instruction(
         UGate(self.theta, self.phi, self.lam),
         {(0, ): InstructionProperties(duration=270.22e-9, error=0.00713)},
     )
     self.assertFalse(
         target.instruction_supported("u", parameters=[math.pi]))
     self.assertTrue(
         target.instruction_supported(
             "u", parameters=[math.pi, math.pi, math.pi]))
     self.assertTrue(
         target.instruction_supported(
             operation_class=UGate, parameters=[math.pi, math.pi, math.pi]))
     self.assertFalse(
         target.instruction_supported(operation_class=UGate,
                                      parameters=[Parameter("x")]))
Esempio n. 20
0
 def test_multiple_gate_error_matrix(self):
     """Test error matrix ona small target with multiple gets on each qubit generates"""
     target = Target(num_qubits=3)
     phi = Parameter("phi")
     lam = Parameter("lam")
     theta = Parameter("theta")
     target.add_instruction(
         RZGate(phi), {(i, ): InstructionProperties(duration=0, error=0)
                       for i in range(3)})
     target.add_instruction(
         UGate(theta, phi, lam),
         {(i, ): InstructionProperties(duration=1e-7, error=1e-2)
          for i in range(3)},
     )
     cx_props = {
         (0, 1): InstructionProperties(error=1e-3),
         (0, 2): InstructionProperties(error=1e-3),
         (1, 0): InstructionProperties(error=1e-3),
         (1, 2): InstructionProperties(error=1e-3),
         (2, 0): InstructionProperties(error=1e-3),
         (2, 1): InstructionProperties(error=1e-3),
     }
     target.add_instruction(CXGate(), cx_props)
     ecr_props = {
         (0, 1): InstructionProperties(error=2e-2),
         (1, 2): InstructionProperties(error=2e-2),
         (2, 0): InstructionProperties(error=2e-2),
     }
     target.add_instruction(ECRGate(), ecr_props)
     expected_error_matrix = np.array([
         [1e-2, 2e-2, 1e-3],
         [1e-3, 1e-2, 2e-2],
         [2e-2, 1e-3, 1e-2],
     ])
     np.testing.assert_array_equal(expected_error_matrix,
                                   DenseLayout(target=target).error_mat)
 def test_reverse_direction(self, opt_level):
     target = Target(2)
     target.add_instruction(CXGate(), {(0, 1): InstructionProperties(error=1.2e-6)})
     target.add_instruction(ECRGate(), {(0, 1): InstructionProperties(error=1.2e-7)})
     target.add_instruction(
         UGate(Parameter("theta"), Parameter("phi"), Parameter("lam")), {(0,): None, (1,): None}
     )
     qr = QuantumRegister(2)
     circ = QuantumCircuit(qr)
     circ.append(random_unitary(4, seed=1), [1, 0])
     tqc = transpile(
         circ,
         target=target,
         optimization_level=opt_level,
         translation_method="synthesis",
         layout_method="trivial",
     )
     tqc_index = {qubit: index for index, qubit in enumerate(tqc.qubits)}
     self.assertGreaterEqual(len(tqc.get_instructions("ecr")), 1)
     for instr in tqc.get_instructions("ecr"):
         self.assertEqual((0, 1), (tqc_index[instr.qubits[0]], tqc_index[instr.qubits[1]]))
Esempio n. 22
0
 def test_coupling_map_3q_gate(self):
     fake_target = Target()
     ccx_props = {
         (0, 1, 2): None,
         (1, 0, 2): None,
         (2, 1, 0): None,
     }
     fake_target.add_instruction(CCXGate(), ccx_props)
     with self.assertLogs("qiskit.transpiler.target", level="WARN") as log:
         cmap = fake_target.build_coupling_map()
     self.assertEqual(
         log.output,
         [
             "WARNING:qiskit.transpiler.target:"
             "This Target object contains multiqubit gates that "
             "operate on > 2 qubits. This will not be reflected in "
             "the output coupling map."
         ],
     )
     self.assertEqual([], cmap.get_edges())
     with self.assertRaises(ValueError):
         fake_target.build_coupling_map("ccx")
Esempio n. 23
0
 def test_duplicate_instruction_add_instruction(self):
     target = Target()
     target.add_instruction(XGate(), {(0, ): None})
     with self.assertRaises(AttributeError):
         target.add_instruction(XGate(), {(1, ): None})
Esempio n. 24
0
    def setUp(self):
        super().setUp()
        self.fake_backend = FakeBackendV2()
        self.fake_backend_target = self.fake_backend.target
        self.theta = Parameter("theta")
        self.phi = Parameter("phi")
        self.ibm_target = Target()
        i_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(IGate(), i_props)
        rz_props = {
            (0, ): InstructionProperties(duration=0, error=0),
            (1, ): InstructionProperties(duration=0, error=0),
            (2, ): InstructionProperties(duration=0, error=0),
            (3, ): InstructionProperties(duration=0, error=0),
            (4, ): InstructionProperties(duration=0, error=0),
        }
        self.ibm_target.add_instruction(RZGate(self.theta), rz_props)
        sx_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(SXGate(), sx_props)
        x_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(XGate(), x_props)
        cx_props = {
            (3, 4): InstructionProperties(duration=270.22e-9, error=0.00713),
            (4, 3): InstructionProperties(duration=305.77e-9, error=0.00713),
            (3, 1): InstructionProperties(duration=462.22e-9, error=0.00929),
            (1, 3): InstructionProperties(duration=497.77e-9, error=0.00929),
            (1, 2): InstructionProperties(duration=227.55e-9, error=0.00659),
            (2, 1): InstructionProperties(duration=263.11e-9, error=0.00659),
            (0, 1): InstructionProperties(duration=519.11e-9, error=0.01201),
            (1, 0): InstructionProperties(duration=554.66e-9, error=0.01201),
        }
        self.ibm_target.add_instruction(CXGate(), cx_props)
        measure_props = {
            (0, ): InstructionProperties(duration=5.813e-6, error=0.0751),
            (1, ): InstructionProperties(duration=5.813e-6, error=0.0225),
            (2, ): InstructionProperties(duration=5.813e-6, error=0.0146),
            (3, ): InstructionProperties(duration=5.813e-6, error=0.0215),
            (4, ): InstructionProperties(duration=5.813e-6, error=0.0333),
        }
        self.ibm_target.add_instruction(Measure(), measure_props)

        self.aqt_target = Target(description="AQT Target")
        rx_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RXGate(self.theta), rx_props)
        ry_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RYGate(self.theta), ry_props)
        rz_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RZGate(self.theta), rz_props)
        r_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RGate(self.theta, self.phi), r_props)
        rxx_props = {
            (0, 1): None,
            (0, 2): None,
            (0, 3): None,
            (0, 4): None,
            (1, 0): None,
            (2, 0): None,
            (3, 0): None,
            (4, 0): None,
            (1, 2): None,
            (1, 3): None,
            (1, 4): None,
            (2, 1): None,
            (3, 1): None,
            (4, 1): None,
            (2, 3): None,
            (2, 4): None,
            (3, 2): None,
            (4, 2): None,
            (3, 4): None,
            (4, 3): None,
        }
        self.aqt_target.add_instruction(RXXGate(self.theta), rxx_props)
        measure_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(Measure(), measure_props)
        self.empty_target = Target()
        self.ideal_sim_target = Target(num_qubits=3,
                                       description="Ideal Simulator")
        self.lam = Parameter("lam")
        for inst in [
                UGate(self.theta, self.phi, self.lam),
                RXGate(self.theta),
                RYGate(self.theta),
                RZGate(self.theta),
                CXGate(),
                ECRGate(),
                CCXGate(),
                Measure(),
        ]:
            self.ideal_sim_target.add_instruction(inst, {None: None})
Esempio n. 25
0
class TestTarget(QiskitTestCase):
    def setUp(self):
        super().setUp()
        self.fake_backend = FakeBackendV2()
        self.fake_backend_target = self.fake_backend.target
        self.theta = Parameter("theta")
        self.phi = Parameter("phi")
        self.ibm_target = Target()
        i_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(IGate(), i_props)
        rz_props = {
            (0, ): InstructionProperties(duration=0, error=0),
            (1, ): InstructionProperties(duration=0, error=0),
            (2, ): InstructionProperties(duration=0, error=0),
            (3, ): InstructionProperties(duration=0, error=0),
            (4, ): InstructionProperties(duration=0, error=0),
        }
        self.ibm_target.add_instruction(RZGate(self.theta), rz_props)
        sx_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(SXGate(), sx_props)
        x_props = {
            (0, ): InstructionProperties(duration=35.5e-9, error=0.000413),
            (1, ): InstructionProperties(duration=35.5e-9, error=0.000502),
            (2, ): InstructionProperties(duration=35.5e-9, error=0.0004003),
            (3, ): InstructionProperties(duration=35.5e-9, error=0.000614),
            (4, ): InstructionProperties(duration=35.5e-9, error=0.006149),
        }
        self.ibm_target.add_instruction(XGate(), x_props)
        cx_props = {
            (3, 4): InstructionProperties(duration=270.22e-9, error=0.00713),
            (4, 3): InstructionProperties(duration=305.77e-9, error=0.00713),
            (3, 1): InstructionProperties(duration=462.22e-9, error=0.00929),
            (1, 3): InstructionProperties(duration=497.77e-9, error=0.00929),
            (1, 2): InstructionProperties(duration=227.55e-9, error=0.00659),
            (2, 1): InstructionProperties(duration=263.11e-9, error=0.00659),
            (0, 1): InstructionProperties(duration=519.11e-9, error=0.01201),
            (1, 0): InstructionProperties(duration=554.66e-9, error=0.01201),
        }
        self.ibm_target.add_instruction(CXGate(), cx_props)
        measure_props = {
            (0, ): InstructionProperties(duration=5.813e-6, error=0.0751),
            (1, ): InstructionProperties(duration=5.813e-6, error=0.0225),
            (2, ): InstructionProperties(duration=5.813e-6, error=0.0146),
            (3, ): InstructionProperties(duration=5.813e-6, error=0.0215),
            (4, ): InstructionProperties(duration=5.813e-6, error=0.0333),
        }
        self.ibm_target.add_instruction(Measure(), measure_props)

        self.aqt_target = Target(description="AQT Target")
        rx_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RXGate(self.theta), rx_props)
        ry_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RYGate(self.theta), ry_props)
        rz_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RZGate(self.theta), rz_props)
        r_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(RGate(self.theta, self.phi), r_props)
        rxx_props = {
            (0, 1): None,
            (0, 2): None,
            (0, 3): None,
            (0, 4): None,
            (1, 0): None,
            (2, 0): None,
            (3, 0): None,
            (4, 0): None,
            (1, 2): None,
            (1, 3): None,
            (1, 4): None,
            (2, 1): None,
            (3, 1): None,
            (4, 1): None,
            (2, 3): None,
            (2, 4): None,
            (3, 2): None,
            (4, 2): None,
            (3, 4): None,
            (4, 3): None,
        }
        self.aqt_target.add_instruction(RXXGate(self.theta), rxx_props)
        measure_props = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.aqt_target.add_instruction(Measure(), measure_props)
        self.empty_target = Target()
        self.ideal_sim_target = Target(num_qubits=3,
                                       description="Ideal Simulator")
        self.lam = Parameter("lam")
        for inst in [
                UGate(self.theta, self.phi, self.lam),
                RXGate(self.theta),
                RYGate(self.theta),
                RZGate(self.theta),
                CXGate(),
                ECRGate(),
                CCXGate(),
                Measure(),
        ]:
            self.ideal_sim_target.add_instruction(inst, {None: None})

    def test_qargs(self):
        self.assertEqual(set(), self.empty_target.qargs)
        expected_ibm = {
            (0, ),
            (1, ),
            (2, ),
            (3, ),
            (4, ),
            (3, 4),
            (4, 3),
            (3, 1),
            (1, 3),
            (1, 2),
            (2, 1),
            (0, 1),
            (1, 0),
        }
        self.assertEqual(expected_ibm, self.ibm_target.qargs)
        expected_aqt = {
            (0, ),
            (1, ),
            (2, ),
            (3, ),
            (4, ),
            (0, 1),
            (0, 2),
            (0, 3),
            (0, 4),
            (1, 0),
            (2, 0),
            (3, 0),
            (4, 0),
            (1, 2),
            (1, 3),
            (1, 4),
            (2, 1),
            (3, 1),
            (4, 1),
            (2, 3),
            (2, 4),
            (3, 2),
            (4, 2),
            (3, 4),
            (4, 3),
        }
        self.assertEqual(expected_aqt, self.aqt_target.qargs)
        expected_fake = {
            (0, ),
            (1, ),
            (0, 1),
            (1, 0),
        }
        self.assertEqual(expected_fake, self.fake_backend_target.qargs)
        self.assertEqual(None, self.ideal_sim_target.qargs)

    def test_qargs_for_operation_name(self):
        with self.assertRaises(KeyError):
            self.empty_target.qargs_for_operation_name("rz")
        self.assertEqual(self.ibm_target.qargs_for_operation_name("rz"),
                         {(0, ), (1, ), (2, ), (3, ), (4, )})
        self.assertEqual(self.aqt_target.qargs_for_operation_name("rz"),
                         {(0, ), (1, ), (2, ), (3, ), (4, )})
        self.assertEqual(
            self.fake_backend_target.qargs_for_operation_name("cx"), {(0, 1)})
        self.assertEqual(
            self.fake_backend_target.qargs_for_operation_name("ecr"),
            {
                (1, 0),
            },
        )
        self.assertEqual(self.ideal_sim_target.qargs_for_operation_name("cx"),
                         None)

    def test_instruction_names(self):
        self.assertEqual(self.empty_target.operation_names, set())
        self.assertEqual(self.ibm_target.operation_names,
                         {"rz", "id", "sx", "x", "cx", "measure"})
        self.assertEqual(self.aqt_target.operation_names,
                         {"rz", "ry", "rx", "rxx", "r", "measure"})
        self.assertEqual(self.fake_backend_target.operation_names,
                         {"u", "cx", "measure", "ecr", "rx_30", "rx"})
        self.assertEqual(
            self.ideal_sim_target.operation_names,
            {"u", "rz", "ry", "rx", "cx", "ecr", "ccx", "measure"},
        )

    def test_operations(self):
        self.assertEqual(self.empty_target.operations, [])
        ibm_expected = [
            RZGate(self.theta),
            IGate(),
            SXGate(),
            XGate(),
            CXGate(),
            Measure()
        ]
        for gate in ibm_expected:
            self.assertIn(gate, self.ibm_target.operations)
        aqt_expected = [
            RZGate(self.theta),
            RXGate(self.theta),
            RYGate(self.theta),
            RGate(self.theta, self.phi),
            RXXGate(self.theta),
        ]
        for gate in aqt_expected:
            self.assertIn(gate, self.aqt_target.operations)
        fake_expected = [
            UGate(self.fake_backend._theta, self.fake_backend._phi,
                  self.fake_backend._lam),
            CXGate(),
            Measure(),
            ECRGate(),
            RXGate(math.pi / 6),
            RXGate(self.fake_backend._theta),
        ]
        for gate in fake_expected:
            self.assertIn(gate, self.fake_backend_target.operations)
        ideal_sim_expected = [
            UGate(self.theta, self.phi, self.lam),
            RXGate(self.theta),
            RYGate(self.theta),
            RZGate(self.theta),
            CXGate(),
            ECRGate(),
            CCXGate(),
            Measure(),
        ]
        for gate in ideal_sim_expected:
            self.assertIn(gate, self.ideal_sim_target.operations)

    def test_instructions(self):
        self.assertEqual(self.empty_target.instructions, [])
        ibm_expected = [
            (IGate(), (0, )),
            (IGate(), (1, )),
            (IGate(), (2, )),
            (IGate(), (3, )),
            (IGate(), (4, )),
            (RZGate(self.theta), (0, )),
            (RZGate(self.theta), (1, )),
            (RZGate(self.theta), (2, )),
            (RZGate(self.theta), (3, )),
            (RZGate(self.theta), (4, )),
            (SXGate(), (0, )),
            (SXGate(), (1, )),
            (SXGate(), (2, )),
            (SXGate(), (3, )),
            (SXGate(), (4, )),
            (XGate(), (0, )),
            (XGate(), (1, )),
            (XGate(), (2, )),
            (XGate(), (3, )),
            (XGate(), (4, )),
            (CXGate(), (3, 4)),
            (CXGate(), (4, 3)),
            (CXGate(), (3, 1)),
            (CXGate(), (1, 3)),
            (CXGate(), (1, 2)),
            (CXGate(), (2, 1)),
            (CXGate(), (0, 1)),
            (CXGate(), (1, 0)),
            (Measure(), (0, )),
            (Measure(), (1, )),
            (Measure(), (2, )),
            (Measure(), (3, )),
            (Measure(), (4, )),
        ]
        self.assertEqual(ibm_expected, self.ibm_target.instructions)
        ideal_sim_expected = [
            (UGate(self.theta, self.phi, self.lam), None),
            (RXGate(self.theta), None),
            (RYGate(self.theta), None),
            (RZGate(self.theta), None),
            (CXGate(), None),
            (ECRGate(), None),
            (CCXGate(), None),
            (Measure(), None),
        ]
        self.assertEqual(ideal_sim_expected,
                         self.ideal_sim_target.instructions)

    def test_instruction_properties(self):
        i_gate_2 = self.ibm_target.instruction_properties(2)
        self.assertEqual(i_gate_2.error, 0.0004003)
        self.assertIsNone(self.ideal_sim_target.instruction_properties(4))

    def test_get_instruction_from_name(self):
        with self.assertRaises(KeyError):
            self.empty_target.operation_from_name("measure")
        self.assertEqual(self.ibm_target.operation_from_name("measure"),
                         Measure())
        self.assertEqual(self.fake_backend_target.operation_from_name("rx_30"),
                         RXGate(math.pi / 6))
        self.assertEqual(
            self.fake_backend_target.operation_from_name("rx"),
            RXGate(self.fake_backend._theta),
        )
        self.assertEqual(self.ideal_sim_target.operation_from_name("ccx"),
                         CCXGate())

    def test_get_instructions_for_qargs(self):
        with self.assertRaises(KeyError):
            self.empty_target.operations_for_qargs((0, ))
        expected = [RZGate(self.theta), IGate(), SXGate(), XGate(), Measure()]
        res = self.ibm_target.operations_for_qargs((0, ))
        for gate in expected:
            self.assertIn(gate, res)
        expected = [ECRGate()]
        res = self.fake_backend_target.operations_for_qargs((1, 0))
        for gate in expected:
            self.assertIn(gate, res)
        expected = [CXGate()]
        res = self.fake_backend_target.operations_for_qargs((0, 1))
        self.assertEqual(expected, res)
        ideal_sim_expected = [
            UGate(self.theta, self.phi, self.lam),
            RXGate(self.theta),
            RYGate(self.theta),
            RZGate(self.theta),
            CXGate(),
            ECRGate(),
            CCXGate(),
            Measure(),
        ]
        for gate in ideal_sim_expected:
            self.assertIn(gate,
                          self.ideal_sim_target.operations_for_qargs(None))

    def test_get_operation_names_for_qargs(self):
        with self.assertRaises(KeyError):
            self.empty_target.operation_names_for_qargs((0, ))
        expected = {"rz", "id", "sx", "x", "measure"}
        res = self.ibm_target.operation_names_for_qargs((0, ))
        for gate in expected:
            self.assertIn(gate, res)
        expected = {"ecr"}
        res = self.fake_backend_target.operation_names_for_qargs((1, 0))
        for gate in expected:
            self.assertIn(gate, res)
        expected = {"cx"}
        res = self.fake_backend_target.operation_names_for_qargs((0, 1))
        self.assertEqual(expected, res)
        ideal_sim_expected = [
            "u", "rx", "ry", "rz", "cx", "ecr", "ccx", "measure"
        ]
        for gate in ideal_sim_expected:
            self.assertIn(
                gate, self.ideal_sim_target.operation_names_for_qargs(None))

    def test_coupling_map(self):
        self.assertEqual(CouplingMap().get_edges(),
                         self.empty_target.build_coupling_map().get_edges())
        self.assertEqual(
            set(CouplingMap.from_full(5).get_edges()),
            set(self.aqt_target.build_coupling_map().get_edges()),
        )
        self.assertEqual(
            {(0, 1), (1, 0)},
            set(self.fake_backend_target.build_coupling_map().get_edges()))
        self.assertEqual(
            {
                (3, 4),
                (4, 3),
                (3, 1),
                (1, 3),
                (1, 2),
                (2, 1),
                (0, 1),
                (1, 0),
            },
            set(self.ibm_target.build_coupling_map().get_edges()),
        )
        self.assertEqual(None, self.ideal_sim_target.build_coupling_map())

    def test_coupling_map_2q_gate(self):
        cmap = self.fake_backend_target.build_coupling_map("ecr")
        self.assertEqual(
            [
                (1, 0),
            ],
            cmap.get_edges(),
        )

    def test_coupling_map_3q_gate(self):
        fake_target = Target()
        ccx_props = {
            (0, 1, 2): None,
            (1, 0, 2): None,
            (2, 1, 0): None,
        }
        fake_target.add_instruction(CCXGate(), ccx_props)
        with self.assertLogs("qiskit.transpiler.target", level="WARN") as log:
            cmap = fake_target.build_coupling_map()
        self.assertEqual(
            log.output,
            [
                "WARNING:qiskit.transpiler.target:"
                "This Target object contains multiqubit gates that "
                "operate on > 2 qubits. This will not be reflected in "
                "the output coupling map."
            ],
        )
        self.assertEqual([], cmap.get_edges())
        with self.assertRaises(ValueError):
            fake_target.build_coupling_map("ccx")

    def test_physical_qubits(self):
        self.assertEqual([], self.empty_target.physical_qubits)
        self.assertEqual(list(range(5)), self.ibm_target.physical_qubits)
        self.assertEqual(list(range(5)), self.aqt_target.physical_qubits)
        self.assertEqual(list(range(2)),
                         self.fake_backend_target.physical_qubits)
        self.assertEqual(list(range(3)), self.ideal_sim_target.physical_qubits)

    def test_duplicate_instruction_add_instruction(self):
        target = Target()
        target.add_instruction(XGate(), {(0, ): None})
        with self.assertRaises(AttributeError):
            target.add_instruction(XGate(), {(1, ): None})

    def test_durations(self):
        empty_durations = self.empty_target.durations()
        self.assertEqual(empty_durations.duration_by_name_qubits,
                         InstructionDurations().duration_by_name_qubits)
        aqt_durations = self.aqt_target.durations()
        self.assertEqual(aqt_durations.duration_by_name_qubits, {})
        ibm_durations = self.ibm_target.durations()
        expected = {
            ("cx", (0, 1)): (5.1911e-07, "s"),
            ("cx", (1, 0)): (5.5466e-07, "s"),
            ("cx", (1, 2)): (2.2755e-07, "s"),
            ("cx", (1, 3)): (4.9777e-07, "s"),
            ("cx", (2, 1)): (2.6311e-07, "s"),
            ("cx", (3, 1)): (4.6222e-07, "s"),
            ("cx", (3, 4)): (2.7022e-07, "s"),
            ("cx", (4, 3)): (3.0577e-07, "s"),
            ("id", (0, )): (3.55e-08, "s"),
            ("id", (1, )): (3.55e-08, "s"),
            ("id", (2, )): (3.55e-08, "s"),
            ("id", (3, )): (3.55e-08, "s"),
            ("id", (4, )): (3.55e-08, "s"),
            ("measure", (0, )): (5.813e-06, "s"),
            ("measure", (1, )): (5.813e-06, "s"),
            ("measure", (2, )): (5.813e-06, "s"),
            ("measure", (3, )): (5.813e-06, "s"),
            ("measure", (4, )): (5.813e-06, "s"),
            ("rz", (0, )): (0, "s"),
            ("rz", (1, )): (0, "s"),
            ("rz", (2, )): (0, "s"),
            ("rz", (3, )): (0, "s"),
            ("rz", (4, )): (0, "s"),
            ("sx", (0, )): (3.55e-08, "s"),
            ("sx", (1, )): (3.55e-08, "s"),
            ("sx", (2, )): (3.55e-08, "s"),
            ("sx", (3, )): (3.55e-08, "s"),
            ("sx", (4, )): (3.55e-08, "s"),
            ("x", (0, )): (3.55e-08, "s"),
            ("x", (1, )): (3.55e-08, "s"),
            ("x", (2, )): (3.55e-08, "s"),
            ("x", (3, )): (3.55e-08, "s"),
            ("x", (4, )): (3.55e-08, "s"),
        }
        self.assertEqual(ibm_durations.duration_by_name_qubits, expected)

    def test_mapping(self):
        with self.assertRaises(KeyError):
            _res = self.empty_target["cx"]
        expected = {
            (0, ): None,
            (1, ): None,
            (2, ): None,
            (3, ): None,
            (4, ): None,
        }
        self.assertEqual(self.aqt_target["r"], expected)
        self.assertEqual(["rx", "ry", "rz", "r", "rxx", "measure"],
                         list(self.aqt_target))
        expected_values = [
            {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            {
                (0, 1): None,
                (0, 2): None,
                (0, 3): None,
                (0, 4): None,
                (1, 0): None,
                (2, 0): None,
                (3, 0): None,
                (4, 0): None,
                (1, 2): None,
                (1, 3): None,
                (1, 4): None,
                (2, 1): None,
                (3, 1): None,
                (4, 1): None,
                (2, 3): None,
                (2, 4): None,
                (3, 2): None,
                (4, 2): None,
                (3, 4): None,
                (4, 3): None,
            },
            {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
        ]
        self.assertEqual(expected_values, list(self.aqt_target.values()))
        expected_items = {
            "rx": {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            "ry": {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            "rz": {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            "r": {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
            "rxx": {
                (0, 1): None,
                (0, 2): None,
                (0, 3): None,
                (0, 4): None,
                (1, 0): None,
                (2, 0): None,
                (3, 0): None,
                (4, 0): None,
                (1, 2): None,
                (1, 3): None,
                (1, 4): None,
                (2, 1): None,
                (3, 1): None,
                (4, 1): None,
                (2, 3): None,
                (2, 4): None,
                (3, 2): None,
                (4, 2): None,
                (3, 4): None,
                (4, 3): None,
            },
            "measure": {
                (0, ): None,
                (1, ): None,
                (2, ): None,
                (3, ): None,
                (4, ): None,
            },
        }
        self.assertEqual(expected_items, dict(self.aqt_target.items()))
        self.assertIn("cx", self.ibm_target)
        self.assertNotIn("ecr", self.ibm_target)
        self.assertEqual(len(self.ibm_target), 6)

    def test_update_instruction_properties(self):
        self.aqt_target.update_instruction_properties(
            "rxx",
            (0, 1),
            InstructionProperties(duration=1e-6, error=1e-5),
        )
        self.assertEqual(self.aqt_target["rxx"][(0, 1)].duration, 1e-6)
        self.assertEqual(self.aqt_target["rxx"][(0, 1)].error, 1e-5)

    def test_update_instruction_properties_invalid_instruction(self):
        with self.assertRaises(KeyError):
            self.ibm_target.update_instruction_properties("rxx", (0, 1), None)

    def test_update_instruction_properties_invalid_qarg(self):
        with self.assertRaises(KeyError):
            self.fake_backend_target.update_instruction_properties(
                "ecr", (0, 1), None)

    def test_str(self):
        expected = """Target
Number of qubits: 5
Instructions:
	id
		(0,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000413
		(1,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000502
		(2,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.0004003
		(3,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000614
		(4,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.006149
	rz
		(0,):
			Duration: 0 sec.
			Error Rate: 0
		(1,):
			Duration: 0 sec.
			Error Rate: 0
		(2,):
			Duration: 0 sec.
			Error Rate: 0
		(3,):
			Duration: 0 sec.
			Error Rate: 0
		(4,):
			Duration: 0 sec.
			Error Rate: 0
	sx
		(0,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000413
		(1,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000502
		(2,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.0004003
		(3,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000614
		(4,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.006149
	x
		(0,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000413
		(1,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000502
		(2,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.0004003
		(3,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000614
		(4,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.006149
	cx
		(3, 4):
			Duration: 2.7022e-07 sec.
			Error Rate: 0.00713
		(4, 3):
			Duration: 3.0577e-07 sec.
			Error Rate: 0.00713
		(3, 1):
			Duration: 4.6222e-07 sec.
			Error Rate: 0.00929
		(1, 3):
			Duration: 4.9777e-07 sec.
			Error Rate: 0.00929
		(1, 2):
			Duration: 2.2755e-07 sec.
			Error Rate: 0.00659
		(2, 1):
			Duration: 2.6311e-07 sec.
			Error Rate: 0.00659
		(0, 1):
			Duration: 5.1911e-07 sec.
			Error Rate: 0.01201
		(1, 0):
			Duration: 5.5466e-07 sec.
			Error Rate: 0.01201
	measure
		(0,):
			Duration: 5.813e-06 sec.
			Error Rate: 0.0751
		(1,):
			Duration: 5.813e-06 sec.
			Error Rate: 0.0225
		(2,):
			Duration: 5.813e-06 sec.
			Error Rate: 0.0146
		(3,):
			Duration: 5.813e-06 sec.
			Error Rate: 0.0215
		(4,):
			Duration: 5.813e-06 sec.
			Error Rate: 0.0333
"""
        self.assertEqual(expected, str(self.ibm_target))
        aqt_expected = """Target: AQT Target
Number of qubits: 5
Instructions:
	rx
		(0,)
		(1,)
		(2,)
		(3,)
		(4,)
	ry
		(0,)
		(1,)
		(2,)
		(3,)
		(4,)
	rz
		(0,)
		(1,)
		(2,)
		(3,)
		(4,)
	r
		(0,)
		(1,)
		(2,)
		(3,)
		(4,)
	rxx
		(0, 1)
		(0, 2)
		(0, 3)
		(0, 4)
		(1, 0)
		(2, 0)
		(3, 0)
		(4, 0)
		(1, 2)
		(1, 3)
		(1, 4)
		(2, 1)
		(3, 1)
		(4, 1)
		(2, 3)
		(2, 4)
		(3, 2)
		(4, 2)
		(3, 4)
		(4, 3)
	measure
		(0,)
		(1,)
		(2,)
		(3,)
		(4,)
"""
        self.assertEqual(aqt_expected, str(self.aqt_target))
        sim_expected = """Target: Ideal Simulator
Number of qubits: 3
Instructions:
	u
	rx
	ry
	rz
	cx
	ecr
	ccx
	measure
"""
        self.assertEqual(sim_expected, str(self.ideal_sim_target))

    def test_extra_props_str(self):
        target = Target(description="Extra Properties")

        class ExtraProperties(InstructionProperties):
            """An example properties subclass."""
            def __init__(
                self,
                duration=None,
                error=None,
                calibration=None,
                tuned=None,
                diamond_norm_error=None,
            ):
                super().__init__(duration=duration,
                                 error=error,
                                 calibration=calibration)
                self.tuned = tuned
                self.diamond_norm_error = diamond_norm_error

        cx_props = {
            (3, 4):
            ExtraProperties(duration=270.22e-9,
                            error=0.00713,
                            tuned=False,
                            diamond_norm_error=2.12e-6),
        }
        target.add_instruction(CXGate(), cx_props)
        expected = """Target: Extra Properties
Number of qubits: 5
Instructions:
	cx
		(3, 4):
			Duration: 2.7022e-07 sec.
			Error Rate: 0.00713
"""
        self.assertEqual(expected, str(target))

    def test_timing_constraints(self):
        generated_constraints = self.aqt_target.timing_constraints()
        expected_constraints = TimingConstraints()
        for i in [
                "granularity", "min_length", "pulse_alignment",
                "acquire_alignment"
        ]:
            self.assertEqual(
                getattr(generated_constraints, i),
                getattr(expected_constraints, i),
                f"Generated constraints differs from expected for attribute {i}"
                f"{getattr(generated_constraints, i)}!={getattr(expected_constraints, i)}",
            )

    def test_get_non_global_operation_name_ideal_backend(self):
        self.assertEqual(self.aqt_target.get_non_global_operation_names(), [])
        self.assertEqual(
            self.ideal_sim_target.get_non_global_operation_names(), [])
        self.assertEqual(self.ibm_target.get_non_global_operation_names(), [])
        self.assertEqual(
            self.fake_backend_target.get_non_global_operation_names(), [])

    def test_get_non_global_operation_name_ideal_backend_strict_direction(
            self):
        self.assertEqual(self.aqt_target.get_non_global_operation_names(True),
                         [])
        self.assertEqual(
            self.ideal_sim_target.get_non_global_operation_names(True), [])
        self.assertEqual(self.ibm_target.get_non_global_operation_names(True),
                         [])
        self.assertEqual(
            self.fake_backend_target.get_non_global_operation_names(True),
            ["cx", "ecr"])

    def test_instruction_supported(self):
        self.assertTrue(self.aqt_target.instruction_supported("r", (0, )))
        self.assertFalse(self.aqt_target.instruction_supported("cx", (0, 1)))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported("cx", (0, 1)))
        self.assertFalse(
            self.ideal_sim_target.instruction_supported("cx", (0, 524)))
        self.assertTrue(
            self.fake_backend_target.instruction_supported("cx", (0, 1)))
        self.assertFalse(
            self.fake_backend_target.instruction_supported("cx", (1, 0)))
        self.assertFalse(
            self.ideal_sim_target.instruction_supported("cx", (0, 1, 2)))

    def test_instruction_supported_parameters(self):
        mumbai = FakeMumbaiFractionalCX()
        self.assertTrue(
            mumbai.target.instruction_supported(qargs=(0, 1),
                                                operation_class=RZXGate,
                                                parameters=[math.pi / 4]))
        self.assertTrue(
            mumbai.target.instruction_supported(qargs=(0, 1),
                                                operation_class=RZXGate))
        self.assertTrue(
            mumbai.target.instruction_supported(operation_class=RZXGate,
                                                parameters=[math.pi / 4]))
        self.assertFalse(
            mumbai.target.instruction_supported("rzx",
                                                parameters=[math.pi / 4]))
        self.assertTrue(
            mumbai.target.instruction_supported(
                "rz", parameters=[Parameter("angle")]))
        self.assertTrue(
            mumbai.target.instruction_supported("rzx_45",
                                                qargs=(0, 1),
                                                parameters=[math.pi / 4]))
        self.assertTrue(
            mumbai.target.instruction_supported("rzx_45", qargs=(0, 1)))
        self.assertTrue(
            mumbai.target.instruction_supported("rzx_45",
                                                parameters=[math.pi / 4]))
        self.assertFalse(
            mumbai.target.instruction_supported("rzx_45",
                                                parameters=[math.pi / 6]))
        self.assertFalse(
            mumbai.target.instruction_supported(
                "rzx_45", parameters=[Parameter("angle")]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(
                qargs=(0, ),
                operation_class=RXGate,
                parameters=[Parameter("angle")]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(qargs=(0, ),
                                                        operation_class=RXGate,
                                                        parameters=[math.pi]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(operation_class=RXGate,
                                                        parameters=[math.pi]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(
                operation_class=RXGate, parameters=[Parameter("angle")]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(
                "rx", qargs=(0, ), parameters=[Parameter("angle")]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported("rx",
                                                        qargs=(0, ),
                                                        parameters=[math.pi]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported("rx",
                                                        parameters=[math.pi]))
        self.assertTrue(
            self.ideal_sim_target.instruction_supported(
                "rx", parameters=[Parameter("angle")]))

    def test_instruction_supported_multiple_parameters(self):
        target = Target(1)
        target.add_instruction(
            UGate(self.theta, self.phi, self.lam),
            {(0, ): InstructionProperties(duration=270.22e-9, error=0.00713)},
        )
        self.assertFalse(
            target.instruction_supported("u", parameters=[math.pi]))
        self.assertTrue(
            target.instruction_supported(
                "u", parameters=[math.pi, math.pi, math.pi]))
        self.assertTrue(
            target.instruction_supported(
                operation_class=UGate, parameters=[math.pi, math.pi, math.pi]))
        self.assertFalse(
            target.instruction_supported(operation_class=UGate,
                                         parameters=[Parameter("x")]))

    def test_instruction_supported_arg_len_mismatch(self):
        self.assertFalse(
            self.ideal_sim_target.instruction_supported(operation_class=UGate,
                                                        parameters=[math.pi]))
        self.assertFalse(
            self.ideal_sim_target.instruction_supported("u",
                                                        parameters=[math.pi]))

    def test_instruction_supported_class_not_in_target(self):
        self.assertFalse(
            self.ibm_target.instruction_supported(operation_class=CZGate,
                                                  parameters=[math.pi]))

    def test_instruction_supported_no_args(self):
        self.assertFalse(self.ibm_target.instruction_supported())

    def test_instruction_supported_no_operation(self):
        self.assertFalse(
            self.ibm_target.instruction_supported(qargs=(0, ),
                                                  parameters=[math.pi]))
Esempio n. 26
0
class FakeBackendV2(BackendV2):
    """A mock backend that doesn't implement run() to test compatibility with Terra internals."""
    def __init__(self):
        super().__init__(
            None,
            name="FakeV2",
            description="A fake BackendV2 example",
            online_date=datetime.datetime.utcnow(),
            backend_version="0.0.1",
        )
        self._target = Target()
        self._theta = Parameter("theta")
        self._phi = Parameter("phi")
        self._lam = Parameter("lambda")
        rx_props = {
            (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
            (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
        }
        self._target.add_instruction(RXGate(self._theta), rx_props)
        rx_30_props = {
            (0, ): InstructionProperties(duration=1.23e-8, error=0.00018115),
            (1, ): InstructionProperties(duration=1.52e-8, error=0.00012115),
        }
        self._target.add_instruction(RXGate(np.pi / 6),
                                     rx_30_props,
                                     name="rx_30")
        u_props = {
            (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
            (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
        }
        self._target.add_instruction(UGate(self._theta, self._phi, self._lam),
                                     u_props)
        cx_props = {
            (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115),
        }
        self._target.add_instruction(CXGate(), cx_props)
        measure_props = {
            (0, ): InstructionProperties(duration=6e-6, error=5e-6),
            (1, ): InstructionProperties(duration=1e-6, error=9e-6),
        }
        self._target.add_instruction(Measure(), measure_props)
        ecr_props = {
            (1, 0): InstructionProperties(duration=4.52e-9,
                                          error=0.0000132115),
        }
        self._target.add_instruction(ECRGate(), ecr_props)
        self.options.set_validator("shots", (1, 4096))
        self._qubit_properties = {
            0:
            QubitProperties(t1=63.48783e-6,
                            t2=112.23246e-6,
                            frequency=5.17538e9),
            1:
            QubitProperties(t1=73.09352e-6,
                            t2=126.83382e-6,
                            frequency=5.26722e9),
        }

    @property
    def target(self):
        return self._target

    @property
    def max_circuits(self):
        return None

    @classmethod
    def _default_options(cls):
        return Options(shots=1024)

    def run(self, run_input, **options):
        raise NotImplementedError

    def qubit_properties(self, qubit):
        if isinstance(qubit, int):
            return self._qubit_properties[qubit]
        return [self._qubit_properties[i] for i in qubit]
Esempio n. 27
0
class TestPulseTarget(QiskitTestCase):
    def setUp(self):
        super().setUp()
        self.pulse_target = Target(dt=3e-7,
                                   granularity=2,
                                   min_length=4,
                                   pulse_alignment=8,
                                   aquire_alignment=8)
        with pulse.build(name="sx_q0") as self.custom_sx_q0:
            pulse.play(pulse.Constant(100, 0.1), pulse.DriveChannel(0))
        with pulse.build(name="sx_q1") as self.custom_sx_q1:
            pulse.play(pulse.Constant(100, 0.2), pulse.DriveChannel(1))
        sx_props = {
            (0, ):
            InstructionProperties(duration=35.5e-9,
                                  error=0.000413,
                                  calibration=self.custom_sx_q0),
            (1, ):
            InstructionProperties(duration=35.5e-9,
                                  error=0.000502,
                                  calibration=self.custom_sx_q1),
        }
        self.pulse_target.add_instruction(SXGate(), sx_props)

    def test_instruction_schedule_map(self):
        inst_map = self.pulse_target.instruction_schedule_map()
        self.assertIn("sx", inst_map.instructions)
        self.assertEqual(inst_map.qubits_with_instruction("sx"), [0, 1])
        self.assertTrue("sx" in inst_map.qubit_instructions(0))

    def test_instruction_schedule_map_ideal_sim_backend(self):
        ideal_sim_target = Target(num_qubits=3)
        theta = Parameter("theta")
        phi = Parameter("phi")
        lam = Parameter("lambda")
        for inst in [
                UGate(theta, phi, lam),
                RXGate(theta),
                RYGate(theta),
                RZGate(theta),
                CXGate(),
                ECRGate(),
                CCXGate(),
                Measure(),
        ]:
            ideal_sim_target.add_instruction(inst, {None: None})
        inst_map = ideal_sim_target.instruction_schedule_map()
        self.assertEqual(InstructionScheduleMap(), inst_map)

    def test_str(self):
        expected = """Target
Number of qubits: 2
Instructions:
	sx
		(0,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000413
			With pulse schedule calibration
		(1,):
			Duration: 3.55e-08 sec.
			Error Rate: 0.000502
			With pulse schedule calibration
"""
        self.assertEqual(expected, str(self.pulse_target))

    def test_update_from_instruction_schedule_map_add_instruction(self):
        target = Target()
        inst_map = InstructionScheduleMap()
        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, self.custom_sx_q1)
        target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()})
        self.assertEqual(inst_map, target.instruction_schedule_map())

    def test_update_from_instruction_schedule_map_update_schedule(self):
        self.pulse_target.dt = None
        inst_map = InstructionScheduleMap()
        with pulse.build(name="sx_q1") as custom_sx:
            pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1))

        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, custom_sx)
        self.pulse_target.update_from_instruction_schedule_map(
            inst_map, {"sx": SXGate()})
        self.assertEqual(inst_map,
                         self.pulse_target.instruction_schedule_map())
        self.assertIsNone(self.pulse_target["sx"][(0, )].duration)
        self.assertIsNone(self.pulse_target["sx"][(0, )].error)
        self.assertIsNone(self.pulse_target["sx"][(1, )].duration)
        self.assertIsNone(self.pulse_target["sx"][(1, )].error)

    def test_update_from_instruction_schedule_map_new_instruction_no_name_map(
            self):
        target = Target()
        inst_map = InstructionScheduleMap()
        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, self.custom_sx_q1)
        with self.assertRaises(ValueError):
            target.update_from_instruction_schedule_map(inst_map)

    def test_update_from_instruction_schedule_map_new_qarg_raises(self):
        inst_map = InstructionScheduleMap()
        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, self.custom_sx_q1)
        inst_map.add("sx", 2, self.custom_sx_q1)
        with self.assertRaises(KeyError):
            self.pulse_target.update_from_instruction_schedule_map(inst_map)

    def test_update_from_instruction_schedule_map_with_dt_set(self):
        inst_map = InstructionScheduleMap()
        with pulse.build(name="sx_q1") as custom_sx:
            pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1))

        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, custom_sx)
        self.pulse_target.dt = 1.0
        self.pulse_target.update_from_instruction_schedule_map(
            inst_map, {"sx": SXGate()})
        self.assertEqual(inst_map,
                         self.pulse_target.instruction_schedule_map())
        self.assertEqual(self.pulse_target["sx"][(1, )].duration, 1000.0)
        self.assertIsNone(self.pulse_target["sx"][(1, )].error)
        self.assertIsNone(self.pulse_target["sx"][(0, )].error)

    def test_update_from_instruction_schedule_map_with_error_dict(self):
        inst_map = InstructionScheduleMap()
        with pulse.build(name="sx_q1") as custom_sx:
            pulse.play(pulse.Constant(1000, 0.2), pulse.DriveChannel(1))

        inst_map.add("sx", 0, self.custom_sx_q0)
        inst_map.add("sx", 1, custom_sx)
        self.pulse_target.dt = 1.0
        error_dict = {"sx": {(1, ): 1.0}}

        self.pulse_target.update_from_instruction_schedule_map(
            inst_map, {"sx": SXGate()}, error_dict=error_dict)
        self.assertEqual(self.pulse_target["sx"][(1, )].error, 1.0)
        self.assertIsNone(self.pulse_target["sx"][(0, )].error)

    def test_timing_constraints(self):
        generated_constraints = self.pulse_target.timing_constraints()
        expected_constraints = TimingConstraints(2, 4, 8, 8)
        for i in [
                "granularity", "min_length", "pulse_alignment",
                "acquire_alignment"
        ]:
            self.assertEqual(
                getattr(generated_constraints, i),
                getattr(expected_constraints, i),
                f"Generated constraints differs from expected for attribute {i}"
                f"{getattr(generated_constraints, i)}!={getattr(expected_constraints, i)}",
            )
Esempio n. 28
0
class TestDenseLayout(QiskitTestCase):
    """Tests the DenseLayout pass"""
    def setUp(self):
        super().setUp()
        self.cmap20 = FakeTokyo().configuration().coupling_map
        self.target_19 = Target()
        rng = np.random.default_rng(12345)
        instruction_props = {
            edge: InstructionProperties(duration=rng.uniform(1e-7, 1e-6),
                                        error=rng.uniform(1e-4, 1e-3))
            for edge in CouplingMap.from_heavy_hex(3).get_edges()
        }
        self.target_19.add_instruction(CXGate(), instruction_props)

    def test_5q_circuit_20q_coupling(self):
        """Test finds dense 5q corner in 20q coupling map."""
        qr = QuantumRegister(5, "q")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[0], qr[3])
        circuit.cx(qr[3], qr[4])
        circuit.cx(qr[3], qr[1])
        circuit.cx(qr[0], qr[2])

        dag = circuit_to_dag(circuit)
        pass_ = DenseLayout(CouplingMap(self.cmap20))
        pass_.run(dag)

        layout = pass_.property_set["layout"]
        self.assertEqual(layout[qr[0]], 11)
        self.assertEqual(layout[qr[1]], 10)
        self.assertEqual(layout[qr[2]], 6)
        self.assertEqual(layout[qr[3]], 5)
        self.assertEqual(layout[qr[4]], 0)

    def test_6q_circuit_20q_coupling(self):
        """Test finds dense 5q corner in 20q coupling map."""
        qr0 = QuantumRegister(3, "q0")
        qr1 = QuantumRegister(3, "q1")
        circuit = QuantumCircuit(qr0, qr1)
        circuit.cx(qr0[0], qr1[2])
        circuit.cx(qr1[1], qr0[2])

        dag = circuit_to_dag(circuit)
        pass_ = DenseLayout(CouplingMap(self.cmap20))
        pass_.run(dag)

        layout = pass_.property_set["layout"]
        self.assertEqual(layout[qr0[0]], 11)
        self.assertEqual(layout[qr0[1]], 10)
        self.assertEqual(layout[qr0[2]], 6)
        self.assertEqual(layout[qr1[0]], 5)
        self.assertEqual(layout[qr1[1]], 1)
        self.assertEqual(layout[qr1[2]], 0)

    def test_5q_circuit_19q_target_with_noise(self):
        """Test layout works finds a dense 5q subgraph in a 19q heavy hex target."""
        qr = QuantumRegister(5, "q")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[0], qr[3])
        circuit.cx(qr[3], qr[4])
        circuit.cx(qr[3], qr[1])
        circuit.cx(qr[0], qr[2])
        dag = circuit_to_dag(circuit)
        pass_ = DenseLayout(target=self.target_19)
        pass_.run(dag)
        layout = pass_.property_set["layout"]
        self.assertEqual(layout[qr[0]], 9)
        self.assertEqual(layout[qr[1]], 3)
        self.assertEqual(layout[qr[2]], 11)
        self.assertEqual(layout[qr[3]], 15)
        self.assertEqual(layout[qr[4]], 4)

    def test_5q_circuit_19q_target_without_noise(self):
        """Test layout works finds a dense 5q subgraph in a 19q heavy hex target with no noise."""
        qr = QuantumRegister(5, "q")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[0], qr[3])
        circuit.cx(qr[3], qr[4])
        circuit.cx(qr[3], qr[1])
        circuit.cx(qr[0], qr[2])
        dag = circuit_to_dag(circuit)
        instruction_props = {
            edge: None
            for edge in CouplingMap.from_heavy_hex(3).get_edges()
        }
        noiseless_target = Target()
        noiseless_target.add_instruction(CXGate, instruction_props)
        pass_ = DenseLayout(target=noiseless_target)
        pass_.run(dag)
        layout = pass_.property_set["layout"]
        self.assertEqual(layout[qr[0]], 1)
        self.assertEqual(layout[qr[1]], 13)
        self.assertEqual(layout[qr[2]], 0)
        self.assertEqual(layout[qr[3]], 9)
        self.assertEqual(layout[qr[4]], 3)

    def test_ideal_target_no_coupling(self):
        """Test pass fails as expected if a target without edge constraints exists."""
        qr = QuantumRegister(5, "q")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[0], qr[3])
        circuit.cx(qr[3], qr[4])
        circuit.cx(qr[3], qr[1])
        circuit.cx(qr[0], qr[2])
        dag = circuit_to_dag(circuit)
        target = Target(num_qubits=19)
        target.add_instruction(CXGate())
        layout_pass = DenseLayout(target=target)
        with self.assertRaises(TranspilerError):
            layout_pass.run(dag)

    def test_target_too_small_for_circuit(self):
        """Test error is raised when target is too small for circuit."""
        target = Target()
        target.add_instruction(
            CXGate(),
            {edge: None
             for edge in CouplingMap.from_line(3).get_edges()})
        dag = circuit_to_dag(QuantumCircuit(5))
        layout_pass = DenseLayout(target=target)
        with self.assertRaises(TranspilerError):
            layout_pass.run(dag)

    def test_19q_target_with_noise_error_matrix(self):
        """Test the error matrix construction works for a just cx target."""
        pass_ = DenseLayout(target=self.target_19)
        expected_error_mat = np.zeros((19, 19))
        for qargs, props in self.target_19["cx"].items():
            error = props.error
            expected_error_mat[qargs[0]][qargs[1]] = error
        np.testing.assert_array_equal(expected_error_mat, pass_.error_mat)

    def test_multiple_gate_error_matrix(self):
        """Test error matrix ona small target with multiple gets on each qubit generates"""
        target = Target(num_qubits=3)
        phi = Parameter("phi")
        lam = Parameter("lam")
        theta = Parameter("theta")
        target.add_instruction(
            RZGate(phi), {(i, ): InstructionProperties(duration=0, error=0)
                          for i in range(3)})
        target.add_instruction(
            UGate(theta, phi, lam),
            {(i, ): InstructionProperties(duration=1e-7, error=1e-2)
             for i in range(3)},
        )
        cx_props = {
            (0, 1): InstructionProperties(error=1e-3),
            (0, 2): InstructionProperties(error=1e-3),
            (1, 0): InstructionProperties(error=1e-3),
            (1, 2): InstructionProperties(error=1e-3),
            (2, 0): InstructionProperties(error=1e-3),
            (2, 1): InstructionProperties(error=1e-3),
        }
        target.add_instruction(CXGate(), cx_props)
        ecr_props = {
            (0, 1): InstructionProperties(error=2e-2),
            (1, 2): InstructionProperties(error=2e-2),
            (2, 0): InstructionProperties(error=2e-2),
        }
        target.add_instruction(ECRGate(), ecr_props)
        expected_error_matrix = np.array([
            [1e-2, 2e-2, 1e-3],
            [1e-3, 1e-2, 2e-2],
            [2e-2, 1e-3, 1e-2],
        ])
        np.testing.assert_array_equal(expected_error_matrix,
                                      DenseLayout(target=target).error_mat)
Esempio n. 29
0
class FakeBackend5QV2(BackendV2):
    """A mock backend that doesn't implement run() to test compatibility with Terra internals."""
    def __init__(self, bidirectional=True):
        super().__init__(
            None,
            name="Fake5QV2",
            description="A fake BackendV2 example",
            online_date=datetime.datetime.utcnow(),
            backend_version="0.0.1",
        )
        qubit_properties = [
            QubitProperties(t1=63.48783e-6,
                            t2=112.23246e-6,
                            frequency=5.17538e9),
            QubitProperties(t1=73.09352e-6,
                            t2=126.83382e-6,
                            frequency=5.26722e9),
            QubitProperties(t1=73.09352e-6,
                            t2=126.83382e-6,
                            frequency=5.26722e9),
            QubitProperties(t1=73.09352e-6,
                            t2=126.83382e-6,
                            frequency=5.26722e9),
            QubitProperties(t1=73.09352e-6,
                            t2=126.83382e-6,
                            frequency=5.26722e9),
        ]
        self._target = Target(qubit_properties=qubit_properties)
        self._theta = Parameter("theta")
        self._phi = Parameter("phi")
        self._lam = Parameter("lambda")
        u_props = {
            (0, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
            (1, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
            (2, ): InstructionProperties(duration=5.23e-8, error=0.00038115),
            (3, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
            (4, ): InstructionProperties(duration=4.52e-8, error=0.00032115),
        }
        self._target.add_instruction(UGate(self._theta, self._phi, self._lam),
                                     u_props)
        cx_props = {
            (0, 1): InstructionProperties(duration=5.23e-7, error=0.00098115),
            (3, 4): InstructionProperties(duration=5.23e-7, error=0.00098115),
        }
        if bidirectional:
            cx_props[(1, 0)] = InstructionProperties(duration=6.23e-7,
                                                     error=0.00099115)
            cx_props[(4, 3)] = InstructionProperties(duration=7.23e-7,
                                                     error=0.00099115)
        self._target.add_instruction(CXGate(), cx_props)
        measure_props = {
            (0, ): InstructionProperties(duration=6e-6, error=5e-6),
            (1, ): InstructionProperties(duration=1e-6, error=9e-6),
            (2, ): InstructionProperties(duration=6e-6, error=5e-6),
            (3, ): InstructionProperties(duration=1e-6, error=9e-6),
            (4, ): InstructionProperties(duration=1e-6, error=9e-6),
        }
        self._target.add_instruction(Measure(), measure_props)
        ecr_props = {
            (1, 2): InstructionProperties(duration=4.52e-9,
                                          error=0.0000132115),
            (2, 3): InstructionProperties(duration=4.52e-9,
                                          error=0.0000132115),
        }
        if bidirectional:
            ecr_props[(2, 1)] = InstructionProperties(duration=5.52e-9,
                                                      error=0.0000232115)
            ecr_props[(3, 2)] = InstructionProperties(duration=5.52e-9,
                                                      error=0.0000232115)
        self._target.add_instruction(ECRGate(), ecr_props)
        self.options.set_validator("shots", (1, 4096))

    @property
    def target(self):
        return self._target

    @property
    def max_circuits(self):
        return None

    @classmethod
    def _default_options(cls):
        return Options(shots=1024)

    def run(self, run_input, **options):
        raise NotImplementedError
Esempio n. 30
0
    def __init__(self):
        super().__init__(
            name="FakeMumbaiV2",
            description="A fake BackendV2 example based on IBM Mumbai",
            online_date=datetime.datetime.utcnow(),
            backend_version="0.0.1",
        )
        dt = 0.2222222222222222e-9
        self._target = Target(dt=dt)
        self._phi = Parameter("phi")
        rz_props = {
            (0, ): InstructionProperties(duration=0.0, error=0),
            (1, ): InstructionProperties(duration=0.0, error=0),
            (2, ): InstructionProperties(duration=0.0, error=0),
            (3, ): InstructionProperties(duration=0.0, error=0),
            (4, ): InstructionProperties(duration=0.0, error=0),
            (5, ): InstructionProperties(duration=0.0, error=0),
            (6, ): InstructionProperties(duration=0.0, error=0),
            (7, ): InstructionProperties(duration=0.0, error=0),
            (8, ): InstructionProperties(duration=0.0, error=0),
            (9, ): InstructionProperties(duration=0.0, error=0),
            (10, ): InstructionProperties(duration=0.0, error=0),
            (11, ): InstructionProperties(duration=0.0, error=0),
            (12, ): InstructionProperties(duration=0.0, error=0),
            (13, ): InstructionProperties(duration=0.0, error=0),
            (14, ): InstructionProperties(duration=0.0, error=0),
            (15, ): InstructionProperties(duration=0.0, error=0),
            (16, ): InstructionProperties(duration=0.0, error=0),
            (17, ): InstructionProperties(duration=0.0, error=0),
            (18, ): InstructionProperties(duration=0.0, error=0),
            (19, ): InstructionProperties(duration=0.0, error=0),
            (20, ): InstructionProperties(duration=0.0, error=0),
            (21, ): InstructionProperties(duration=0.0, error=0),
            (22, ): InstructionProperties(duration=0.0, error=0),
            (23, ): InstructionProperties(duration=0.0, error=0),
            (24, ): InstructionProperties(duration=0.0, error=0),
            (25, ): InstructionProperties(duration=0.0, error=0),
            (26, ): InstructionProperties(duration=0.0, error=0),
        }
        self._target.add_instruction(RZGate(self._phi), rz_props)
        x_props = {
            (0, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00020056469709026198),
            (1, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0004387432040599484),
            (2, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002196765027963209),
            (3, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0003065541555566093),
            (4, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002402026686478811),
            (5, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002162777062721698),
            (6, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00021981280474256117),
            (7, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00018585647396926756),
            (8, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00027053333211825124),
            (9, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002603116226593832),
            (10, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00023827406030798066),
            (11, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024856063217108685),
            (12, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002065075637361354),
            (13, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024898181450337464),
            (14, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00017758796319636606),
            (15, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00016530893922883836),
            (16, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0003213658218204255),
            (17, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024068450432012685),
            (18, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00026676441863976344),
            (19, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00017090891698571018),
            (20, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00021057196071004095),
            (21, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00030445404779882887),
            (22, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00019322295843406375),
            (23, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00030966037392287727),
            (24, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00023570754161126),
            (25, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00018367783963229033),
            (26, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00019630609928571516),
        }
        self._target.add_instruction(XGate(), x_props)
        sx_props = {
            (0, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00020056469709026198),
            (1, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0004387432040599484),
            (2, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002196765027963209),
            (3, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0003065541555566093),
            (4, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002402026686478811),
            (5, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002162777062721698),
            (6, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00021981280474256117),
            (7, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00018585647396926756),
            (8, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00027053333211825124),
            (9, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002603116226593832),
            (10, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00023827406030798066),
            (11, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024856063217108685),
            (12, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0002065075637361354),
            (13, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024898181450337464),
            (14, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00017758796319636606),
            (15, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00016530893922883836),
            (16, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.0003213658218204255),
            (17, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00024068450432012685),
            (18, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00026676441863976344),
            (19, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00017090891698571018),
            (20, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00021057196071004095),
            (21, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00030445404779882887),
            (22, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00019322295843406375),
            (23, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00030966037392287727),
            (24, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00023570754161126),
            (25, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00018367783963229033),
            (26, ):
            InstructionProperties(duration=3.5555555555555554e-08,
                                  error=0.00019630609928571516),
        }
        self._target.add_instruction(SXGate(), sx_props)
        chunk_size = 16
        cx_props = {
            (0, 1):
            InstructionProperties(duration=101 * chunk_size * dt,
                                  error=0.030671121181161276),
            (4, 1):
            InstructionProperties(duration=70 * chunk_size * dt,
                                  error=0.014041986073052737),
            (4, 7):
            InstructionProperties(duration=74 * chunk_size * dt,
                                  error=0.0052040275323747),
            (10, 7):
            InstructionProperties(duration=92 * chunk_size * dt,
                                  error=0.005625282141655502),
            (10, 12):
            InstructionProperties(duration=84 * chunk_size * dt,
                                  error=0.005771827440726435),
            (15, 12):
            InstructionProperties(duration=84 * chunk_size * dt,
                                  error=0.0050335609425562755),
            (15, 18):
            InstructionProperties(duration=64 * chunk_size * dt,
                                  error=0.0051374141171115495),
            (12, 13):
            InstructionProperties(duration=70 * chunk_size * dt,
                                  error=0.011361175954064051),
            (13, 14):
            InstructionProperties(duration=101 * chunk_size * dt,
                                  error=0.005231334872256355),
            # From FakeMumbai:
            (1, 0):
            InstructionProperties(duration=4.551111111111111e-07,
                                  error=0.030671121181161276),
            (1, 2):
            InstructionProperties(duration=7.395555555555556e-07,
                                  error=0.03420291964205785),
            (1, 4):
            InstructionProperties(duration=3.6266666666666663e-07,
                                  error=0.014041986073052737),
            (2, 1):
            InstructionProperties(duration=7.04e-07,
                                  error=0.03420291964205785),
            (2, 3):
            InstructionProperties(duration=4.266666666666666e-07,
                                  error=0.005618162036535312),
            (3, 2):
            InstructionProperties(duration=3.911111111111111e-07,
                                  error=0.005618162036535312),
            (3, 5):
            InstructionProperties(duration=3.5555555555555553e-07,
                                  error=0.006954580732294352),
            (5, 3):
            InstructionProperties(duration=3.911111111111111e-07,
                                  error=0.006954580732294352),
            (5, 8):
            InstructionProperties(duration=1.3155555555555553e-06,
                                  error=0.021905829471073668),
            (6, 7):
            InstructionProperties(duration=2.4177777777777775e-07,
                                  error=0.011018069718028878),
            (7, 4):
            InstructionProperties(duration=3.7688888888888884e-07,
                                  error=0.0052040275323747),
            (7, 6):
            InstructionProperties(duration=2.7733333333333333e-07,
                                  error=0.011018069718028878),
            (7, 10):
            InstructionProperties(duration=4.337777777777778e-07,
                                  error=0.005625282141655502),
            (8, 5):
            InstructionProperties(duration=1.351111111111111e-06,
                                  error=0.021905829471073668),
            (8, 9):
            InstructionProperties(duration=6.897777777777777e-07,
                                  error=0.011889378687341773),
            (8, 11):
            InstructionProperties(duration=5.902222222222222e-07,
                                  error=0.009523844852027258),
            (9, 8):
            InstructionProperties(duration=6.542222222222222e-07,
                                  error=0.011889378687341773),
            (11, 8):
            InstructionProperties(duration=6.257777777777777e-07,
                                  error=0.009523844852027258),
            (11, 14):
            InstructionProperties(duration=4.053333333333333e-07,
                                  error=0.004685421425282804),
            (12, 10):
            InstructionProperties(duration=3.9822222222222215e-07,
                                  error=0.005771827440726435),
            (12, 15):
            InstructionProperties(duration=4.053333333333333e-07,
                                  error=0.0050335609425562755),
            (13, 12):
            InstructionProperties(duration=5.831111111111111e-07,
                                  error=0.011361175954064051),
            (14, 11):
            InstructionProperties(duration=3.697777777777778e-07,
                                  error=0.004685421425282804),
            (14, 13):
            InstructionProperties(duration=3.5555555555555553e-07,
                                  error=0.005231334872256355),
            (14, 16):
            InstructionProperties(duration=3.484444444444444e-07,
                                  error=0.0051117141032224755),
            (16, 14):
            InstructionProperties(duration=3.1288888888888885e-07,
                                  error=0.0051117141032224755),
            (16, 19):
            InstructionProperties(duration=7.537777777777777e-07,
                                  error=0.013736796355458464),
            (17, 18):
            InstructionProperties(duration=2.488888888888889e-07,
                                  error=0.007267536233537236),
            (18, 15):
            InstructionProperties(duration=3.413333333333333e-07,
                                  error=0.0051374141171115495),
            (18, 17):
            InstructionProperties(duration=2.8444444444444443e-07,
                                  error=0.007267536233537236),
            (18, 21):
            InstructionProperties(duration=4.977777777777778e-07,
                                  error=0.007718304749257138),
            (19, 16):
            InstructionProperties(duration=7.182222222222222e-07,
                                  error=0.013736796355458464),
            (19, 20):
            InstructionProperties(duration=4.266666666666666e-07,
                                  error=0.005757038521092134),
            (19, 22):
            InstructionProperties(duration=3.6266666666666663e-07,
                                  error=0.004661878013991871),
            (20, 19):
            InstructionProperties(duration=3.911111111111111e-07,
                                  error=0.005757038521092134),
            (21, 18):
            InstructionProperties(duration=5.333333333333332e-07,
                                  error=0.007718304749257138),
            (21, 23):
            InstructionProperties(duration=3.911111111111111e-07,
                                  error=0.007542515578725928),
            (22, 19):
            InstructionProperties(duration=3.271111111111111e-07,
                                  error=0.004661878013991871),
            (22, 25):
            InstructionProperties(duration=4.835555555555555e-07,
                                  error=0.005536735115231589),
            (23, 21):
            InstructionProperties(duration=4.266666666666666e-07,
                                  error=0.007542515578725928),
            (23, 24):
            InstructionProperties(duration=6.613333333333332e-07,
                                  error=0.010797784688907186),
            (24, 23):
            InstructionProperties(duration=6.257777777777777e-07,
                                  error=0.010797784688907186),
            (24, 25):
            InstructionProperties(duration=4.337777777777778e-07,
                                  error=0.006127506135155392),
            (25, 22):
            InstructionProperties(duration=4.48e-07,
                                  error=0.005536735115231589),
            (25, 24):
            InstructionProperties(duration=4.693333333333333e-07,
                                  error=0.006127506135155392),
            (25, 26):
            InstructionProperties(duration=3.484444444444444e-07,
                                  error=0.0048451525929122385),
            (26, 25):
            InstructionProperties(duration=3.1288888888888885e-07,
                                  error=0.0048451525929122385),
        }
        self.target.add_instruction(CXGate(), cx_props)
        # Error and duration the same as CX
        rzx_90_props = {
            (0, 1):
            InstructionProperties(duration=101 * chunk_size * dt,
                                  error=0.030671121181161276),
            (4, 1):
            InstructionProperties(duration=70 * chunk_size * dt,
                                  error=0.014041986073052737),
            (4, 7):
            InstructionProperties(duration=74 * chunk_size * dt,
                                  error=0.0052040275323747),
            (10, 7):
            InstructionProperties(duration=92 * chunk_size * dt,
                                  error=0.005625282141655502),
            (10, 12):
            InstructionProperties(duration=84 * chunk_size * dt,
                                  error=0.005771827440726435),
            (15, 12):
            InstructionProperties(duration=84 * chunk_size * dt,
                                  error=0.0050335609425562755),
            (15, 18):
            InstructionProperties(duration=64 * chunk_size * dt,
                                  error=0.0051374141171115495),
            (12, 13):
            InstructionProperties(duration=70 * chunk_size * dt,
                                  error=0.011361175954064051),
            (13, 14):
            InstructionProperties(duration=101 * chunk_size * dt,
                                  error=0.005231334872256355),
        }
        self.target.add_instruction(RZXGate(np.pi / 2),
                                    rzx_90_props,
                                    name="rzx_90")
        rzx_45_props = {
            (0, 1):
            InstructionProperties(duration=52 * chunk_size * dt,
                                  error=0.030671121181161276 / 2),
            (4, 1):
            InstructionProperties(duration=37 * chunk_size * dt,
                                  error=0.014041986073052737 / 2),
            (4, 7):
            InstructionProperties(duration=40 * chunk_size * dt,
                                  error=0.0052040275323747 / 2),
            (10, 7):
            InstructionProperties(duration=46 * chunk_size * dt,
                                  error=0.005625282141655502 / 2),
            (10, 12):
            InstructionProperties(duration=45 * chunk_size * dt,
                                  error=0.005771827440726435 / 2),
            (15, 12):
            InstructionProperties(duration=42 * chunk_size * dt,
                                  error=0.0050335609425562755 / 2),
            (15, 18):
            InstructionProperties(duration=34 * chunk_size * dt,
                                  error=0.0051374141171115495 / 2),
            (12, 13):
            InstructionProperties(duration=37 * chunk_size * dt,
                                  error=0.011361175954064051 / 2),
            (13, 14):
            InstructionProperties(duration=52 * chunk_size * dt,
                                  error=0.005231334872256355 / 2),
        }
        self.target.add_instruction(RZXGate(np.pi / 4),
                                    rzx_45_props,
                                    name="rzx_45")
        rzx_30_props = {
            (0, 1):
            InstructionProperties(duration=37 * chunk_size * dt,
                                  error=0.030671121181161276 / 3),
            (4, 1):
            InstructionProperties(duration=24 * chunk_size * dt,
                                  error=0.014041986073052737 / 3),
            (4, 7):
            InstructionProperties(duration=29 * chunk_size * dt,
                                  error=0.0052040275323747 / 3),
            (10, 7):
            InstructionProperties(duration=32 * chunk_size * dt,
                                  error=0.005625282141655502 / 3),
            (10, 12):
            InstructionProperties(duration=32 * chunk_size * dt,
                                  error=0.005771827440726435 / 3),
            (15, 12):
            InstructionProperties(duration=29 * chunk_size * dt,
                                  error=0.0050335609425562755 / 3),
            (15, 18):
            InstructionProperties(duration=26 * chunk_size * dt,
                                  error=0.0051374141171115495 / 3),
            (12, 13):
            InstructionProperties(duration=24 * chunk_size * dt,
                                  error=0.011361175954064051 / 3),
            (13, 14):
            InstructionProperties(duration=377 * chunk_size * dt,
                                  error=0.005231334872256355 / 3),
        }
        self.target.add_instruction(RZXGate(np.pi / 6),
                                    rzx_30_props,
                                    name="rzx_30")
        reset_props = {(i, ):
                       InstructionProperties(duration=3676.4444444444443)
                       for i in range(27)}
        self._target.add_instruction(Reset(), reset_props)

        meas_props = {
            (0, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.02089999999999992),
            (1, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.020199999999999996),
            (2, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.014100000000000001),
            (3, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.03710000000000002),
            (4, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.015100000000000002),
            (5, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.01869999999999994),
            (6, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.013000000000000012),
            (7, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.02059999999999995),
            (8, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.06099999999999994),
            (9, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.02950000000000008),
            (10, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.040000000000000036),
            (11, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.017299999999999982),
            (12, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.04410000000000003),
            (13, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.017199999999999993),
            (14, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.10119999999999996),
            (15, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.07840000000000003),
            (16, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.014499999999999957),
            (17, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.021299999999999986),
            (18, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.022399999999999975),
            (19, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.01859999999999995),
            (20, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.02859999999999996),
            (21, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.021600000000000064),
            (22, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.030200000000000005),
            (23, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.01970000000000005),
            (24, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.03079999999999994),
            (25, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.04400000000000004),
            (26, ):
            InstructionProperties(duration=3.552e-06,
                                  error=0.026800000000000046),
        }
        self.target.add_instruction(Measure(), meas_props)
        self._qubit_properties = {
            0:
            QubitProperties(t1=0.00015987993124584417,
                            t2=0.00016123516590787283,
                            frequency=5073462814.921423),
            1:
            QubitProperties(t1=0.00017271188343294773,
                            t2=3.653713654834547e-05,
                            frequency=4943844681.620448),
            2:
            QubitProperties(t1=7.179635917914033e-05,
                            t2=0.00012399765778639733,
                            frequency=4668157502.363186),
            3:
            QubitProperties(t1=0.0001124203171256432,
                            t2=0.0001879954854434302,
                            frequency=4887315883.214115),
            4:
            QubitProperties(t1=9.568769051084652e-05,
                            t2=6.9955557231525e-05,
                            frequency=5016355075.77537),
            5:
            QubitProperties(t1=9.361326963775646e-05,
                            t2=0.00012561361411231962,
                            frequency=4950539585.866738),
            6:
            QubitProperties(t1=9.735672898365994e-05,
                            t2=0.00012522003396944046,
                            frequency=4970622491.726983),
            7:
            QubitProperties(t1=0.00012117839009784141,
                            t2=0.0001492370106539427,
                            frequency=4889863864.167805),
            8:
            QubitProperties(t1=8.394707006435891e-05,
                            t2=5.5194256398727296e-05,
                            frequency=4769852625.405966),
            9:
            QubitProperties(t1=0.00012392229685657686,
                            t2=5.97129502818714e-05,
                            frequency=4948868138.885028),
            10:
            QubitProperties(t1=0.00011193014813922708,
                            t2=0.00014091085124119432,
                            frequency=4966294754.357908),
            11:
            QubitProperties(t1=0.000124426408667364,
                            t2=9.561432905002298e-05,
                            frequency=4664636564.282378),
            12:
            QubitProperties(t1=0.00012469120424014884,
                            t2=7.1792446286313e-05,
                            frequency=4741461907.952719),
            13:
            QubitProperties(t1=0.00010010942474357871,
                            t2=9.260751861141544e-05,
                            frequency=4879064835.799635),
            14:
            QubitProperties(t1=0.00010793367069728063,
                            t2=0.00020462601085738193,
                            frequency=4774809501.962878),
            15:
            QubitProperties(t1=0.00010814279470918582,
                            t2=0.00014052616328020083,
                            frequency=4860834948.367331),
            16:
            QubitProperties(t1=9.889617874757627e-05,
                            t2=0.00012160357011388956,
                            frequency=4978318747.333388),
            17:
            QubitProperties(t1=8.435212562619916e-05,
                            t2=4.43587633824445e-05,
                            frequency=5000300619.491221),
            18:
            QubitProperties(t1=0.00011719166507869474,
                            t2=5.461866556148401e-05,
                            frequency=4772460318.985625),
            19:
            QubitProperties(t1=0.00013321880066203932,
                            t2=0.0001704632622810825,
                            frequency=4807707035.998121),
            20:
            QubitProperties(t1=9.14192211953385e-05,
                            t2=0.00014298332288799443,
                            frequency=5045028334.669125),
            21:
            QubitProperties(t1=5.548103716494676e-05,
                            t2=9.328101902519704e-05,
                            frequency=4941029753.792485),
            22:
            QubitProperties(t1=0.00017109481586484562,
                            t2=0.00019209594920551097,
                            frequency=4906801587.246266),
            23:
            QubitProperties(t1=0.00010975552427765991,
                            t2=0.00015616813868639905,
                            frequency=4891601685.652732),
            24:
            QubitProperties(t1=0.0001612962696960434,
                            t2=6.940808472789023e-05,
                            frequency=4664347869.784967),
            25:
            QubitProperties(t1=0.00015414506978323392,
                            t2=8.382170181880107e-05,
                            frequency=4742061753.511209),
            26:
            QubitProperties(t1=0.00011828557676958944,
                            t2=0.00016963640893557827,
                            frequency=4961661099.733828),
        }