Esempio n. 1
0
    def test_align_right(self):
        """Test the right alignment context."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)
        d2 = pulse.DriveChannel(2)

        with pulse.build() as schedule:
            with pulse.align_right():
                with pulse.align_right():
                    pulse.delay(11, d2)
                    pulse.delay(3, d0)
                pulse.delay(13, d0)
                pulse.delay(5, d1)

        reference = pulse.Schedule()
        # d0
        reference.insert(8, instructions.Delay(3, d0), inplace=True)
        reference.insert(11, instructions.Delay(13, d0), inplace=True)
        # d1
        reference.insert(19, instructions.Delay(5, d1), inplace=True)
        # d2
        reference.insert(0, instructions.Delay(11, d2), inplace=True)

        self.assertScheduleEqual(schedule, reference)
Esempio n. 2
0
    def test_align_sequential(self):
        """Test the sequential alignment context."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)

        with pulse.build() as schedule:
            with pulse.align_sequential():
                pulse.delay(3, d0)
                pulse.delay(5, d1)
                pulse.delay(7, d0)

        reference = pulse.Schedule()
        # d0
        reference.insert(0, instructions.Delay(3, d0), inplace=True)
        reference.insert(8, instructions.Delay(7, d0), inplace=True)
        # d1
        reference.insert(3, instructions.Delay(5, d1), inplace=True)

        self.assertEqual(schedule, reference)
