def test_walsh_sequence():
    """
    Tests the Walsh sequence.
    """

    duration = 10.0
    paley_order = 20

    sequence = new_walsh_sequence(duration=duration, paley_order=paley_order)

    hamming_weight = 5
    samples = 2**hamming_weight
    relative_offset = np.arange(1.0 / (2 * samples), 1.0, 1.0 / samples)
    binary_string = np.binary_repr(paley_order)
    binary_order = [int(binary_string[i]) for i in range(hamming_weight)]
    walsh_array = np.ones([samples])
    for i in range(hamming_weight):
        walsh_array *= (np.sign(
            np.sin(2**(i + 1) * np.pi *
                   relative_offset))**binary_order[hamming_weight - 1 - i])

    walsh_relative_offsets = []
    for i in range(samples - 1):
        if walsh_array[i] != walsh_array[i + 1]:
            walsh_relative_offsets.append((i + 1) * (1.0 / samples))
    walsh_relative_offsets = np.array(walsh_relative_offsets, dtype=np.float)
    _offsets = duration * walsh_relative_offsets
    _offsets = np.array(_offsets)

    _rabi_rotations = np.pi * np.ones(_offsets.shape)
    _azimuthal_angles = np.zeros(_offsets.shape)
    _detuning_rotations = np.zeros(_offsets.shape)

    assert np.allclose(_offsets, sequence.offsets)
    assert np.allclose(_rabi_rotations, sequence.rabi_rotations)
    assert np.allclose(_azimuthal_angles, sequence.azimuthal_angles)
    assert np.allclose(_detuning_rotations, sequence.detuning_rotations)

    sequence = new_walsh_sequence(
        duration=duration,
        paley_order=paley_order,
        pre_post_rotation=True,
    )

    _offsets = np.insert(
        _offsets,
        [0, _offsets.shape[0]],
        [0, duration],
    )
    _rabi_rotations = np.insert(_rabi_rotations, [0, _rabi_rotations.shape[0]],
                                [np.pi / 2, np.pi / 2])
    _azimuthal_angles = np.zeros(_offsets.shape)
    _azimuthal_angles[-1] = np.pi
    _detuning_rotations = np.zeros(_offsets.shape)

    assert np.allclose(_offsets, sequence.offsets)
    assert np.allclose(_rabi_rotations, sequence.rabi_rotations)
    assert np.allclose(_azimuthal_angles, sequence.azimuthal_angles)
    assert np.allclose(_detuning_rotations, sequence.detuning_rotations)
Esempio n. 2
0
def test_if_walsh_sequence_with_even_pulses_is_identity():
    """
    Tests if the product of the pulses in a quadratic sequence with pre/post
    pi/2-pulses is an identity, when the number of pulses is even.
    """
    even_walsh_sequence = new_walsh_sequence(duration=10.0,
                                             paley_order=6,
                                             pre_post_rotation=True)

    # A Walsh sequence with paley_order 6 has 4 pi-pulses + 2 pi/2-pulses,
    # see https://arxiv.org/pdf/1109.6002.pdf
    assert len(even_walsh_sequence.offsets) == 4 + 2

    assert _pulses_produce_identity(even_walsh_sequence)
Esempio n. 3
0
def test_if_walsh_sequence_with_odd_pulses_is_identity():
    """
    Tests if the product of the pulses in a Walsh sequence with pre/post
    pi/2-pulses is an identity, when the number of pulses is odd.
    """
    odd_walsh_sequence = new_walsh_sequence(duration=10.0,
                                            paley_order=7,
                                            pre_post_rotation=True)

    # A Walsh sequence with paley_order 7 has 5 pi-pulses + 2 pi/2-pulses,
    # see https://arxiv.org/pdf/1109.6002.pdf
    assert len(odd_walsh_sequence.offsets) == 5 + 2

    assert _pulses_produce_identity(odd_walsh_sequence)