<jupyter_start><jupyter_text>Terra - Pulses Getting Started with Pulseshttps://qiskit.org/documentation/tutorials/advanced/index.html  Additional Useful Tutorial Links1. Obtaining Information about your backend https://qiskit.org/documentation/tutorials/advanced/terra/pulse/gathering_system_information.html2. Building Pulse Instructions https://qiskit.org/documentation/tutorials/advanced/terra/pulse/building_pulse_instructions.html3. Calibrating Qubits with Qiskit Pulsehttps://qiskit.org/textbook/ch-quantum-hardware/calibrating-qubits-openpulse.html<jupyter_code>from qiskit.pulse import Schedule

sched = Schedule(name='getting_started')
from qiskit.pulse import SamplePulse
my_pulse = SamplePulse([0.00043, 0.0007 , 0.00112, 0.00175, 0.00272, 0.00414, 0.00622,
                        0.00919, 0.01337, 0.01916, 0.02702, 0.03751, 0.05127, 0.06899,
                        0.09139, 0.1192 , 0.15306, 0.19348, 0.24079, 0.29502, 0.35587,
                        0.4226 , 0.49407, 0.56867, 0.64439, 0.71887, 0.78952, 0.85368,
                        0.90873, 0.95234, 0.98258, 0.99805, 0.99805, 0.98258, 0.95234,
                        0.90873, 0.85368, 0.78952, 0.71887, 0.64439, 0.56867, 0.49407,
                        0.4226 , 0.35587, 0.29502, 0.24079, 0.19348, 0.15306, 0.1192 ,
                        0.09139, 0.06899, 0.05127, 0.03751, 0.02702, 0.01916, 0.01337,
                        0.00919, 0.00622, 0.00414, 0.00272, 0.00175, 0.00112, 0.0007 ,
                        0.00043],
                       name="short_gaussian_pulse")
from qiskit.pulse import Play, DriveChannel

qubit_idx = 0
sched = sched.insert(0, Play(my_pulse, DriveChannel(qubit_idx)))
sched.draw(label=True)
from qiskit.test.mock import FakeAlmaden

backend = FakeAlmaden()
from qiskit.scheduler.utils import measure_all

sched = sched.insert(sched.duration, measure_all(backend))
sched.draw(plot_range=[0, 1000])
from qiskit import IBMQ, execute
backend = IBMQ.load_account().get_backend(open_pulse=True)
job = execute(sched, backend)

result = job.result()<jupyter_output>ibmqfactory.load_account:WARNING:2020-04-29 11:22:31,132: Credentials are already in use. The existing account in the session will be replaced.
/Users/worknic/opt/anaconda3/envs/test/lib/python3.8/site-packages/qiskit/compiler/transpile.py:174: UserWarning: Transpiling schedules is not supported yet.
  warnings.warn("Transpiling schedules is not supported yet.", UserWarning)<jupyter_text>Building Pulse Schedules<jupyter_code>from qiskit.pulse import Schedule, Play, ConstantPulse, Delay, DriveChannel

sched_a = Schedule(name="A")
sched_b = Schedule(name="B")
sched_a = sched_a.insert(0, Play(ConstantPulse(duration=5, amp=1), DriveChannel(0)))
sched_b |= Play(ConstantPulse(duration=5,amp=-1), DriveChannel(0))

sched_a.draw()
sched_b.draw()
sched_a |= Play(ConstantPulse(duration=5, amp=0.5), DriveChannel(0)).shift(10)
sched_b |= Play(ConstantPulse(duration=5, amp=-0.5), DriveChannel(0)) << 10

sched_b.draw()
sched_a_and_b = sched_a.insert(20, sched_b)
sched_b_and_a = sched_b | sched_a << 20

sched_a_and_b.draw()
sched_b_and_a.draw()
sched_a_plus_b = sched_a.append(sched_b)

sched_a_plus_b.draw()
sched_a_plus_c = sched_a + Play(ConstantPulse(duration=20, amp=0.2), DriveChannel(1))

