Example #1
0
 def test_sampled_pulse(self):
     """Test that we can convert to a sampled pulse."""
     gauss = Gaussian(duration=25, sigma=4, amp=0.5j)
     sample_pulse = gauss.get_sample_pulse()
     self.assertIsInstance(sample_pulse, SamplePulse)
     pulse_lib_gaus = gaussian(duration=25, sigma=4,
                               amp=0.5j, zero_ends=False).samples
     np.testing.assert_almost_equal(sample_pulse.samples, pulse_lib_gaus)
Example #2
0
 def test_gauss_square_extremes(self):
     """Test that the gaussian square pulse can build a gaussian."""
     duration = 125
     sigma = 4
     amp = 0.5j
     gaus_square = GaussianSquare(duration=duration, sigma=sigma, amp=amp, width=0)
     gaus = Gaussian(duration=duration, sigma=sigma, amp=amp)
     np.testing.assert_almost_equal(gaus_square.get_sample_pulse().samples,
                                    gaus.get_sample_pulse().samples)
     gaus_square = GaussianSquare(duration=duration, sigma=sigma, amp=amp, width=121)
     const = ConstantPulse(duration=duration, amp=amp)
     np.testing.assert_almost_equal(gaus_square.get_sample_pulse().samples[2:-2],
                                    const.get_sample_pulse().samples[2:-2])
Example #3
0
 def test_gauss_samples(self):
     """Test that the gaussian samples match the formula."""
     duration = 25
     sigma = 4
     amp = 0.5j
     # formulaic
     times = np.array(range(25), dtype=np.complex_)
     times = times - (duration / 2) + 0.5
     gauss = amp * np.exp(-(times / sigma)**2 / 2)
     # command
     command = Gaussian(duration=duration, sigma=sigma, amp=amp)
     samples = command.get_sample_pulse().samples
     np.testing.assert_almost_equal(samples, gauss)
Example #4
0
 def test_repr(self):
     """Test the repr methods for parametric pulses."""
     gaus = Gaussian(duration=25, amp=0.7, sigma=4)
     self.assertEqual(repr(gaus), 'Gaussian(duration=25, amp=(0.7+0j), sigma=4)')
     gaus_square = GaussianSquare(duration=20, sigma=30, amp=1.0, width=3)
     self.assertEqual(repr(gaus_square),
                      'GaussianSquare(duration=20, amp=(1+0j), sigma=30, width=3)')
     drag = Drag(duration=5, amp=0.5, sigma=7, beta=1)
     self.assertEqual(repr(drag), 'Drag(duration=5, amp=(0.5+0j), sigma=7, beta=1)')
     const = ConstantPulse(duration=150, amp=0.1 + 0.4j)
     self.assertEqual(repr(const), 'ConstantPulse(duration=150, amp=(0.1+0.4j))')
Example #5
0
 def test_param_validation(self):
     """Test that parametric pulse parameters are validated when initialized."""
     with self.assertRaises(PulseError):
         Gaussian(duration=25, sigma=0, amp=0.5j)
     with self.assertRaises(PulseError):
         GaussianSquare(duration=150, amp=0.2, sigma=8, width=160)
     with self.assertRaises(PulseError):
         ConstantPulse(duration=150, amp=0.9 + 0.8j)
     with self.assertRaises(PulseError):
         Drag(duration=25, amp=0.2 + 0.3j, sigma=-7.8, beta=4)
     with self.assertRaises(PulseError):
         Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4j)
Example #6
0
def cr_drive_experiments(drive_idx,
                         target_idx,
                         flip_drive_qubit = False,

                         #cr_drive_amps=np.linspace(0, 0.9, 16),
                         #cr_drive_samples=800,
                         #cr_drive_sigma=4,
                         #pi_drive_samples=128,
                         #pi_drive_sigma=16
                         #meas_amp = Dims/128*0.025/2
                         #meas_width = int(rows/128*1150/2)
                         cr_drive_amps=np.linspace(0, 0.9, meas_width**2),
                         cr_drive_samples=sum(label1[:] == label2[:]),
                         cr_drive_sigma=meas_sigma,
                         pi_drive_samples=sum((label1[:] ==1)*(label2[:] ==1)), #label1[:] ==1 and label2[:] ==1
                         pi_drive_sigma=cr_drive_sigma**2):
    """Generate schedules corresponding to CR drive experiments.

    Args:
        drive_idx (int): label of driven qubit
        target_idx (int): label of target qubit
        flip_drive_qubit (bool): whether or not to start the driven qubit in the ground or excited state
        cr_drive_amps (array): list of drive amplitudes to use
        cr_drive_samples (int): number samples for each CR drive signal
        cr_drive_sigma (float): standard deviation of CR Gaussian pulse
        pi_drive_samples (int): number samples for pi pulse on drive
        pi_drive_sigma (float): standard deviation of Gaussian pi pulse on drive

    Returns:
        list[Schedule]: A list of Schedule objects for each experiment
    """

    # Construct measurement commands to be used for all schedules
    #meas_amp = 0.025
    #meas_samples = 1200
    #meas_sigma = 4
    #meas_width = 1150
    meas_amp = 0.025
    meas_sigma = 4
    ni = int(np.ceil(cols/meas_sigma))
    print(ni)
    meas_samples = rows*ni
    meas_width = int(rows*ni*23/24)
    meas_pulse = GaussianSquare(duration=meas_samples, amp=meas_amp/np.linalg.norm(meas_amp),
                               sigma=meas_sigma, width=meas_width)

    acq_sched = pulse.Acquire(meas_samples, pulse.AcquireChannel(0), pulse.MemorySlot(0))
    acq_sched += pulse.Acquire(meas_samples, pulse.AcquireChannel(1), pulse.MemorySlot(1))

    # create measurement schedule
    measure_sched = (pulse.Play(meas_pulse, pulse.MeasureChannel(0)) |
                     pulse.Play(meas_pulse, pulse.MeasureChannel(1))|
                     acq_sched)

    # Create schedule
    schedules = []
    for ii, cr_drive_amp in enumerate(cr_drive_amps):

        # pulse for flipping drive qubit if desired
        pi_pulse = Gaussian(duration=pi_drive_samples, amp=pi_amps[drive_idx], sigma=pi_drive_sigma)

        # cr drive pulse
        cr_width = cr_drive_samples - 2*cr_drive_sigma*4
        cr_rabi_pulse = GaussianSquare(duration=cr_drive_samples,
                                       amp=cr_drive_amp/np.linalg.norm(cr_drive_amp),
                                       sigma=cr_drive_sigma,
                                       width=cr_width)

        # add commands to schedule
        schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp)
        #schedule = pulse.Schedule(name='cr_rabi_exp_amp_%s' % cr_drive_amp/np.linalg.norm(cr_drive_amp))

        # flip drive qubit if desired
        if flip_drive_qubit:
            schedule += pulse.Play(pi_pulse, pulse.DriveChannel(drive_idx))

        # do cr drive
        # First, get the ControlChannel index for CR drive from drive to target
        cr_idx = two_qubit_model.control_channel_index((drive_idx, target_idx))
        schedule += pulse.Play(cr_rabi_pulse, pulse.ControlChannel(cr_idx))  << schedule.duration


        schedule += measure_sched << schedule.duration

        schedules.append(schedule)
    return schedules
Example #7
0
    """
    return (int(num) - (int(num)%4))

# samples need to be multiples of 16
def get_closest_multiple_of_16(num):
    return int(num + 8 ) - (int(num + 8 ) % 16)

# center data around 0
def baseline_remove(values):
    return np.array(values) - np.mean(values)

meas_duration = 848
meas_sigma = 32
meas_square_width = 64
meas_amp = 0.2
gaussian_pulse = Gaussian(meas_duration, meas_amp, meas_sigma)
#qc1 = transpile(GC, backend)

n = 2
t = 2
N = 1
M = 4
qc = QuantumCircuit(n,t)
GC = initialize_s(qc, range(n))
GC.measure_all()

#ceate the CR1 schedule

# The Unitary is an identity (with a global phase)
backend = qiskit.Aer.get_backend('unitary_simulator')
basis_gates = ['u1','u2','u3','cx'] # use U,CX for now
Example #8
0
 def test_construction(self):
     """Test that parametric pulses can be constructed without error."""
     Gaussian(duration=25, sigma=4, amp=0.5j)
     GaussianSquare(duration=150, amp=0.2, sigma=8, width=140)
     ConstantPulse(duration=150, amp=0.1 + 0.4j)
     Drag(duration=25, amp=0.2 + 0.3j, sigma=7.8, beta=4)