Example #1
0
def test_heterodyne_sweep():
    num_tones = 16
    num_waveforms = 2 ** 5
    num_tone_samples = 2 ** 10
    length_seconds = 0.1
    ri = RoachHeterodyne(roach=MockRoach("roach"), initialize=False, adc_valon=MockValon())
    ri.lo_frequency = 1000
    center_frequencies = ri.lo_frequency + np.linspace(-100, 100, num_tones)
    offsets = np.linspace(-20e-3, 20e-3, num_waveforms)
    tone_banks = [center_frequencies + offset for offset in offsets]
    state = {"something": "something state"}

    # Load waveforms one at a time.
    sweep = acquire.run_sweep(
        ri=ri,
        tone_banks=tone_banks,
        num_tone_samples=num_tone_samples,
        length_seconds=length_seconds,
        state=state,
        description="description",
    )
    assert len(sweep.stream_arrays) == num_waveforms
    assert all([stream_array.s21_raw.shape[0] == num_tones for stream_array in sweep.stream_arrays])

    # Pre-load all waveforms.
    acquire.load_heterodyne_sweep_tones(ri, tone_banks, num_tone_samples)
    sweep = acquire.run_loaded_sweep(ri=ri, length_seconds=length_seconds, state=state, description="description")
    assert len(sweep.stream_arrays) == num_waveforms
    assert all([stream_array.s21_raw.shape[0] == num_tones for stream_array in sweep.stream_arrays])