sched_a_plus_c.draw()
sched_d = Play(ConstantPulse(duration=20, amp=-0.2), DriveChannel(0)) \
            + (Play(ConstantPulse(duration=10, amp=-0.2), DriveChannel(1)) << 10)

sched_d.draw()
sched_a_plus_c.draw()
(sched_a_plus_c + sched_d).draw()<jupyter_output><empty_output><jupyter_text>Utilizing the Scheduler<jupyter_code>from qiskit import QuantumCircuit

circ = QuantumCircuit(1, 1)
circ = QuantumCircuit(2, 2)
circ.h(0)
circ.cx(0, 1)
circ.measure([0, 1], [0, 1])

circ.draw()
from qiskit import transpile, schedule as build_schedule
from qiskit.test.mock import FakeAlmaden

backend = FakeAlmaden()

transpiled_circ = transpile(circ, backend) 
schedule = build_schedule(transpiled_circ, backend)
transpiled_circ.draw()
schedule.draw(plot_range=[0, 1700])
from qiskit.pulse import Schedule, Play, Gaussian, DriveChannel

h_q0 = Schedule(Play(Gaussian(duration=128, amp=0.045, sigma=8), DriveChannel(0)))

h_q0.draw()
inst_map = backend.defaults().instruction_schedule_map
from qiskit import transpile, schedule as build_schedule
from qiskit.test.mock import FakeAlmaden

backend = FakeAlmaden()
print(inst_map)
inst_map.add('h', 0, h_q0)
print(inst_map)
inst_map2 = backend.defaults().instruction_schedule_map
print(inst_map2)
schedule = build_schedule(circ, backend, inst_map=inst_map)<jupyter_output><empty_output><jupyter_text>Building Circuits with non-standard gates<jupyter_code>import numpy as np

from qiskit.pulse import Play, SamplePulse, ControlChannel
from qiskit.pulse.schedule import ParameterizedSchedule

def random_pulse(duration):
    if duration < 1:
        raise ValueError("Duration cannot be less than 1.")
    return SamplePulse(np.random.random(duration))

def random_2q_gate(x):
    sched = Schedule()
    sched += Play(random_pulse(x), DriveChannel(0))
    sched += Play(random_pulse(x), ControlChannel(0))
    sched + Play(random_pulse(x), DriveChannel(1))
    return sched

my_random_2q_gate = ParameterizedSchedule(random_2q_gate, parameters=['x'])    
inst_map.add('my_2q', (0, 1), my_random_2q_gate)
my_random_2q_gate(5).draw()
from qiskit.circuit import Gate

my_2q = Gate('my_2q', num_qubits=2, params=[100])
circ2 = QuantumCircuit(2, 2)
circ2.h(0)
circ2.append(my_2q, [0, 1])
circ2.h(0)
circ2.measure(0, 0)
circ2.draw()
#inst_map.remove('h', 0)

transpiled_circ2 = transpile(circ2, coupling_map=[[0, 1]],
                          basis_gates=backend.configuration().basis_gates + ['my_2q'])
transpiled_circ2.draw()
schedule = build_schedule(transpiled_circ, backend, inst_map=inst_map)

schedule.draw(plot_range=(0, 500))<jupyter_output><empty_output><jupyter_text>Scheduler Methods<jupyter_code>circ = QuantumCircuit(2, 2)
circ.x(0)
circ.x(0)
circ.x(1)
circ.measure([0, 1], [0, 1])
schedule = build_schedule(circ, backend, method="as_late_as_possible")

schedule.draw(channels_to_plot=[DriveChannel(0), DriveChannel(1)], scale=5)
schedule = build_schedule(circ, backend, method="as_soon_as_possible")
schedule.draw(channels_to_plot=[DriveChannel(0), DriveChannel(1)], scale=5)<jupyter_output><empty_output><jupyter_text>Adding Measurements to Schedules<jupyter_code>from qiskit.scheduler import measure
sched += measure([0, 1], backend) << sched.duration
sched.draw(channels_to_plot=[DriveChannel(0), DriveChannel(1)], scale=1)
from qiskit import IBMQ
from qiskit.pulse import Schedule
from qiskit.scheduler import measure_all
from qiskit.test.mock import FakeAlmaden

