コード例 #1
0
    def test_sampler_name(self):
        """Test that sampler setting of pulse name works."""
        m = 0.1
        b = 0.1
        duration = 2
        left_linear_pulse_fun = samplers.left(linear)

        pulse = left_linear_pulse_fun(duration, m=m, b=b, name='test')
        self.assertIsInstance(pulse, commands.SamplePulse)
        self.assertEqual(pulse.name, 'test')
コード例 #2
0
    def test_default_arg_sampler(self):
        """Test that default arguments work with sampler."""
        m = 0.1
        duration = 2
        left_linear_pulse_fun = samplers.left(linear)
        reference = np.array([0.1, 0.2], dtype=np.complex)

        pulse = left_linear_pulse_fun(duration, m=m)
        self.assertIsInstance(pulse, commands.SamplePulse)
        np.testing.assert_array_almost_equal(pulse.samples, reference)
コード例 #3
0
    def test_left_sampler(self):
        """Test left sampler."""
        m = 0.1
        b = 0.1
        duration = 2
        left_linear_pulse_fun = samplers.left(linear)
        reference = np.array([0.1, 0.2], dtype=np.complex)

        pulse = left_linear_pulse_fun(duration, m=m, b=b)
        self.assertIsInstance(pulse, commands.SamplePulse)
        np.testing.assert_array_almost_equal(pulse.samples, reference)
コード例 #4
0
# that they have been altered from the originals.

# pylint: disable=missing-return-doc, invalid-name

"""Module for builtin discrete pulses.

Note the sampling strategy use for all discrete pulses is `left`.
"""
from typing import Optional

from qiskit.pulse.commands import SamplePulse
from qiskit.pulse.pulse_lib import continuous
from qiskit.pulse import samplers


_sampled_constant_pulse = samplers.left(continuous.constant)


def constant(duration: int, amp: complex, name: Optional[str] = None) -> SamplePulse:
    """Generates constant-sampled `SamplePulse`.

    Applies `left` sampling strategy to generate discrete pulse from continuous function.

    Args:
        duration: Duration of pulse. Must be greater than zero.
        amp: Complex pulse amplitude.
        name: Name of pulse.
    """
    return _sampled_constant_pulse(duration, amp, name=name)