Esempio n. 1
0
 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)
Esempio n. 2
0
    def __init__(self, qubit_freq_est: List[float], meas_freq_est: List[float],
                 buffer: int, pulse_library: List[PulseLibraryItem],
                 cmd_def: List[Command], **kwargs: Dict[str, Any]):
        """
        Validate and reformat transport layer inputs to initialize.

        Args:
            qubit_freq_est: Estimated qubit frequencies in GHz.
            meas_freq_est: Estimated measurement cavity frequencies in GHz.
            buffer: Default buffer time (in units of dt) between pulses.
            pulse_library: Pulse name and sample definitions.
            cmd_def: Operation name and definition in terms of Commands.
            **kwargs: Other attributes for the super class.
        """
        super().__init__(**kwargs)

        self.buffer = buffer
        self.qubit_freq_est = [freq * 1e9 for freq in qubit_freq_est]
        """Qubit frequencies in Hertz."""
        self.meas_freq_est = [freq * 1e9 for freq in meas_freq_est]
        """Measurement frequencies in Hertz."""
        self.pulse_library = pulse_library
        self.cmd_def = cmd_def
        self.instruction_schedule_map = InstructionScheduleMap()

        self.converter = QobjToInstructionConverter(pulse_library)
        for inst in cmd_def:
            pulse_insts = [self.converter(inst) for inst in inst.sequence]
            schedule = ParameterizedSchedule(*pulse_insts, name=inst.name)
            self.instruction_schedule_map.add(inst.name, inst.qubits, schedule)
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_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. 5
0
    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)
Esempio n. 6
0
    def __init__(
        self,
        qubit_freq_est: List[float],
        meas_freq_est: List[float],
        buffer: int,
        pulse_library: List[PulseLibraryItem],
        cmd_def: List[Command],
        meas_kernel: MeasurementKernel = None,
        discriminator: Discriminator = None,
        **kwargs: Dict[str, Any],
    ):
        """
        Validate and reformat transport layer inputs to initialize.
        Args:
            qubit_freq_est: Estimated qubit frequencies in GHz.
            meas_freq_est: Estimated measurement cavity frequencies in GHz.
            buffer: Default buffer time (in units of dt) between pulses.
            pulse_library: Pulse name and sample definitions.
            cmd_def: Operation name and definition in terms of Commands.
            meas_kernel: The measurement kernels
            discriminator: The discriminators
            **kwargs: Other attributes for the super class.
        """
        self._data = {}
        self.buffer = buffer
        self.qubit_freq_est = [freq * 1e9 for freq in qubit_freq_est]
        """Qubit frequencies in Hertz."""
        self.meas_freq_est = [freq * 1e9 for freq in meas_freq_est]
        """Measurement frequencies in Hertz."""
        self.pulse_library = pulse_library
        self.cmd_def = cmd_def
        self.instruction_schedule_map = InstructionScheduleMap()

        self.converter = QobjToInstructionConverter(pulse_library)
        for inst in cmd_def:
            pulse_insts = [self.converter(inst) for inst in inst.sequence]
            schedule = Schedule(*pulse_insts, name=inst.name)
            schedule.metadata[
                "publisher"] = CalibrationPublisher.BACKEND_PROVIDER
            self.instruction_schedule_map.add(inst.name, inst.qubits, schedule)

        if meas_kernel is not None:
            self.meas_kernel = meas_kernel
        if discriminator is not None:
            self.discriminator = discriminator

        self._data.update(kwargs)
Esempio n. 7
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. 8
0
    def instruction_schedule_map(self):
        """Return an :class:`~qiskit.pulse.InstructionScheduleMap` for the
        instructions in the target with a pulse schedule defined.

        Returns:
            InstructionScheduleMap: The instruction schedule map for the
            instructions in this target with a pulse schedule defined.
        """
        if self._instruction_schedule_map is not None:
            return self._instruction_schedule_map
        out_inst_schedule_map = InstructionScheduleMap()
        for instruction, qargs in self._gate_map.items():
            for qarg, properties in qargs.items():
                if properties is not None and properties.calibration is not None:
                    out_inst_schedule_map.add(instruction, qarg,
                                              properties.calibration)
        self._instruction_schedule_map = out_inst_schedule_map
        return out_inst_schedule_map