Exemplo n.º 1
0
def test_baseband_sweep():
    num_tones = 16
    num_waveforms = 2 ** 5
    num_tone_samples = 2 ** 10
    length_seconds = 0.1
    ri = RoachBaseband(roach=MockRoach("roach"), initialize=False, adc_valon=MockValon())
    center_frequencies = np.linspace(100, 200, 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_baseband_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])
Exemplo n.º 2
0
def fake_sweep_array(num_tones=16, num_waveforms=16, num_tone_samples=2 ** 16, length_seconds=0.01,
                     state={'I_am_a': 'fake sweep array'}, description='fake sweep array'):
    ri = baseband.RoachBaseband(roach=mock_roach.MockRoach('roach'), adc_valon=mock_valon.MockValon(), initialize=False)
    center_frequencies = np.linspace(100, 200, num_tones)
    offsets = np.linspace(-100e-3, 100e-3, num_waveforms)
    tone_banks = [center_frequencies + offset for offset in offsets]
    return acquire.run_sweep(ri=ri, tone_banks=tone_banks, num_tone_samples=num_tone_samples,
                             length_seconds=length_seconds, state=state, description=description, wait_for_sync=False)
Exemplo n.º 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
Exemplo n.º 4
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
Exemplo n.º 5
0
def fake_sweep_array(num_tones=16,
                     num_waveforms=16,
                     num_tone_samples=2**16,
                     length_seconds=0.01,
                     state={'I_am_a': 'fake sweep array'},
                     description='fake sweep array'):
    ri = baseband.RoachBaseband(roach=mock_roach.MockRoach('roach'),
                                adc_valon=mock_valon.MockValon(),
                                initialize=False)
    center_frequencies = np.linspace(100, 200, num_tones)
    offsets = np.linspace(-100e-3, 100e-3, num_waveforms)
    tone_banks = [center_frequencies + offset for offset in offsets]
    return acquire.run_sweep(ri=ri,
                             tone_banks=tone_banks,
                             num_tone_samples=num_tone_samples,
                             length_seconds=length_seconds,
                             state=state,
                             description=description,
                             wait_for_sync=False)
Exemplo n.º 6
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
    ])
