def __init__(
        self,
        qubit: int,
        calibrations: Calibrations,
        schedule_name: str = "x",
        amplitudes: Iterable[float] = None,
        cal_parameter_name: Optional[str] = "amp",
        target_angle: float = np.pi,
        auto_update: bool = True,
        group: str = "default",
        backend: Optional[Backend] = None,
    ):
        r"""see class :class:`Rabi` for details.

        Args:
            qubit: The qubit for which to run the rough amplitude calibration.
            calibrations: The calibrations instance with the schedules.
            schedule_name: The name of the schedule to calibrate. Defaults to "x".
            amplitudes: A list of amplitudes to scan. If None is given 51 amplitudes ranging
                from -0.95 to 0.95 will be scanned.
            cal_parameter_name: The name of the parameter in the schedule to update.
            target_angle: The target angle of the gate to calibrate this will default to a
                :math:`\pi`-pulse.
            auto_update: Whether or not to automatically update the calibrations. By
                default this variable is set to True.
            group: The group of calibration parameters to use. The default value is "default".
            backend: Optional, the backend to run the experiment on.
        """
        schedule = calibrations.get_schedule(
            schedule_name,
            qubit,
            assign_params={cal_parameter_name: Parameter("amp")},
            group=group)

        self._validate_channels(schedule, [qubit])
        self._validate_parameters(schedule, 1)

        super().__init__(
            calibrations,
            qubit,
            schedule=schedule,
            amplitudes=amplitudes,
            backend=backend,
            schedule_name=schedule_name,
            cal_parameter_name=cal_parameter_name,
            auto_update=auto_update,
        )

        # Set the pulses to update.
        prev_amp = calibrations.get_parameter_value(cal_parameter_name, qubit,
                                                    schedule_name)
        self.experiment_options.group = group
        self.experiment_options.angles_schedules = [
            AnglesSchedules(
                target_angle=target_angle,
                parameter=cal_parameter_name,
                schedule=schedule_name,
                previous_value=prev_amp,
            )
        ]
Пример #2
0
    def setUp(self):
        """Setup the tests."""
        super().setUp()
        library = FixedFrequencyTransmon()

        self.backend = FakeArmonk()
        self.cals = Calibrations.from_backend(self.backend, library)
    def test_update_calibrations(self):
        """Test that we can properly update an instance of Calibrations."""

        freq01 = FakeArmonk().defaults().qubit_freq_est[0]

        backend = MockIQBackend(
            experiment_helper=SpectroscopyHelper(freq_offset=5e6, line_width=2e6),
            iq_cluster_centers=[((-1.0, -1.0), (1.0, 1.0))],
            iq_cluster_width=[0.2],
        )
        backend._configuration.basis_gates = ["x"]
        backend._configuration.timing_constraints = {"granularity": 16}

        backend.defaults().qubit_freq_est = [freq01, freq01]

        library = FixedFrequencyTransmon(basis_gates=["x", "sx"])
        cals = Calibrations.from_backend(FakeArmonk(), libraries=[library])

        prev_freq = cals.get_parameter_value(cals.__drive_freq_parameter__, (0,))
        self.assertEqual(prev_freq, freq01)

        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        expdata = RoughFrequencyCal(0, cals, frequencies).run(backend)
        self.assertExperimentDone(expdata)

        # Check the updated frequency which should be shifted by 5MHz.
        post_freq = cals.get_parameter_value(cals.__drive_freq_parameter__, (0,))
        self.assertTrue(abs(post_freq - freq01 - 5e6) < 1e6)
Пример #4
0
    def setUp(self):
        """Setup the test."""
        super().setUp()

        library = FixedFrequencyTransmon()
        self.backend = MockIQBackend(FineDragHelper())
        self.cals = Calibrations.from_backend(self.backend, libraries=[library])
Пример #5
0
    def setUp(self):
        """Setup the tests"""
        super().setUp()

        library = FixedFrequencyTransmon()

        self.backend = MockFineAmp(-np.pi * 0.07, np.pi, "xp")
        self.cals = Calibrations.from_backend(self.backend, library)