Esempio n. 3
0
    def test_inline(self):
        """Test the inlining context."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)

        with pulse.build() as schedule:
            pulse.delay(3, d0)
            with pulse.inline():
                # this alignment will be ignored due to inlining.
                with pulse.align_right():
                    pulse.delay(5, d1)
                    pulse.delay(7, d0)

        reference = pulse.Schedule()
        # d0
        reference += instructions.Delay(3, d0)
        reference += instructions.Delay(7, d0)
        # d1
        reference += instructions.Delay(5, d1)

        self.assertEqual(schedule, reference)
Esempio n. 4
0
    def test_complex_build(self):
        """Test a general program build with nested contexts,
        circuits and macros."""
        d0 = pulse.DriveChannel(0)
        d1 = pulse.DriveChannel(1)
        d2 = pulse.DriveChannel(2)
        delay_dur = 19
        short_dur = 31
        long_dur = 101

        with pulse.build(self.backend) as schedule:
            with pulse.align_sequential():
                pulse.delay(delay_dur, d0)
                pulse.u2(0, pi/2, 1)
            with pulse.align_right():
                pulse.play(library.Constant(short_dur, 0.1), d1)
                pulse.play(library.Constant(long_dur, 0.1), d2)
                pulse.u2(0, pi/2, 1)
            with pulse.align_left():
                pulse.u2(0, pi/2, 0)
                pulse.u2(0, pi/2, 1)
                pulse.u2(0, pi/2, 0)
            pulse.measure(0)

        # prepare and schedule circuits that will be used.
        single_u2_qc = circuit.QuantumCircuit(2)
        single_u2_qc.u2(0, pi/2, 1)
        single_u2_qc = compiler.transpile(single_u2_qc, self.backend)
        single_u2_sched = compiler.schedule(single_u2_qc, self.backend)

        # sequential context
        sequential_reference = pulse.Schedule()
        sequential_reference += instructions.Delay(delay_dur, d0)
        sequential_reference.insert(delay_dur, single_u2_sched, inplace=True)

        # align right
        align_right_reference = pulse.Schedule()
        align_right_reference += pulse.Play(
            library.Constant(long_dur, 0.1), d2)
        align_right_reference.insert(long_dur-single_u2_sched.duration,
                                     single_u2_sched,
                                     inplace=True)
        align_right_reference.insert(
            long_dur-single_u2_sched.duration-short_dur,
            pulse.Play(library.Constant(short_dur, 0.1), d1),
            inplace=True)

        # align left
        triple_u2_qc = circuit.QuantumCircuit(2)
        triple_u2_qc.u2(0, pi/2, 0)
        triple_u2_qc.u2(0, pi/2, 1)
        triple_u2_qc.u2(0, pi/2, 0)
        triple_u2_qc = compiler.transpile(triple_u2_qc, self.backend)
        align_left_reference = compiler.schedule(
            triple_u2_qc, self.backend, method='alap')

        # measurement
        measure_reference = macros.measure(qubits=[0],
                                           inst_map=self.inst_map,
                                           meas_map=self.configuration.meas_map)
        reference = pulse.Schedule()
        reference += sequential_reference
        # Insert so that the long pulse on d2 occurs as early as possible
        # without an overval on d1.
        insert_time = (reference.ch_stop_time(d1) -
                       align_right_reference.ch_start_time(d1))
        reference.insert(insert_time,
                         align_right_reference,
                         inplace=True)
        reference.insert(reference.ch_stop_time(d0, d1),
                         align_left_reference,
                         inplace=True)
        reference += measure_reference
        self.assertEqual(schedule, reference)
def output(data):
    print("We have F: ", data.F, " nT")

    N_delta = 2


    N = int(math.log(data.T_2 * 10 ** (-6) / data.t_init) / math.log(2))-N_delta
    multiplier = 30

    # Ramsey experiment parameters
    detuning_max_MHz = data.const * data.F_max * data.F_degree / (2 * math.pi) / MHz / multiplier
    detuning_min_MHz = data.const * data.F_min * data.F_degree / (2 * math.pi) / MHz / multiplier
    detuning_MHz = data.const * data.F * data.F_degree / (2 * math.pi) / MHz / multiplier

    delta_min_det_MHz = -0.05 - 0.02 - 0.12 - 0.22
    delta_max_det_MHz = -0.05 - 0.05 - 0.05 - 0.12 - 0.20

    detuning_MHz = (detuning_min_MHz+delta_min_det_MHz) + (detuning_max_MHz+delta_max_det_MHz - (detuning_min_MHz+delta_min_det_MHz))*(detuning_MHz - detuning_min_MHz)/(detuning_max_MHz-detuning_min_MHz)

    times = [data.t_init*2**(i) for i in range(N)]

    # Drive parameters
    # The drive amplitude for pi/2 is simply half the amplitude of the pi pulse
    drive_amp = pi_amp / 2

    # x_90 is a concise way to say pi_over_2; i.e., an X rotation of 90 degrees
    with pulse.build(backend) as x90_pulse:
        drive_duration = get_closest_multiple_of_16(pulse.seconds_to_samples(drive_duration_sec))
        drive_sigma = pulse.seconds_to_samples(drive_sigma_sec)
        drive_chan = pulse.drive_channel(qubit)
        pulse.play(pulse.Gaussian(duration=drive_duration,
                                  amp=drive_amp,
                                  sigma=drive_sigma,
                                  name='x90_pulse'), drive_chan)

    # create schedules for Ramsey experiment
    ramsey_schedules = []
    ramsey_frequency = round(precise_qubit_freq + detuning_MHz * MHz, 6)  # need ramsey freq in Hz
    for time in times:
        with pulse.build(backend=backend, default_alignment='sequential',
                         name=f"det = {detuning_MHz} MHz") as ramsey_schedule:
            drive_chan = pulse.drive_channel(qubit)
            pulse.set_frequency(ramsey_frequency, drive_chan)
            pulse.call(x90_pulse)
            pulse.delay(get_closest_multiple_of_16(pulse.seconds_to_samples(time*multiplier)), drive_chan)
            pulse.call(x90_pulse)
            pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)])
        ramsey_schedules.append(ramsey_schedule)

    # Execution settings
    num_shots = data.num_of_repetitions

    job = backend.run(ramsey_schedules,
                      meas_level=1,
                      meas_return='single',
                      shots=num_shots)

    job_monitor(job)

    ramsey_results = job.result(timeout=120)

    ramsey_values = {}

    for i in range(len(times)):
        iq_data = ramsey_results.get_memory(i)[:, qubit] * scale_factor
        ramsey_values[times[i]]=int(round(sum(map(classify, iq_data)) / num_shots))
    '''
    times = [data.t_init * 2 ** (i) for i in range(N, N+N_delta)]

    # create schedules for Ramsey experiment
    ramsey_schedules = []
    ramsey_frequency = round(precise_qubit_freq + detuning_MHz * MHz, 6)  # need ramsey freq in Hz
    for time in times:
        with pulse.build(backend=backend, default_alignment='sequential',
                         name=f"det = {detuning_MHz} MHz") as ramsey_schedule:
            drive_chan = pulse.drive_channel(qubit)
            pulse.set_frequency(ramsey_frequency, drive_chan)
            pulse.call(x90_pulse)
            pulse.delay(get_closest_multiple_of_16(pulse.seconds_to_samples(time * multiplier)), drive_chan)
            pulse.call(x90_pulse)
            pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)])
        ramsey_schedules.append(ramsey_schedule)

    # Execution settings
    num_shots = data.num_of_repetitions

    job = backend.run(ramsey_schedules,
                      meas_level=1,
                      meas_return='single',
                      shots=num_shots)

    job_monitor(job)

    ramsey_results = job.result(timeout=120)

    for i in range(len(times)):
        iq_data = ramsey_results.get_memory(i)[:, qubit] * scale_factor
        ramsey_values[times[i]] = int(round(sum(map(classify, iq_data)) / num_shots))
    #'''


    print(ramsey_values)
    return ramsey_values

#print(output(data))
    def test_circuit_generation_from_sec(self):
        """Test generated circuits when time unit is sec."""

        backend = CrossResonanceHamiltonianBackend()

        expr = cr_hamiltonian.CrossResonanceHamiltonian(
            qubits=(0, 1),
            flat_top_widths=[500],
            unit="ns",
            amp=0.1,
            sigma=20,
            risefall=2,
        )

        nearlest_16 = 576

        with pulse.build(default_alignment="left", name="cr") as ref_cr_sched:
            pulse.play(
                pulse.GaussianSquare(
                    nearlest_16,
                    amp=0.1,
                    sigma=20,
                    width=500,
                ),
                pulse.ControlChannel(0),
            )
            pulse.delay(nearlest_16, pulse.DriveChannel(0))
            pulse.delay(nearlest_16, pulse.DriveChannel(1))

        cr_gate = circuit.Gate("cr_gate", num_qubits=2, params=[500])
        expr_circs = expr.circuits(backend)

        x0_circ = QuantumCircuit(2, 1)
        x0_circ.append(cr_gate, [0, 1])
        x0_circ.h(1)
        x0_circ.measure(1, 0)

        x1_circ = QuantumCircuit(2, 1)
        x1_circ.x(0)
        x1_circ.append(cr_gate, [0, 1])
        x1_circ.h(1)
        x1_circ.measure(1, 0)

        y0_circ = QuantumCircuit(2, 1)
        y0_circ.append(cr_gate, [0, 1])
        y0_circ.sdg(1)
        y0_circ.h(1)
        y0_circ.measure(1, 0)

        y1_circ = QuantumCircuit(2, 1)
        y1_circ.x(0)
        y1_circ.append(cr_gate, [0, 1])
        y1_circ.sdg(1)
        y1_circ.h(1)
        y1_circ.measure(1, 0)

        z0_circ = QuantumCircuit(2, 1)
        z0_circ.append(cr_gate, [0, 1])
        z0_circ.measure(1, 0)

        z1_circ = QuantumCircuit(2, 1)
        z1_circ.x(0)
        z1_circ.append(cr_gate, [0, 1])
        z1_circ.measure(1, 0)

        ref_circs = [x0_circ, y0_circ, z0_circ, x1_circ, y1_circ, z1_circ]
        for c in ref_circs:
            c.add_calibration(cr_gate, (0, 1), ref_cr_sched)

        self.assertListEqual(expr_circs, ref_circs)
Esempio n. 7
0
# Definiamo T1 il tempo caratteristico della decrescita esponenziale osservata.

# T1 experiment parameters
time_max_sec = 450 * us
time_step_sec = 6.5 * us
delay_times_sec = np.arange(1 * us, time_max_sec, time_step_sec)

# Create schedules for the experiment
t1_schedules = []
for delay in delay_times_sec:
    with pulse.build(backend=backend, default_alignment='sequential',
                    name=f"T1 delay = {delay / ns} ns") as t1_schedule:
        drive_chan = pulse.drive_channel(qubit)
        pulse.set_frequency(rough_qubit_frequency, drive_chan)
        pulse.call(pi_pulse)
        pulse.delay(get_closest_multiple_of_16(pulse.seconds_to_samples(delay)),drive_chan)
        pulse.measure(qubits=[qubit], registers=[pulse.MemorySlot(mem_slot)])
    t1_schedules.append(t1_schedule)

sched_idx = 0
t1_schedules[sched_idx].draw(backend=backend)

# Execution settings
num_shots = 256

job = backend.run(t1_schedules,
                  meas_level=1,
                  meas_return='single',
                  shots=num_shots)

job_monitor(job)
    def test_circuit_generation(self):
        """Test generated circuits."""
        backend = FakeBogota()

        # Add granularity to check duration optimization logic
        setattr(
            backend.configuration(),
            "timing_constraints",
            {"granularity": 16},
        )

        expr = cr_hamiltonian.CrossResonanceHamiltonian(
            qubits=(0, 1),
            flat_top_widths=[1000],
            amp=0.1,
            sigma=64,
            risefall=2,
        )
        expr.backend = backend

        nearlest_16 = 1248

        with pulse.build(default_alignment="left", name="cr") as ref_cr_sched:
            pulse.play(
                pulse.GaussianSquare(
                    nearlest_16,
                    amp=0.1,
                    sigma=64,
                    width=1000,
                ),
                pulse.ControlChannel(0),
            )
            pulse.delay(nearlest_16, pulse.DriveChannel(0))
            pulse.delay(nearlest_16, pulse.DriveChannel(1))

        cr_gate = cr_hamiltonian.CrossResonanceHamiltonian.CRPulseGate(
            width=1000)
        expr_circs = expr.circuits()

        x0_circ = QuantumCircuit(2, 1)
        x0_circ.append(cr_gate, [0, 1])
        x0_circ.h(1)
        x0_circ.measure(1, 0)

        x1_circ = QuantumCircuit(2, 1)
        x1_circ.x(0)
        x1_circ.append(cr_gate, [0, 1])
        x1_circ.h(1)
        x1_circ.measure(1, 0)

        y0_circ = QuantumCircuit(2, 1)
        y0_circ.append(cr_gate, [0, 1])
        y0_circ.sdg(1)
        y0_circ.h(1)
        y0_circ.measure(1, 0)

        y1_circ = QuantumCircuit(2, 1)
        y1_circ.x(0)
        y1_circ.append(cr_gate, [0, 1])
        y1_circ.sdg(1)
        y1_circ.h(1)
        y1_circ.measure(1, 0)

        z0_circ = QuantumCircuit(2, 1)
        z0_circ.append(cr_gate, [0, 1])
        z0_circ.measure(1, 0)

        z1_circ = QuantumCircuit(2, 1)
        z1_circ.x(0)
        z1_circ.append(cr_gate, [0, 1])
        z1_circ.measure(1, 0)

        ref_circs = [x0_circ, y0_circ, z0_circ, x1_circ, y1_circ, z1_circ]
        for c in ref_circs:
            c.add_calibration(cr_gate, (0, 1), ref_cr_sched)

        self.assertListEqual(expr_circs, ref_circs)