Exemplo n.º 7
0
# Run
ncf = acquire.new_nc_file(suffix=suffix)
tic = time.time()
try:
    for fft_gain, attenuation in zip(fft_gains, attenuations):
        ri.set_fft_gain(fft_gain)
        ri.set_dac_attenuator(attenuation)
        state = hw.state()
        start_time = time.time(
        )  # Use this time to retrieve the temperature (see below).
        logger.info(
            "Recording {:.1f} s coarse sweep around MHz frequencies {}".format(
                sweep_length_seconds, f0_MHz))
        sweep_array_coarse = acquire.run_sweep(
            ri=ri,
            tone_banks=sweep_frequencies_coarse_MHz,
            length_seconds=sweep_length_seconds,
            num_tone_samples=num_tone_samples_coarse,
            state=state)
        ncf.write(sweep_array_coarse)
        fit_f0_coarse_MHz = np.array([
            1e-6 * sweep_array_coarse[n].resonator.f_0
            for n in range(sweep_array_coarse.num_channels)
        ])
        logger.info("coarse - initial [kHz]: {}".format(', '.join([
            '{:.3f}'.format(1e3 * df0) for df0 in fit_f0_coarse_MHz - f0_MHz
        ])))
        sweep_frequencies_fine_MHz = offset_frequencies_fine_MHz[:, np.
                                                                 newaxis] + fit_f0_coarse_MHz[
                                                                     np.
                                                                     newaxis, :]
        logger.info(
Exemplo n.º 8
0
f_baseband = f_baseband_minimum + ri.state.adc_sample_rate / 2 ** tone_sample_exponent * np.arange(num_sweep_tones)
f_lo_center = f_lo_spacing * np.round((f_center - f_baseband.mean()) / f_lo_spacing)
logger.info("Sweep using {:d} tones spanning {:.1f} MHz with resolution {:.0f} Hz (2^{:d} samples)".format(
    num_sweep_tones, 1e-6 * f_baseband.ptp(), df_baseband, tone_sample_exponent))

# Run
npd = acquire.new_npy_directory(suffix=suffix)
tic = time.time()
try:
    for lo_index, f_lo in enumerate(f_lo_center):
        assert np.all(ri.adc_valon.get_phase_locks())
        tools.set_and_attempt_external_phase_lock(ri=ri, f_lo=1e-6 * f_lo, f_lo_spacing=1e-6 * f_lo_spacing)
        for attenuation_index, attenuation in enumerate(attenuations):
            ri.set_dac_attenuator(attenuation)
            ri.set_tone_baseband_freqs(freqs=1e-6 * np.array([f_baseband[0]]), nsamp=2 ** tone_sample_exponent)
            time.sleep(1)
            npd.write(ri.get_adc_measurement())
            tools.optimize_fft_gain(ri, fraction_of_maximum=0.5)
            state = hw.state()
            state['lo_index'] = lo_index
            state['attenuation_index'] = attenuation_index
            sweep = acquire.run_sweep(ri=ri, tone_banks=1e-6 * (f_lo + f_baseband[:, np.newaxis]),
                                      num_tone_samples=2 ** tone_sample_exponent, length_seconds=sweep_length_seconds,
                                      state=state, verbose=True)[0]
            npd.write(sweep)
finally:
    ri.set_modulation_output('high')
    npd.close()
    print("Wrote {}".format(npd.root_path))
    print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
Exemplo n.º 9
0
tic = time.time()
try:
    for lo_index, f_lo in enumerate(f_lo_center):
        assert np.all(ri.adc_valon.get_phase_locks())
        tools.set_and_attempt_external_phase_lock(ri=ri, f_lo=1e-6 * f_lo, f_lo_spacing=1e-6 * f_lo_spacing)
        for attenuation_index, attenuation in enumerate(attenuations):
            ri.set_dac_attenuator(attenuation)
            #ri.set_tone_baseband_freqs(freqs=1e-6 * np.array([f_baseband[0]]), nsamp=2 ** tone_sample_exponent)
            #time.sleep(1)
            #tools.optimize_fft_gain(ri, fraction_of_maximum=0.5)
            ri.set_fft_gain(4)
            coarse_state = hw.state()
            coarse_state['lo_index'] = lo_index
            coarse_state['attenuation_index'] = attenuation_index
            coarse_sweep = acquire.run_sweep(ri=ri, tone_banks=1e-6 * (f_lo + f_baseband[::coarse_stride, np.newaxis]),
                                             num_tone_samples=2 ** tone_sample_exponent,
                                             length_seconds=stream_length_seconds, state=coarse_state,
                                             verbose=True)[0]
            npd.write(coarse_sweep)
            coarse_f_r = coarse_sweep.resonator.f_0
            coarse_Q = coarse_sweep.resonator.Q
            logger.info("Coarse sweep f_r = {:.3f} MHz +/- {:.0f} Hz".format(1e-6 * coarse_f_r,
                                                                             coarse_sweep.resonator.f_0_error))
            logger.info("Coarse sweep Q = {:.0f} +/- {:.0f}".format(coarse_Q, coarse_sweep.resonator.Q_error))
            raise Exception()
            df_filterbank = calculate.stream_sample_rate(ri_state)
            f_baseband_bin_center = df_filterbank * np.round(f_baseband.mean() / df_filterbank)
            f_lo_fine = f_lo_spacing * np.round((coarse_f_r - f_baseband_bin_center) / f_lo_spacing)
            assert np.all(ri.adc_valon.get_phase_locks())
            tools.set_and_attempt_external_phase_lock(ri=ri, f_lo=1e-6 * f_lo, f_lo_spacing=1e-6 * f_lo_spacing)
            #fine_indices = np.where(np.abs(f_lo_fine + f_baseband - coarse_f_r) <=
            #                        (fine_sweep_num_linewidths / 2) * (coarse_f_r / coarse_Q))[0]
last_f0s = initial_f0s

for heater_voltage in np.sqrt(np.linspace(0,4**2,16)):
    fg.set_dc_voltage(heater_voltage)
    if heater_voltage == 0:
        print "heater voltage is 0 V, skipping wait"
    else:
        print "waiting 20 minutes", heater_voltage
        time.sleep(1200)
    fg.enable_output(True)
    for dac_atten in [35]:
        ri.set_dac_atten(dac_atten)
        tic = time.time()
        ncf = new_nc_file(suffix='%d_dB_load_heater_%.3f_V' % (dac_atten, heater_voltage))
        swpa = acquire.run_sweep(ri, tone_banks=last_f0s[None,:] + offsets[:,None], num_tone_samples=nsamp,
                                 length_seconds=0, verbose=True,
                                 description='bb sweep')
        print "resonance sweep done", (time.time()-tic)/60.
        ncf.write(swpa)
        current_f0s = []
        for sidx in range(last_f0s.shape[0]):
            swp = swpa.sweep(sidx)
            res = swp.resonator
            print res.f_0, res.Q, res.current_result.redchi, (last_f0s[sidx]*1e6-res.f_0)
            if np.abs(res.f_0 - last_f0s[sidx]*1e6) > 200e3:
                current_f0s.append(last_f0s[sidx]*1e6)
                print "using original frequency for ",last_f0s[sidx]
            else:
                current_f0s.append(res.f_0)
        print "fits complete", (time.time()-tic)/60.
        current_f0s = np.array(current_f0s)/1e6
                                                                 offset_frequencies_fine_MHz[0])))