backend = FakeAlmaden()
sched = Schedule(name="Measurement scheduling example")
sched += measure_all(backend)

sched.draw()
from qiskit.pulse import MeasureChannel, AcquireChannel, MemorySlot, Play, GaussianSquare, Acquire

# Duration (in number of cycles) for readout
duration = 16000

# Stimulus pulses for qubits 0 and 1
measure_tx = Play(GaussianSquare(duration=duration, amp=0.2, sigma=10, width=duration - 50),
                  MeasureChannel(0))
measure_tx += Play(GaussianSquare(duration=duration, amp=0.2, sigma=10, width=duration - 50),
                   MeasureChannel(1))
measure_tx.draw()<jupyter_output><empty_output><jupyter_text>and blah blah blah... we probably won't be getting too deep into defining our own measurement procedures if we can help it...  Obtaining Information about your backend  Configuration<jupyter_code>from qiskit.test.mock import FakeAlmaden
backend = FakeAlmaden()
config = backend.configuration()

# Basic Features
print("This backend is called {0}, and is on version {1}. It has {2} qubit{3}. It "
      "{4} OpenPulse programs. The basis gates supported on this device are {5}."
      "".format(config.backend_name,
                config.backend_version,
                config.n_qubits,
                '' if config.n_qubits == 1 else 's',
                'supports' if config.open_pulse else 'does not support',
                config.basis_gates))
# this is the timescale of waveforms
# aka the inverse sampling rate of the control rack arb waveform generator
config.dt
## different types of measurement output data... but tutorials are not written yet
config.meas_levels
## sampling rate of control rack's analog-to-digital converters (ADCs)
config.dtm
config.meas_map
config.drive(0)
config.measure(0)
config.acquire(0)<jupyter_output><empty_output><jupyter_text>Properties of qubits and stuff like that<jupyter_code>props = backend.properties()
def describe_qubit(qubit, properties):
    """Print a string describing some of reported properties of the given qubit."""

    # Conversion factors from standard SI units
    us = 1e6
    ns = 1e9
    GHz = 1e-9

    print("Qubit {0} has a \n"
          "  - T1 time of {1} microseconds\n"
          "  - T2 time of {2} microseconds\n"
          "  - U2 gate error of {3}\n"
          "  - U2 gate duration of {4} nanoseconds\n"
          "  - resonant frequency of {5} GHz".format(
              qubit,
              properties.t1(qubit) * us,
              properties.t2(qubit) * us,
              properties.gate_error('u2', qubit),
              properties.gate_length('u2', qubit) * ns,
              properties.frequency(qubit) * GHz))

describe_qubit(0, props)<jupyter_output>Qubit 0 has a 
  - T1 time of 113.3795751321217 microseconds
  - T2 time of 150.2847720544259 microseconds
  - U2 gate error of 0.0005295247303964942
  - U2 gate duration of 35.555555555555564 nanoseconds
  - resonant frequency of 4.8572819835984875 GHz<jupyter_text>Pulse Defaults (only defined for pulse-enabled backends obvs)<jupyter_code>defaults = backend.defaults()<jupyter_output><empty_output><jupyter_text>Drive Frequencies<jupyter_code>q0_freq = defaults.qubit_freq_est[0]  # Hz
q0_meas_freq = defaults.meas_freq_est[0]  # Hz

GHz = 1e-9
print("DriveChannel(0) defaults to a modulation frequency of {} GHz.".format(q0_freq * GHz))
print("MeasureChannel(0) defaults to a modulation frequency of {} GHz.".format(q0_meas_freq * GHz))<jupyter_output>DriveChannel(0) defaults to a modulation frequency of 4.857219891603379 GHz.
MeasureChannel(0) defaults to a modulation frequency of 7.264856891000001 GHz.<jupyter_text>Pulse Schedule definitions for Quantum Circuit Instructions<jupyter_code>inst_map = defaults.instruction_schedule_map
print(inst_map)
measure_schedule = inst_map.get('measure', [q for q in range(config.n_qubits)])
measure_schedule.draw()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup