Example #1
0
def test_waveform_samples():
    # this is a very naive check: can we sample from the built-in template
    # waveforms?
    duration = 1e-6
    waveforms = [
        FlatWaveform(duration=duration, iq=1.0),
        FlatWaveform(duration=duration, iq=1.0 + 2.0j),
        GaussianWaveform(duration=duration, fwhm=2.0, t0=1.0),
        DragGaussianWaveform(duration=duration,
                             fwhm=duration / 4,
                             t0=duration / 2,
                             anh=5.0,
                             alpha=3.0),
        HrmGaussianWaveform(
            duration=duration,
            fwhm=duration / 4,
            t0=duration / 2,
            anh=5.0,
            alpha=3.0,
            second_order_hrm_coeff=0.5,
        ),
        ErfSquareWaveform(duration=duration,
                          risetime=duration / 8,
                          pad_left=0.0,
                          pad_right=0.0),
        BoxcarAveragerKernel(duration=duration),
    ]

    rates = [int(1e9), 1e9, 1e9 + 0.5]

    for rate in rates:
        for wf in waveforms:
            assert wf.samples(rate) is not None
Example #2
0
def test_parse_pulse():
    wf = FlatWaveform(duration=1.0, iq=1.0)
    parse_equals('PULSE 0 "rf" flat(duration: 1.0, iq: 1.0)', Pulse(Frame([Qubit(0)], "rf"), wf))
    parse_equals('PULSE 0 1 "ff" flat(duration: 1.0, iq: 1.0)', Pulse(Frame([Qubit(0), Qubit(1)], "ff"), wf))
    parse_equals(
        'NONBLOCKING PULSE 0 "rf" flat(duration: 1.0, iq: 1.0)',
        Pulse(Frame([Qubit(0)], "rf"), wf, nonblocking=True),
    )
Example #3
0
def test_parsing_capture():
    wf = FlatWaveform(duration=1.0, iq=1.0)
    parse_equals(
        "DECLARE iq REAL[2]\n" 'CAPTURE 0 "ro_rx" flat(duration: 1.0, iq: 1.0) iq',
        Declare("iq", "REAL", 2),
        Capture(Frame([Qubit(0)], "ro_rx"), wf, MemoryReference("iq")),
    )
    parse_equals(
        "DECLARE iq REAL[2]\n" 'NONBLOCKING CAPTURE 0 "ro_rx" flat(duration: 1.0, iq: 1.0) iq',
        Declare("iq", "REAL", 2),
        Capture(Frame([Qubit(0)], "ro_rx"), wf, MemoryReference("iq"), nonblocking=True),
    )
Example #4
0
def test_parse_template_waveforms():
    def wf_agrees(wf_str: str, wf: TemplateWaveform):
        frame = Frame([Qubit(0)], "rf")
        pulse_str = 'PULSE 0 "rf" ' + wf_str
        parse_equals(pulse_str, Pulse(frame, wf))

    wf_agrees("flat(duration: 1.0, iq: 2.0)", FlatWaveform(duration=1.0,
                                                           iq=2.0))
    wf_agrees("flat(duration: 1.0, iq: 2)", FlatWaveform(duration=1.0, iq=2.0))
    wf_agrees("flat(iq: 2.0, duration: 1.0)", FlatWaveform(duration=1.0,
                                                           iq=2.0))
    wf_agrees("flat(duration: 1.0, iq: 1 + 2.0*i)",
              FlatWaveform(duration=1.0, iq=1.0 + 2.0j))
    wf_agrees(
        "flat(duration: 1.0, iq: 1.0, detuning: 1e-5)",
        FlatWaveform(duration=1.0, iq=1.0, detuning=1e-5),
    )
    wf_agrees("flat(duration: 1.0, iq: 1.0, scale: 0.5)",
              FlatWaveform(duration=1.0, iq=1.0, scale=0.5))
    wf_agrees(
        "gaussian(fwhm: 2.0, t0: 1.0, duration: 3.0)",
        GaussianWaveform(duration=3.0, fwhm=2.0, t0=1.0),
    )
    wf_agrees(
        "drag_gaussian(fwhm: 2.0, t0: 1.0, anh: 5.0, alpha: 3.0, duration: 5.0)",
        DragGaussianWaveform(duration=5.0,
                             fwhm=2.0,
                             t0=1.0,
                             anh=5.0,
                             alpha=3.0),
    )
    wf_agrees(
        "hrm_gaussian(fwhm: 2.0, t0: 1.0, anh: 5.0, alpha: 3.0, " +
        "             duration: 5.0, second_order_hrm_coeff: 0.5)".strip(),
        HrmGaussianWaveform(duration=5.0,
                            fwhm=2.0,
                            t0=1.0,
                            anh=5.0,
                            alpha=3.0,
                            second_order_hrm_coeff=0.5),
    )
    wf_agrees(
        "erf_square(risetime: 0.5, pad_left: 1.0, pad_right: 0.0, duration: 3.0)",
        ErfSquareWaveform(duration=3.0,
                          risetime=0.5,
                          pad_left=1.0,
                          pad_right=0.0),
    )
    wf_agrees("boxcar_kernel(duration: 1.0)",
              BoxcarAveragerKernel(duration=1.0))

    # missing required field
    with pytest.raises(ValueError):
        parse('PULSE 0 "rf" flat(duration: 1.0)')

    # undefined template
    with pytest.raises(ValueError):
        parse('PULSE 0 "rf" undefined_template(duration: 1)')
Example #5
0
def test_parsing_defcal_measure():
    parse_equals("DEFCAL MEASURE 0:\n" "    NOP\n", DefMeasureCalibration(Qubit(0), None, [NOP]))
    wf = FlatWaveform(duration=1.0, iq=1.0)
    # TODO: note that in a calibration body, reference to the formal argument addr parses
    #       as a memoryreference.
    parse_equals(
        "DEFCAL MEASURE q addr:\n"
        '    PULSE q "ro_tx" flat(duration: 1.0, iq: 1.0+0.0*i)\n'
        '    CAPTURE q "ro_rx" flat(duration: 1.0, iq: 1.0+0*i) addr[0]\n',
        DefMeasureCalibration(
            FormalArgument("q"),
            FormalArgument("addr"),
            [
                Pulse(Frame([FormalArgument("q")], "ro_tx"), wf),
                Capture(Frame([FormalArgument("q")], "ro_rx"), wf, MemoryReference("addr")),
            ],
        ),
    )
Example #6
0
 def flat(**kwargs):
     return FlatWaveform(duration=1e-8, iq=1.0, **kwargs).samples(1e9)