logger.info("Fine sweep span is {:.3f} MHz".format(offset_frequencies_fine_MHz.ptp()))
raw_input("Press enter to continue or ctrl-C to abort.")

# Run
ncf = acquire.new_nc_file(suffix=suffix)
tic = time.time()
try:
    for fft_gain, attenuation in zip(fft_gains, attenuations):
        ri.set_fft_gain(fft_gain)
        ri.set_dac_attenuator(attenuation)
        state = hw.state()
        start_time = time.time()  # Use this time to retrieve the temperature (see below).
        logger.info("Recording {:.1f} s coarse sweep around MHz frequencies {}".format(sweep_length_seconds, f0_MHz))
        sweep_array_coarse = acquire.run_sweep(ri=ri, tone_banks=sweep_frequencies_coarse_MHz,
                                               length_seconds=sweep_length_seconds,
                                               num_tone_samples=num_tone_samples_coarse, state=state)
        ncf.write(sweep_array_coarse)
        fit_f0_coarse_MHz = np.array([1e-6 * sweep_array_coarse[n].resonator.f_0
                                      for n in range(sweep_array_coarse.num_channels)])
        logger.info("coarse - initial [kHz]: {}".format(', '.join(['{:.3f}'.format(1e3 * df0)
                                                                   for df0 in fit_f0_coarse_MHz - f0_MHz])))
        sweep_frequencies_fine_MHz = offset_frequencies_fine_MHz[:, np.newaxis] + fit_f0_coarse_MHz[np.newaxis, :]
        logger.info("Recording {:.1f} s fine sweep around MHz frequencies {}".format(sweep_length_seconds,
                                                                                     fit_f0_coarse_MHz))
        sweep_array_fine = acquire.run_sweep(ri=ri, tone_banks=sweep_frequencies_fine_MHz,
                                             length_seconds=sweep_length_seconds,
                                             num_tone_samples=num_tone_samples_fine)
        fit_f0_fine_MHz = np.array([1e-6 * sweep_array_fine[n].resonator.f_0
                                    for n in range(sweep_array_fine.num_channels)])
        logger.info("fine - coarse [kHz]: {}".format(', '.join(['{:.3f}'.format(1e3 * df0)
Exemplo n.º 12
0
#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('high')

ri.set_lo(1250.)

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

state = dict(magnetic_shield='on', cryostat='starcryo')
state.update(other=setup.state())

tic = time.time()
for lo in 880. + 190 * np.arange(0, 2):
    logger.info("Measuring at LO %.1f" % lo)
    df = acquire.new_nc_file(suffix='scan_lo_%.1f_MHz' % lo)
    ri.set_lo(lo)
    state.update(other=setup.state(fast=True))
    swa = acquire.run_sweep(ri, (np.arange(1, 257)[None, :] * 7 / 8. +
                                 ri.lo_frequency + offsets[:, None]),
                            num_tone_samples=nsamp,
                            length_seconds=0.2,
                            state=state,
                            verbose=True)
    df.write(swa)
    df.close()
    print "elapsed:", (time.time() - tic) / 60.0, 'minutes'
nsamp = 2**15
step = 1
nstep = 24
offset_bins = np.arange(-(nstep + 1), (nstep + 1)) * step
offsets = offset_bins * 512.0 / nsamp
print (initial_f0s[1]-initial_f0s[0])*1e6, offsets.ptp()


for (lo,f0s) in [(initial_lo,initial_f0s)]:
    ri.set_lo(lo)
    for dac_atten in [0]:
        ncf = new_nc_file(suffix='off_on_cw_%d_dB_dac' % dac_atten)
        ri.set_modulation_output('high')
        swpa = acquire.run_sweep(ri, tone_banks=f0s[None,:] + offsets[:,None], num_tone_samples=nsamp,
                                 length_seconds=0.5, state=setup.state(), verbose=True,
                                 description='source off 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(f0s.shape[0]):
            swp = swpa.sweep(sidx)
            res = swp.resonator
            print res.f_0, res.Q, res.current_result.redchi, (f0s[sidx]*1e6-res.f_0)
            if np.abs(res.f_0 - f0s[sidx]*1e6) > 0.9*(initial_f0s[1]-initial_f0s[0])*1e6:
                current_f0s.append(f0s[sidx]*1e6)
                print "using original frequency for ",f0s[sidx]
            else:
                current_f0s.append(res.f_0)
        print "fits complete", (time.time()-tic)/60.
Exemplo n.º 14
0
step = 1
nstep = 32
offset_bins = np.arange(-(nstep + 1), (nstep + 1)) * step
offsets = offset_bins * 512.0 / nsamp

for (lo, f0s) in [(initial_lo, initial_f0s)]:
    ri.set_lo(lo)
    #for dac_atten in [2,6,10,20]:
    for dac_atten in [2]:
        ri.set_dac_atten(dac_atten)
        tic = time.time()
        ncf = new_nc_file(suffix='%d_dB_dac' % dac_atten)
        swpa = acquire.run_sweep(ri,
                                 tone_banks=f0s[None, :] + offsets[:, None],
                                 num_tone_samples=nsamp,
                                 length_seconds=0,
                                 state=setup.state(),
                                 verbose=True,
                                 description='dark 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(f0s.shape[0]):
            swp = swpa.sweep(sidx)
            res = swp.resonator
            print res.f_0, res.Q, res.current_result.redchi, (f0s[sidx] * 1e6 -
                                                              res.f_0)
            if np.abs(res.f_0 - f0s[sidx] * 1e6) > 200e3:
                current_f0s.append(f0s[sidx] * 1e6)
                print "using original frequency for ", f0s[sidx]
Exemplo n.º 15
0
 assert np.all(ri.adc_valon.get_phase_locks())
 tools.set_and_attempt_external_phase_lock(ri=ri,
                                           f_lo=1e-6 * f_lo,
                                           f_lo_spacing=1e-6 *
                                           f_lo_spacing)
 for attenuation_index, attenuation in enumerate(attenuations):
     ri.set_dac_attenuator(attenuation)
     ri.set_tone_baseband_freqs(freqs=1e-6 *
                                np.array([f_baseband[0, :]]),
                                nsamp=2**tone_sample_exponent)
     time.sleep(1)
     tools.optimize_fft_gain(ri, fraction_of_maximum=0.5)
     time.sleep(1)
     sweep_array = acquire.run_sweep(
         ri=ri,
         tone_banks=1e-6 * (f_lo + f_baseband),
         num_tone_samples=2**tone_sample_exponent,
         length_seconds=sweep_length_seconds,
         state=hw.state())
     fit_f_r = [
         sweep_array[number].resonator.f_0
         for number in range(sweep_array.num_channels)
     ]
     logger.info("Fit resonance frequencies [MHz] {}".format(', '.join(
         "{:.1f}".format(1e-6 * f_r) for f_r in fit_f_r)))
     fit_Q = [
         sweep_array[number].resonator.Q
         for number in range(sweep_array.num_channels)
     ]
     logger.info("Fit quality factors {}".format(', '.join(
         '{:.3g}'.format(Q) for Q in fit_Q)))
     ri.set_tone_freqs(freqs=1e-6 * np.array(fit_f_r),
Exemplo n.º 16
0
ri.set_modulation_output('low')

#setup = hardware.Hardware()

ri = Roach2Baseband()

#turn on source
ri.set_modulation_output(7)
raw_input('set attenuator knobs to 3 turns & check lock-in range')

for dac_atten in [10]:
    ri.set_dac_atten(dac_atten)

    ri.set_modulation_output('low')

    df = acquire.new_nc_file(suffix='vna_dac_atten_%.1f_dB_3_turns_broadband' %
                             dac_atten)
    swa = acquire.run_sweep(
        ri,
        np.linspace(100, 180, 64)[None, :] +
        np.arange(650, dtype='int')[:, None] * 512. / 2.**18,
        2**18,
        verbose=True,
        length_seconds=.1,
    )
    df.write(swa)
    df.close()

#for example
#170-230 MHz band, steps are (230-170)/128
#then sampling 480 times between each of these steps by stepping an additional 2**18
Exemplo n.º 17
0
 fg.set_dc_voltage(heater_voltage)
 if heater_voltage == 0:
     print "heater voltage is 0 V, skipping wait"
 else:
     print "waiting 15 minutes", heater_voltage
     time.sleep(900)
 fg.enable_output(True)
 for dac_atten in [35]:
     ri.set_dac_atten(dac_atten)
     tic = time.time()
     ncf = new_nc_file(suffix='%d_dB_load_heater_%.3f_V' %
                       (dac_atten, heater_voltage))
     swpa = acquire.run_sweep(ri,
                              tone_banks=last_f0s[None, :] +
                              offsets[:, None],
                              num_tone_samples=nsamp,
                              length_seconds=0,
                              verbose=True,
                              description='bb sweep')
     print "resonance sweep done", (time.time() - tic) / 60.
     ncf.write(swpa)
     current_f0s = []
     for sidx in range(last_f0s.shape[0]):
         swp = swpa.sweep(sidx)
         res = swp.resonator
         print res.f_0, res.Q, res.current_result.redchi, (
             last_f0s[sidx] * 1e6 - res.f_0)
         if np.abs(res.f_0 - last_f0s[sidx] * 1e6) > 200e3:
             current_f0s.append(last_f0s[sidx] * 1e6)
             print "using original frequency for ", last_f0s[sidx]
         else:
ri = Roach2Baseband()

ri.set_modulation_output('low')

#setup = hardware.Hardware()

ri = Roach2Baseband()

#turn on source
ri.set_modulation_output(7)
raw_input('set attenuator knobs to 3 turns & check lock-in range')

for dac_atten in [10]:
    ri.set_dac_atten(dac_atten)


    ri.set_modulation_output('low')

    df = acquire.new_nc_file(suffix='vna_dac_atten_%.1f_dB_3_turns_broadband' % dac_atten)
    swa = acquire.run_sweep(ri,np.linspace(100,180,64)[None,:]+np.arange(650,dtype='int')[:,None]*512./2.**18,
                            2**18,
                            verbose=True,length_seconds=.1,
                            )
    df.write(swa)
    df.close()


#for example
#170-230 MHz band, steps are (230-170)/128
#then sampling 480 times between each of these steps by stepping an additional 2**18
Exemplo n.º 19
0
hw = hardware.Hardware(conditioner, magnet)
ri = hardware_tools.r2_with_mk2()
ri.set_dac_atten(40)
ri.set_fft_gain(4)
ri.set_modulation_output('high')

# Run
ncf = acquire.new_nc_file(suffix='sweep_stream')
tic = time.time()
try:
    for lo in progress(lo_MHz):
        state = hw.state()
        state['temperature'] = {'package': temps.get_temperature_at(time.time())}
        tone_banks = (lo + offsets_MHz)[:, np.newaxis]  # Transform to shape (num_offsets, 1)
        ri.set_lo(lomhz=lo, chan_spacing=round_to_MHz)
        sweep_array = acquire.run_sweep(ri, tone_banks=tone_banks, num_tone_samples=num_tone_samples,
                                        length_seconds=sweep_length_seconds)
        single_sweep = sweep_array[0]
        f0_MHz = 1e-6 * single_sweep.resonator.f_0
        ri.set_tone_freqs(np.array([f0_MHz]), nsamp=num_tone_samples)
        ri.select_fft_bins(np.array([0]))
        stream_array = ri.get_measurement(num_seconds=stream_length_seconds)
        single_stream = stream_array[0]
        sweep_stream = basic.SingleSweepStream(sweep=single_sweep, stream=single_stream, state=state,
                                               description='f_0 = {:.1f}'.format(f0_MHz))
        ncf.write(sweep_stream)
finally:
        ncf.close()
        print("Wrote {}".format(ncf.root_path))
        print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
Exemplo n.º 20
0
    scan = basic.Scan(sweep_arrays=core.IOList())
    npd.write(scan)
    ri.set_dac_attenuator(attenuation)
    for lo_index, f_lo in enumerate(f_lo_all):
        assert np.all(ri.adc_valon.get_phase_locks())
        tools.set_and_attempt_external_phase_lock(ri=ri,
                                                  f_lo=1e-6 * f_lo,
                                                  f_lo_spacing=1e-6 *
                                                  f_lo_resolution)
        if lo_index == 0:
            ri.set_tone_baseband_freqs(freqs=1e-6 * f_baseband_all[0, :],
                                       nsamp=2**tone_sample_exponent)
            ri.select_fft_bins(
                readout_selection=np.arange(ri.tone_bins.shape[1]))
            time.sleep(1)
            tools.optimize_fft_gain(ri)
        state = hw.state()
        state['lo_index'] = lo_index
        #state['attenuation_index'] = attenuation_index
        scan.sweep_arrays.append(
            acquire.run_sweep(ri=ri,
                              tone_banks=1e-6 * (f_lo + f_baseband_all),
                              num_tone_samples=2**tone_sample_exponent,
                              length_seconds=length_seconds,
                              state=state))
        npd.write(ri.get_adc_measurement())
finally:
    npd.close()
    print("Wrote {}".format(npd.root_path))
    print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
Exemplo n.º 21
0
mmw_freqs = np.linspace(140e9, 165e9, 128)

ri.set_dac_atten(20)
ri.set_lo(initial_lo)

tic = time.time()
f0s = initial_f0s
#setup.hittite.off()

#high is off for initital
ri.set_modulation_output('high')

ncf_source_off = new_nc_file(suffix= 'mmw_broadband_source_off')

swpa = acquire.run_sweep(ri,tone_banks=f0s[None,:]+offsets[:,None],num_tone_samples=nsamp,
                         length_seconds=0.2,
                  verbose=True, state=setup.state())
print "resonance sweep done", (time.time()-tic)/60.

print "sweep written", (time.time()-tic)/60.
current_f0s = []
for sidx in range(swpa.num_channels):
    swp = swpa.sweep(sidx)
    res = swp.resonator
    print res.f_0, res.Q, res.delay*1e6, res.current_result.redchi, (f0s[sidx]*1e6-res.f_0)
    if np.abs(f0s[sidx]*1e6-res.f_0) > 100e3:
        current_f0s.append(f0s[sidx]*1e6)
        logger.info("Resonator index %d moved more than 100 kHz, keeping original value %.1f MHz" % (sidx,
                                                                                                     f0s[sidx]))
    else:
        current_f0s.append(res.f_0)
 num_dummy_frequencies = 2 ** int(np.ceil(np.log2(f_center.size))) - f_center.size
 logger.info("Padding {:d} resonances with {:d} dummy frequencies".format(f_center.size, num_dummy_frequencies))
 f_dummy = f_baseband_maximum + 4 * df_filterbank * np.arange(1, num_dummy_frequencies + 1)
 f_center_baseband = np.concatenate((f_center - f_center.min() + f_baseband_minimum + f_sweep_span / 2, f_dummy))
 n_center_baseband = np.round(f_center_baseband / df_baseband).astype(int)
 n_sweep_offset = np.arange(-num_sweep_tones // 2, num_sweep_tones // 2)
 f_baseband = df_baseband * (n_center_baseband[np.newaxis, :] + n_sweep_offset[:, np.newaxis])
 assert np.all(ri.adc_valon.get_phase_locks())
 tools.set_and_attempt_external_phase_lock(ri=ri, f_lo=1e-6 * f_lo, f_lo_spacing=1e-6 * f_lo_spacing)
 ri.set_dac_attenuator(attenuation)
 ri.set_tone_baseband_freqs(freqs=1e-6 * np.array([f_baseband[0, :]]), nsamp=2 ** tone_sample_exponent)
 time.sleep(1)
 tools.optimize_fft_gain(ri, fraction_of_maximum=0.5)
 time.sleep(1)
 sweep_array = acquire.run_sweep(ri=ri, tone_banks=1e-6 * (f_lo + f_baseband),
                                 num_tone_samples=2 ** tone_sample_exponent,
                                 length_seconds=sweep_length_seconds, state=hw.state())
 fit_f_r = np.array([sweep_array[number].resonator.f_0 for number in range(sweep_array.num_channels)])
 logger.info("Fit resonance frequencies [MHz] {}".format(', '.join(
     "{:.1f}".format(1e-6 * f_r) for f_r in fit_f_r)))
 fit_Q = [sweep_array[number].resonator.Q for number in range(sweep_array.num_channels)]
 logger.info("Fit quality factors {}".format(', '.join(
     '{:.3g}'.format(Q) for Q in fit_Q)))
 ri.set_tone_freqs(freqs=1e-6 * np.array(fit_f_r), nsamp=2 ** tone_sample_exponent)
 sweep_stream_list = basic.SweepStreamList(sweep=sweep_array, stream_list=core.IOList(),
                                           state={'band_index': band_index,
                                                  'num_dummy_frequencies': num_dummy_frequencies})
 npd.write(sweep_stream_list)
 npd.write(ri.get_adc_measurement())
 ri.set_modulation_output(7)
 time.sleep(3)  # Let the lock-in catch up
nsamp = 2**15
step = 1
nstep = 32
#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.)

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

state = dict(magnetic_shield = 'on', cryostat='starcryo')
state.update(other=setup.state())

tic = time.time()
for lo in 790.+190*np.arange(0,5):
    logger.info("Measuring at LO %.1f" % lo)
    df = acquire.new_nc_file(suffix='scan_lo_%.1f_MHz' % lo)
    ri.set_lo(lo)
    state.update(other=setup.state(fast=True))
    swa = acquire.run_sweep(ri, (np.arange(1, 257)[None, :] * 7 / 8. + ri.lo_frequency + offsets[:, None]),
                            num_tone_samples=nsamp, length_seconds=0.2, state=state, verbose=True)
    df.write(swa)
    df.close()
    print "elapsed:", (time.time()-tic)/60.0,'minutes'

Exemplo n.º 24
0
#ri.set_tone_baseband_freqs(freqs=1e-6 * f_baseband_all, nsamp=2 ** tone_sample_exponent)
f_lo_all = f_start - f_baseband_minimum + df_lo * np.arange(num_sweeps)

# Run
npd = acquire.new_npy_directory(suffix=suffix)
tic = time.time()
try:
    scan = basic.Scan(sweep_arrays=core.IOList())
    npd.write(scan)
    ri.set_dac_attenuator(attenuation)
    for lo_index, f_lo in enumerate(f_lo_all):
        assert np.all(ri.adc_valon.get_phase_locks())
        tools.set_and_attempt_external_phase_lock(ri=ri, f_lo=1e-6 * f_lo, f_lo_spacing=1e-6 * f_lo_resolution)
        if lo_index == 0:
            ri.set_tone_baseband_freqs(freqs=1e-6 * f_baseband_all[0, :],
                                       nsamp=2 ** tone_sample_exponent)
            ri.select_fft_bins(readout_selection=np.arange(ri.tone_bins.shape[1]))
            time.sleep(1)
            tools.optimize_fft_gain(ri)
        state = hw.state()
        state['lo_index'] = lo_index
        #state['attenuation_index'] = attenuation_index
        scan.sweep_arrays.append(acquire.run_sweep(ri=ri, tone_banks=1e-6 * (f_lo + f_baseband_all),
                                                   num_tone_samples=2 ** tone_sample_exponent,
                                                   length_seconds=length_seconds, state=state))
        npd.write(ri.get_adc_measurement())
finally:
    npd.close()
    print("Wrote {}".format(npd.root_path))
    print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
                                           f_lo_spacing=1e-6 *
                                           f_lo_spacing)
 for attenuation_index, attenuation in enumerate(attenuations):
     ri.set_dac_attenuator(attenuation)
     ri.set_tone_baseband_freqs(freqs=1e-6 * np.array([f_baseband[0]]),
                                nsamp=2**tone_sample_exponent)
     #time.sleep(1)
     #tools.optimize_fft_gain(ri, fraction_of_maximum=0.5)
     ri.set_fft_gain(4)
     coarse_state = hw.state()
     coarse_state['lo_index'] = lo_index
     coarse_state['attenuation_index'] = attenuation_index
     coarse_sweep = acquire.run_sweep(
         ri=ri,
         tone_banks=1e-6 *
         (f_lo + f_baseband[::coarse_stride, np.newaxis]),
         num_tone_samples=2**tone_sample_exponent,
         length_seconds=stream_length_seconds,
         state=coarse_state,
         verbose=True)[0]
     npd.write(coarse_sweep)
     coarse_f_r = coarse_sweep.resonator.f_0
     coarse_Q = coarse_sweep.resonator.Q
     logger.info("Coarse sweep f_r = {:.3f} MHz +/- {:.0f} Hz".format(
         1e-6 * coarse_f_r, coarse_sweep.resonator.f_0_error))
     logger.info("Coarse sweep Q = {:.0f} +/- {:.0f}".format(
         coarse_Q, coarse_sweep.resonator.Q_error))
     df_filterbank = calculate.stream_sample_rate(ri_state)
     f_baseband_bin_center = df_filterbank * np.round(
         f_baseband.mean() / df_filterbank)
     f_lo_fine = f_lo_spacing * np.round(
         (coarse_f_r - f_baseband_bin_center) / f_lo_spacing)
Exemplo n.º 26
0
offset_frequencies_MHz = 1e-6 * f_resolution * offset_integers
sweep_frequencies_MHz = offset_frequencies_MHz[:, np.newaxis] + f0_MHz[np.newaxis, :]
logger.info("Frequency spacing is {:.3f} kHz".format(1e3 * (offset_frequencies_MHz[1] - offset_frequencies_MHz[0])))
logger.info("Sweep span is {:.3f} MHz".format(offset_frequencies_MHz.ptp()))

# Run
ncf = acquire.new_nc_file(suffix='magnetic_shield')
tic = time.time()
try:
    for attenuation in attenuations:
        ri.set_dac_attenuator(attenuation)
        logger.info("Set DAC attenuation to {:.1f} dB".format(attenuation))
        state = hw.state()
        state['temperature'] = {'package': starcryo_temps.get_temperatures_at(time.time())[0]}
        logger.info("Recording {:.1f} s sweep at MHz center frequencies {}".format(sweep_length_seconds, f0_MHz))
        sweep_array = acquire.run_sweep(ri=ri, tone_banks=sweep_frequencies_MHz, length_seconds=sweep_length_seconds,
                                        num_tone_samples=num_tone_samples)
        fit_f0_MHz = np.array([1e-6 * sweep_array[n].resonator.f_0 for n in range(sweep_array.num_channels)])
        logger.info("Fit - initial [kHz]: {}".format(', '.join(['{:.3f}'.format(1e3 * df0) for df0 in fit_f0_MHz - f0_MHz])))
        f_stream_MHz = ri.set_tone_freqs(np.array(fit_f0_MHz), nsamp=num_tone_samples)
        ri.select_bank(0)
        ri.select_fft_bins(np.arange(f_stream_MHz.size))
        logger.info("Recording {:.1f} s streams at MHz frequencies {}".format(stream_length_seconds, f_stream_MHz))
        stream_array = ri.get_measurement(num_seconds=stream_length_seconds)
        sweep_stream_array = basic.SweepStreamArray(sweep_array=sweep_array, stream_array=stream_array,
                                                    description='attenuation {:.1f} dB'.format(attenuation))
        logger.debug("Writing SweepStreamArray.")
        ncf.write(sweep_stream_array)
        # Record an ADCSnap with the stream tones playing.
        logger.debug("Recording ADCSnap.")
        adc_snap = ri.get_adc_measurement()
        logger.debug("Writing ADCSnap.")
Exemplo n.º 27
0
    'orientation': 'up',
    'distance_from_base_mm': 25
})
hw = hardware.Hardware(conditioner, magnet)
ri = hardware_tools.r2_with_mk2()
ri.set_dac_atten(40)
ri.set_fft_gain(4)
ri.set_modulation_output('high')

# Run
ncf = acquire.new_nc_file(suffix='sweep')
tic = time.time()
try:
    for lo in progress(lo_MHz):
        state = hw.state()
        state['temperature'] = {
            'package': temps.get_temperature_at(time.time())
        }
        tone_banks = np.array([np.array([f]) for f in lo + offsets_MHz])
        ri.set_lo(lomhz=lo, chan_spacing=round_to_MHz)
        sweep = acquire.run_sweep(ri,
                                  tone_banks=tone_banks,
                                  num_tone_samples=num_tone_samples,
                                  length_seconds=length_seconds,
                                  state=state)
        ncf.write(sweep)
finally:
    ncf.close()
    print("Wrote {}".format(ncf.root_path))
    print("Elapsed time {:.0f} minutes.".format((time.time() - tic) / 60))
sweep_frequencies_MHz = offset_frequencies_MHz[:, np.newaxis] + f0_MHz[np.newaxis, :]
logger.info("Frequency spacing is {:.3f} kHz".format(1e3 * (offset_frequencies_MHz[1] - offset_frequencies_MHz[0])))
logger.info("Sweep span is {:.3f} MHz".format(offset_frequencies_MHz.ptp()))

# Run
ncf = acquire.new_nc_file(suffix='magnetic_shield_compressor_off')
tic = time.time()
try:
    for attenuation in attenuations:
        ri.set_dac_attenuator(attenuation)
        logger.info("Set DAC attenuation to {:.1f} dB".format(attenuation))
        state = hw.state()
        state['temperature'] = {'package': starcryo_temps.get_temperatures_at(time.time())[0]}
        raw_input("Hit enter when temperatures have recovered.")
        logger.info("Recording {:.1f} s sweep at MHz center frequencies {}".format(sweep_length_seconds, f0_MHz))
        sweep_array = acquire.run_sweep(ri=ri, tone_banks=sweep_frequencies_MHz, length_seconds=sweep_length_seconds,
                                        num_tone_samples=num_tone_samples)
        fit_f0_MHz = np.array([1e-6 * sweep_array[n].resonator.f_0 for n in range(sweep_array.num_channels)])
        logger.info("Fit - initial [kHz]: {}".format(', '.join(['{:.3f}'.format(df0) for df0 in fit_f0_MHz - f0_MHz])))
        f_stream_MHz = ri.set_tone_freqs(np.array(fit_f0_MHz), nsamp=num_tone_samples)
        ri.select_bank(0)
        ri.select_fft_bins(np.arange(f_stream_MHz.size))
        logger.info("Turning compressor off to record stream.")
        raw_input("Hit enter to continue.")
        logger.info("Recording {:.1f} s streams at MHz frequencies {}".format(stream_length_seconds, f_stream_MHz))
        stream_array = ri.get_measurement(num_seconds=stream_length_seconds)
        logger.info("Turning compressor on.")
        sweep_stream_array = basic.SweepStreamArray(sweep_array=sweep_array, stream_array=stream_array,
                                                    description='attenuation {:.1f} dB'.format(attenuation))
        logger.debug("Writing SweepStreamArray.")
        ncf.write(sweep_stream_array)
        # Record an ADCSnap with the stream tones playing.