Example #1
0
    def test_ef_circuits(self):
        """Test that we get the expected circuits with calibrations for the EF experiment."""

        test_amps = [-0.5, 0, 0.5]
        rabi_ef = EFRoughXSXAmplitudeCal(0, self.cals, amplitudes=test_amps)

        circs = transpile(rabi_ef.circuits(),
                          self.backend,
                          inst_map=rabi_ef.transpile_options.inst_map)

        for circ, amp in zip(circs, test_amps):

            self.assertEqual(circ.count_ops()["x"], 1)
            self.assertEqual(circ.count_ops()["Rabi"], 1)

            d0 = pulse.DriveChannel(0)
            with pulse.build(name="x") as expected_x:
                pulse.play(pulse.Drag(160, 0.5, 40, 0), d0)

            with pulse.build(name="x12") as expected_x12:
                with pulse.frequency_offset(-300e6, d0):
                    pulse.play(pulse.Drag(160, amp, 40, 0), d0)

            self.assertEqual(circ.calibrations["x"][((0, ), ())], expected_x)
            self.assertEqual(circ.calibrations["Rabi"][((0, ), (amp, ))],
                             expected_x12)
Example #2
0
    def setUp(self):
        """Setup the tests."""
        super().setUp()

        self.qubit = 0

        with pulse.build(name="x") as sched:
            with pulse.frequency_offset(-300e6,
                                        pulse.DriveChannel(self.qubit)):
                pulse.play(pulse.Drag(160, Parameter("amp"), 40, 0.4),
                           pulse.DriveChannel(self.qubit))

        self.sched = sched
Example #3
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")
    def test_frequency_offset(self):
        """Test the frequency offset context."""
        d0 = pulse.DriveChannel(0)

        with pulse.build() as schedule:
            with pulse.frequency_offset(1e9, d0):
                pulse.delay(10, d0)

        reference = pulse.Schedule()
        reference += instructions.ShiftFrequency(1e9, d0)  # pylint: disable=no-member
        reference += instructions.Delay(10, d0)
        reference += instructions.ShiftFrequency(-1e9, d0)  # pylint: disable=no-member

        self.assertEqual(schedule, reference)
    def test_phase_compensated_frequency_offset(self):
        """Test that the phase offset context properly compensates for phase
        accumulation."""
        d0 = pulse.DriveChannel(0)

        with pulse.build(self.backend) as schedule:
            with pulse.frequency_offset(1e9, d0, compensate_phase=True):
                pulse.delay(10, d0)

        reference = pulse.Schedule()
        reference += instructions.ShiftFrequency(1e9, d0)  # pylint: disable=no-member
        reference += instructions.Delay(10, d0)
        reference += instructions.ShiftPhase(
            -(1e9*10*self.configuration.dt % (2*np.pi)), d0)
        reference += instructions.ShiftFrequency(-1e9, d0)  # pylint: disable=no-member
        self.assertEqual(schedule, reference)
Example #6
0
    def _default_gate_schedule(self, backend: Optional[Backend] = None):
        """Create the default schedule for the EFRabi gate with a frequency shift to the 1-2
        transition."""

        if self.experiment_options.frequency_shift is None:
            try:
                anharm, _ = backend.properties().qubit_property(self.physical_qubits[0])[
                    "anharmonicity"
                ]
                self.set_experiment_options(frequency_shift=anharm)
            except KeyError as key_err:
                raise CalibrationError(
                    f"The backend {backend} does not provide an anharmonicity for qubit "
                    f"{self.physical_qubits[0]}. Use EFRabi.set_experiment_options(frequency_shift="
                    f"anharmonicity) to manually set the correct frequency for the 1-2 transition."
                ) from key_err
            except AttributeError as att_err:
                raise CalibrationError(
                    "When creating the default schedule without passing a backend, the frequency needs "
                    "to be set manually through EFRabi.set_experiment_options(frequency_shift=..)."
                ) from att_err

        amp = Parameter("amp")
        with pulse.build(backend=backend, name=self.__rabi_gate_name__) as default_schedule:
            with pulse.frequency_offset(
                self.experiment_options.frequency_shift,
                pulse.DriveChannel(self.physical_qubits[0]),
            ):
                pulse.play(
                    pulse.Gaussian(
                        duration=self.experiment_options.duration,
                        amp=amp,
                        sigma=self.experiment_options.sigma,
                    ),
                    pulse.DriveChannel(self.physical_qubits[0]),
                )

        return default_schedule