示例#1
0
    def test_pulse_limits(self):
        """Test that limits of pulse norm of one are enforced properly."""

        # test norm is correct for complex128 numpy data
        unit_pulse_c128 = np.exp(1j*2*np.pi*np.linspace(0, 1, 1000), dtype=np.complex128)
        # test does not raise error
        try:
            Waveform(unit_pulse_c128)
        except PulseError:
            self.fail('Waveform incorrectly failed on approximately unit norm samples.')

        invalid_const = 1.1
        with self.assertRaises(PulseError):
            Waveform(invalid_const*np.exp(1j*2*np.pi*np.linspace(0, 1, 1000)))

        # Test case where data is converted to python types with complex as a list
        # with form [re, im] and back to a numpy array.
        # This is how the transport layer handles samples in the qobj so it is important
        # to test.
        unit_pulse_c64 = np.exp(1j*2*np.pi*np.linspace(0, 1, 1000), dtype=np.complex64)
        sample_components = np.stack(np.transpose([np.real(unit_pulse_c64),
                                                   np.imag(unit_pulse_c64)]))
        pulse_list = sample_components.tolist()
        recombined_pulse = [sample[0]+sample[1]*1j for sample in pulse_list]

        # test does not raise error
        try:
            Waveform(recombined_pulse)
        except PulseError:
            self.fail('Waveform incorrectly failed to approximately unit norm samples.')
示例#2
0
 def test_drive_instruction(self):
     """Test converted qobj from Play."""
     converter = InstructionToQobjConverter(PulseQobjInstruction,
                                            meas_level=2)
     instruction = Play(Waveform(np.arange(0, 0.01), name='linear'),
                        DriveChannel(0))
     valid_qobj = PulseQobjInstruction(name='linear', ch='d0', t0=0)
     self.assertEqual(converter(0, instruction), valid_qobj)
示例#3
0
    def test_type_casting(self):
        """Test casting of input samples to numpy array."""
        n_samples = 100
        samples_f64 = np.linspace(0, 1., n_samples, dtype=np.float64)

        sample_pulse_f64 = Waveform(samples_f64)
        self.assertEqual(sample_pulse_f64.samples.dtype, np.complex128)

        samples_c64 = np.linspace(0, 1., n_samples, dtype=np.complex64)

        sample_pulse_c64 = Waveform(samples_c64)
        self.assertEqual(sample_pulse_c64.samples.dtype, np.complex128)

        samples_list = np.linspace(0, 1., n_samples).tolist()

        sample_pulse_list = Waveform(samples_list)
        self.assertEqual(sample_pulse_list.samples.dtype, np.complex128)
示例#4
0
 def test_waveform_amplitude_limit(self):
     """Test applying amplitude limit to waveform."""
     with builder.build() as test_sched:
         builder.play(
             Waveform([1, 2, 3, 4, 5], limit_amplitude=False),
             DriveChannel(0),
         )
     self.assert_roundtrip_equal(test_sched)
示例#5
0
    def setUp(self):
        super().setUp()
        self.linear = Waveform(np.arange(0, 0.01), name='linear')
        self.pulse_library = [PulseLibraryItem(name=self.linear.name,
                                               samples=self.linear.samples.tolist())]

        self.converter = QobjToInstructionConverter(self.pulse_library, buffer=0)
        self.num_qubits = 2
示例#6
0
文件: x12.py 项目: UTokyo-ICEPP/aqcel
    def apply_sideband(self, pulse, freq):
        t_samples = np.linspace(0, self.dt * self.drive_samples,
                                self.drive_samples)
        sine_pulse = np.sin(2 * np.pi * (freq - self.default_qubit_freq) *
                            t_samples)  # no amp for the sine

        sideband_pulse = Waveform(np.multiply(np.real(pulse.samples),
                                              sine_pulse),
                                  name='sideband_pulse')

        return sideband_pulse
示例#7
0
    def test_sample_pulse(self):
        """Test pulse initialization."""
        n_samples = 100
        samples = np.linspace(0, 1., n_samples, dtype=np.complex128)
        name = 'test'
        sample_pulse = Waveform(samples, name=name)

        self.assertEqual(sample_pulse.samples.dtype, np.complex128)
        np.testing.assert_almost_equal(sample_pulse.samples, samples)

        self.assertEqual(sample_pulse.duration, n_samples)
        self.assertEqual(sample_pulse.name, name)