Example #2
0
def measure_hardware_delay(ri, frequencies=np.arange(1, 9) * 24, num_tone_samples=2 ** 16, num_points=16,
                           make_plots=False,
                           verbose=False):
    offsets = np.arange(-num_points // 2, num_points // 2 + 1) * ri.fs / float(num_tone_samples)
    if ri.is_roach2:
        sa = acquire.run_sweep(ri, ri.lo_frequency + frequencies[None, :] + offsets[:, None],
                               num_tone_samples=num_tone_samples, verbose=verbose)
    else:
        acquire.load_heterodyne_sweep_tones(ri, ri.lo_frequency + frequencies[None, :] + offsets[:, None],
                                            num_tone_samples=num_tone_samples)
        sa = acquire.run_loaded_sweep(ri, verbose=verbose)

    print np.median(np.abs(sa.s21_point))
    local_delays = []
    for k in range(frequencies.shape[0]):
        swp = sa.sweep(k)
        deltaf = swp.frequency - swp.frequency.min()
        phase = np.unwrap(np.angle(swp.s21_point))
        rad_per_Hz, offset = np.polyfit(deltaf, phase, 1)
        local_delays.append(rad_per_Hz / (2 * np.pi))
        if make_plots:
            plt.plot(deltaf, phase - offset, '.')
            plt.plot(deltaf, rad_per_Hz * deltaf)
            plt.xlabel('Offset Frequency (Hz)')
            plt.ylabel('Phase (rad)')
    local_delays = np.array(local_delays)
    if make_plots:
        plt.figure()
        plt.plot(frequencies, local_delays * 1e9, 'o')
        plt.axhline(np.median(local_delays * 1e9), linestyle='--', color='r')
        plt.xlabel('Measurement Frequency (MHz)')
        plt.ylabel('Delay (ns)')
    logger.debug("median local delay: %.1f ns" % (np.median(local_delays) * 1e9))
    frequency = sa.frequency
    deltaf = frequency - frequency.min()
    phase = np.unwrap(np.angle(sa.s21_point * np.exp(-1j * np.median(local_delays) * 2 * np.pi * deltaf)))
    rad_per_Hz, offset = np.polyfit(deltaf, phase, 1)
    if make_plots:
        plt.figure()
        plt.plot(frequency / 1e6, phase, '.')
        plt.plot(frequency / 1e6, offset + rad_per_Hz * deltaf)
        plt.xlabel('Frequency (MHz)')
        plt.ylabel('Phase (rad)')
    total_delay = np.median(local_delays) + rad_per_Hz / (2 * np.pi)
    logger.debug("residual delay %.1f ns global delay = %.1f ns" % (1e9 * rad_per_Hz / (2 * np.pi), 1e9 * total_delay))
    return total_delay
Example #3
0
def measure_hardware_delay(ri, frequencies=np.arange(1, 9) * 24, num_tone_samples=2 ** 16, num_points=16,
                           make_plots=False,
                           verbose=False):
    offsets = np.arange(-num_points // 2, num_points // 2 + 1) * ri.fs / float(num_tone_samples)
    if ri.is_roach2:
        sa = acquire.run_sweep(ri, ri.lo_frequency + frequencies[None, :] + offsets[:, None],
                               num_tone_samples=num_tone_samples, verbose=verbose)
    else:
        acquire.load_heterodyne_sweep_tones(ri, ri.lo_frequency + frequencies[None, :] + offsets[:, None],
                                            num_tone_samples=num_tone_samples)
        sa = acquire.run_loaded_sweep(ri, verbose=verbose)

    print np.median(np.abs(sa.s21_point))
    local_delays = []
    for k in range(frequencies.shape[0]):
        swp = sa.sweep(k)
        deltaf = swp.frequency - swp.frequency.min()
        phase = np.unwrap(np.angle(swp.s21_point))
        rad_per_Hz, offset = np.polyfit(deltaf, phase, 1)
        local_delays.append(rad_per_Hz / (2 * np.pi))
        if make_plots:
            plt.plot(deltaf, phase - offset, '.')
            plt.plot(deltaf, rad_per_Hz * deltaf)
            plt.xlabel('Offset Frequency (Hz)')
            plt.ylabel('Phase (rad)')
    local_delays = np.array(local_delays)
    if make_plots:
        plt.figure()
        plt.plot(frequencies, local_delays * 1e9, 'o')
        plt.axhline(np.median(local_delays * 1e9), linestyle='--', color='r')
        plt.xlabel('Measurement Frequency (MHz)')
        plt.ylabel('Delay (ns)')
    logger.debug("median local delay: %.1f ns" % (np.median(local_delays) * 1e9))
    frequency = sa.frequency
    deltaf = frequency - frequency.min()
    phase = np.unwrap(np.angle(sa.s21_point * np.exp(-1j * np.median(local_delays) * 2 * np.pi * deltaf)))
    rad_per_Hz, offset = np.polyfit(deltaf, phase, 1)
    if make_plots:
        plt.figure()
        plt.plot(frequency / 1e6, phase, '.')
        plt.plot(frequency / 1e6, offset + rad_per_Hz * deltaf)
        plt.xlabel('Frequency (MHz)')
        plt.ylabel('Phase (rad)')
    total_delay = np.median(local_delays) + rad_per_Hz / (2 * np.pi)
    logger.debug("residual delay %.1f ns global delay = %.1f ns" % (1e9 * rad_per_Hz / (2 * np.pi), 1e9 * total_delay))
    return total_delay
Example #4
0
def test_heterodyne_sweep():
    num_tones = 16
    num_waveforms = 2**5
    num_tone_samples = 2**10
    length_seconds = 0.1
    ri = RoachHeterodyne(roach=MockRoach('roach'),
                         initialize=False,
                         adc_valon=MockValon())
    ri.lo_frequency = 1000
    center_frequencies = ri.lo_frequency + np.linspace(-100, 100, num_tones)
    offsets = np.linspace(-20e-3, 20e-3, num_waveforms)
    tone_banks = [center_frequencies + offset for offset in offsets]
    state = {'something': 'something state'}

    # Load waveforms one at a time.
    sweep = acquire.run_sweep(ri=ri,
                              tone_banks=tone_banks,
                              num_tone_samples=num_tone_samples,
                              length_seconds=length_seconds,
                              state=state,
                              description="description")
    assert len(sweep.stream_arrays) == num_waveforms
    assert all([
        stream_array.s21_raw.shape[0] == num_tones
        for stream_array in sweep.stream_arrays
    ])

    # Pre-load all waveforms.
    acquire.load_heterodyne_sweep_tones(ri, tone_banks, num_tone_samples)
    sweep = acquire.run_loaded_sweep(ri=ri,
                                     length_seconds=length_seconds,
                                     state=state,
                                     description="description")
    assert len(sweep.stream_arrays) == num_waveforms
    assert all([
        stream_array.s21_raw.shape[0] == num_tones
        for stream_array in sweep.stream_arrays
    ])
nstep = 48
offset_bins = np.arange(-(nstep + 1), (nstep + 1)) * step
offsets = offset_bins * 512.0 / nsamp

mmw_freqs = np.linspace(140e9, 165e9, 500)

ri.set_dac_atten(10)

state = dict(mmw_atten_turns=(7,7), hittite_power_dBm=0.0,)

for (lo,f0s) in [(low_group_lo,low_group),
                 (high_group_lo, high_group)]:
    tic = time.time()
    ncf = new_nc_file(suffix='lo_%.1f' % lo)
    ri.set_lo(lo)
    measured_frequencies = acquire.load_heterodyne_sweep_tones(ri, np.add.outer(offsets, f0s), num_tone_samples=nsamp)
    print "waveforms loaded", (time.time()-tic)/60.
    hittite.off()
    swpa = acquire.run_loaded_sweep(ri, length_seconds=0, state=state)
    print "resonance sweep done", (time.time()-tic)/60.
    ncf.write(swpa)
    print "sweep written", (time.time()-tic)/60.
    current_f0s = []
    fits = []
    for sidx in range(32):
        swp = swpa.sweep(sidx)
        res = lmfit_resonator.LinearResonatorWithCable(swp.frequency, swp.s21_point, swp.s21_point_error)
        res.fit()
        fits.append(res)
        print res.f_0, res.Q, res.current_result.redchi, (f0s[sidx]*1e6-res.f_0)
        current_f0s.append(res.f_0)
Example #6
0
ri.set_fft_gain(4)

nsamp = 2**16
step = 1
nstep = 128
#f0binned = np.round(f0s * nsamp / 512.0) * 512.0 / nsamp
offset_bins = np.arange(-(nstep), (nstep)) * step

offsets = offset_bins * 512.0 / nsamp

ri.set_modulation_output(7)

ri.set_lo(1250.)

acquire.load_heterodyne_sweep_tones(
    ri,
    (np.arange(1, 129)[None, :] * 7 / 4. + ri.lo_frequency + offsets[:, None]),
    num_tone_samples=nsamp)

state = dict(mmw_atten_turns=(7., 7.))

tic = time.time()
for lo in 1010 + 190 * np.arange(0, 6):
    print "lo:", lo
    df = acquire.new_nc_file(
        suffix='scan_lo_%.1f_MHz_mmw_modulated_7_7_turns' % lo)
    ri.set_lo(lo)
    swa = acquire.run_multipart_sweep(ri,
                                      length_seconds=1.0,
                                      state=state,
                                      verbose=True)
    df.write(swa)
nsamp = 2**16
step = 1
nstep = 128
offset_bins = np.arange(-(nstep + 1), (nstep + 1)) * step
offsets = offset_bins * 512.0 / nsamp

mmw_freqs = np.linspace(140e9, 165e9, 500)

ri.set_dac_atten(2)


for (lo,f0s) in [(low_group_lo,low_group),
                 (high_group_lo, high_group)]:
    ri.set_lo(lo)
    tic = time.time()
    measured_frequencies = acquire.load_heterodyne_sweep_tones(ri, np.add.outer(offsets, f0s), num_tone_samples=nsamp)
    print "waveforms loaded", (time.time()-tic)/60.
    for hittite_power in np.arange(-3.4,1.1,0.5):
        hittite.set_power(hittite_power)
        ncf = new_nc_file(suffix='cw_noise')
        setup.hittite.on()
        ri.set_modulation_output('low')
        swpa = acquire.run_loaded_sweep(ri, length_seconds=0, state=setup.state(), description='source on sweep')
        print "resonance sweep done", (time.time()-tic)/60.
        ncf.write(swpa)
        #print "sweep written", (time.time()-tic)/60.
        current_f0s = []
        for sidx in range(32):
            swp = swpa.sweep(sidx)
            res = lmfit_resonator.LinearResonatorWithCable(swp.frequency, swp.s21_point, swp.s21_point_error)
            print res.f_0, res.Q, res.current_result.redchi, (f0s[sidx]*1e6-res.f_0)
ri.set_dac_atten(30)
ri.set_fft_gain(4)

nsamp = 2 ** 16
step = 1
nstep = 128
# f0binned = np.round(f0s * nsamp / 512.0) * 512.0 / nsamp
offset_bins = np.arange(-(nstep), (nstep)) * step

offsets = offset_bins * 512.0 / nsamp

ri.set_modulation_output(7)

ri.set_lo(1250.0)

acquire.load_heterodyne_sweep_tones(
    ri, (np.arange(1, 129)[None, :] * 7 / 4.0 + ri.lo_frequency + offsets[:, None]), num_tone_samples=nsamp
)

state = dict(mmw_atten_turns=(7.0, 7.0))

tic = time.time()
for lo in 1010 + 190 * np.arange(0, 6):
    print "lo:", lo
    df = acquire.new_nc_file(suffix="scan_lo_%.1f_MHz_mmw_modulated_7_7_turns" % lo)
    ri.set_lo(lo)
    swa = acquire.run_multipart_sweep(ri, length_seconds=1.0, state=state, verbose=True)
    df.write(swa)
    df.close()
    print "elapsed:", (time.time() - tic) / 60.0, "minutes"