Пример #6
0
 def test_experiment_config(self):
     """Test converting to and from config works"""
     cals = Calibrations.from_backend(FakeArmonk())
     frequencies = [1, 2, 3]
     exp = RoughFrequencyCal(0, cals, frequencies)
     loaded_exp = RoughFrequencyCal.from_config(exp.config())
     self.assertNotEqual(exp, loaded_exp)
     self.assertTrue(self.json_equiv(exp, loaded_exp))
Пример #7
0
    def setUp(self):
        """Setup the tests"""
        super().setUp()

        library = FixedFrequencyTransmon()

        self.backend = DragBackend(gate_name="Drag(x)")
        self.cals = Calibrations.from_backend(self.backend, library)
        self.test_tol = 0.05
Пример #8
0
    def setUp(self):
        """Setup the tests"""
        super().setUp()

        library = FixedFrequencyTransmon()

        self.backend = MockIQBackend(FineAmpHelper(-np.pi * 0.07, np.pi, "xp"))
        self.backend.configuration().basis_gates.append("sx")
        self.backend.configuration().basis_gates.append("x")
        self.cals = Calibrations.from_backend(self.backend, libraries=[library])
Пример #9
0
    def setUp(self):
        """Setup the tests"""
        super().setUp()

        library = FixedFrequencyTransmon()

        self.backend = MockIQBackend(DragHelper(gate_name="Drag(x)"))
        self.cals = Calibrations.from_backend(self.backend,
                                              libraries=[library])
        self.test_tol = 0.05
    def setUp(self):
        """Setup for the test."""
        super().setUp()
        self.inst_map = pulse.InstructionScheduleMap()

        self.sx_duration = 160

        with pulse.build(name="sx") as sx_sched:
            pulse.play(pulse.Gaussian(self.sx_duration, 0.5, 40), pulse.DriveChannel(0))

        self.inst_map.add("sx", 0, sx_sched)

        self.cals = Calibrations.from_backend(FakeArmonk(), libraries=[FixedFrequencyTransmon()])
    def __init__(
        self,
        qubit: int,
        calibrations: Calibrations,
        backend: Optional[Backend] = None,
        delay_duration: Optional[int] = None,
        repetitions: List[int] = None,
        auto_update: bool = True,
        gate_name: str = "sx",
    ):
        r"""see class :class:`FineFrequency` for details.

        Note that this class implicitly assumes that the target angle of the gate
        is :math:`\pi/2` as seen from the default analysis options. This experiment
        can be seen as a calibration of a finite duration ``rz(pi/2)`` gate with any
        error attributed to a frequency offset in the qubit.

        Args:
            qubit: The qubit for which to run the fine frequency calibration.
            calibrations: The calibrations instance with the schedules.
            backend: Optional, the backend to run the experiment on.
            delay_duration: The duration of the delay at :math:`n=1`. If this value is
                not given then the duration of the gate named ``gate_name`` in the
                calibrations will be used.
            auto_update: Whether or not to automatically update the calibrations. By
                default this variable is set to True.
            gate_name: This argument is only needed if ``delay_duration`` is None. This
                should be the name of a valid schedule in the calibrations.
        """
        if delay_duration is None:
            delay_duration = calibrations.get_schedule(gate_name, qubit).duration

        super().__init__(
            calibrations,
            qubit,
            delay_duration=delay_duration,
            schedule_name=None,
            repetitions=repetitions,
            backend=backend,
            cal_parameter_name=calibrations.__drive_freq_parameter__,
            auto_update=auto_update,
        )

        self.set_transpile_options(inst_map=calibrations.default_inst_map)

        if self.backend is not None:
            self.set_experiment_options(dt=getattr(self.backend.configuration(), "dt", None))
    def test_init(self):
        """Test that initialization."""

        qubit = 1
        cals = Calibrations.from_backend(FakeArmonk())
        frequencies = [1000, 2000, 3000]
        auto_update = False
        absolute = False

        freq = RoughFrequencyCal(
            qubit, cals, frequencies, auto_update=auto_update, absolute=absolute
        )

        self.assertEqual(freq.physical_qubits, (qubit,))
        self.assertEqual(freq._frequencies, frequencies)
        self.assertEqual(freq._absolute, False)
        self.assertEqual(freq.auto_update, False)
Пример #13
0
    def __init__(
        self,
        qubit: int,
        calibrations: Calibrations,
        backend: Optional[Backend] = None,
        schedule_name: str = "x",
        betas: Iterable[float] = None,
        cal_parameter_name: Optional[str] = "β",
        auto_update: bool = True,
        group: str = "default",
    ):
        r"""see class :class:`RoughDrag` for details.

        Args:
            qubit: The qubit for which to run the rough drag calibration.
            calibrations: The calibrations instance with the schedules.
            backend: Optional, the backend to run the experiment on.
            schedule_name: The name of the schedule to calibrate. Defaults to "x".
            betas: A list of drag parameter values to scan. If None is given 51 betas ranging
                from -5 to 5 will be scanned.
            cal_parameter_name: The name of the parameter in the schedule to update.
                Defaults to "β".
            auto_update: Whether or not to automatically update the calibrations. By
                default this variable is set to True.
            group: The group of calibration parameters to use. The default value is "default".
        """
        schedule = calibrations.get_schedule(
            schedule_name,
            qubit,
            assign_params={cal_parameter_name: Parameter("β")},
            group=group)

        self._validate_channels(schedule, [qubit])
        self._validate_parameters(schedule, 1)

        super().__init__(
            calibrations,
            qubit,
            schedule=schedule,
            betas=betas,
            backend=backend,
            schedule_name=schedule_name,
            cal_parameter_name=cal_parameter_name,
            auto_update=auto_update,
        )
Пример #14
0
    def setUp(self):
        """Setup the tests"""
        super().setUp()

        library = FixedFrequencyTransmon()

        self.backend = FakeArmonk()
        self.cals = Calibrations.from_backend(self.backend, library)

        # Add some pulses on the 1-2 transition.
        d0 = pulse.DriveChannel(0)
        with pulse.build(name="x12") as x12:
            with pulse.frequency_offset(-300e6, d0):
                pulse.play(pulse.Drag(160, Parameter("amp"), 40, 0.0), d0)

        with pulse.build(name="sx12") as sx12:
            with pulse.frequency_offset(-300e6, d0):
                pulse.play(pulse.Drag(160, Parameter("amp"), 40, 0.0), d0)

        self.cals.add_schedule(x12, 0)
        self.cals.add_schedule(sx12, 0)
        self.cals.add_parameter_value(0.4, "amp", 0, "x12")
        self.cals.add_parameter_value(0.2, "amp", 0, "sx12")
Пример #15
0
    def test_update_calibrations(self):
        """Test that we can properly update an instance of Calibrations."""

        freq01 = FakeArmonk().defaults().qubit_freq_est[0]

        backend = SpectroscopyBackend(freq_offset=5e6, line_width=2e6)
        backend.defaults().qubit_freq_est = [freq01, freq01]

        library = FixedFrequencyTransmon(basis_gates=["x", "sx"])
        cals = Calibrations.from_backend(FakeArmonk(), library=library)

        prev_freq = cals.get_parameter_value(cals.__drive_freq_parameter__,
                                             (0, ))
        self.assertEqual(prev_freq, freq01)

        frequencies = np.linspace(freq01 - 10.0e6, freq01 + 10.0e6, 21)

        RoughFrequencyCal(0, cals,
                          frequencies).run(backend).block_for_results()

        # Check the updated frequency which should be shifted by 5MHz.
        post_freq = cals.get_parameter_value(cals.__drive_freq_parameter__,
                                             (0, ))
        self.assertTrue(abs(post_freq - freq01 - 5e6) < 1e6)