2.3. Modelling Pulses Using Functions And Expressions

Assume we want to model a pulse that represents a damped sine function. While we could, in theory, do this using TablePulseTemplates by piecewise linear approximation (cf. Modelling a Simple TablePulseTemplate), this would be a tedious endeavor. A much simpler approach presents itself in the form of the FunctionPulseTemplate class of the qctoolkit. Like the TablePulseTemplate, a FunctionPulseTemplate represents an atomic pulse which will be converted into a waveform for execution. The difference between both is that FunctionPulseTemplate accepts a mathematical expression which is parsed and evaluated using sympy to sample the waveform instead of the linear interpolation between specified supporting points as it is done in TablePulseTemplate.

To define the sine function pulse template, we can thus do the following:

In [1]:
from qctoolkit.pulses import FunctionPT

template = FunctionPT('exp(-t/2)*sin(2*t)', '2*3.1415')

%matplotlib notebook
from qctoolkit.pulses.plotting import plot

_ = plot(template, sample_rate=100)

The first argument to FunctionPulseTemplate’s constructor is the string representation of the formula that the pulse represents. The second argument is used to compute the length of the pulse. In this case, this is simply a constant expression. Refer to sympy’s documentation to read about the usable operators and functions in the expressions.

The t is reserved as the free variable of the time domain in the first argument and must be present. Other variables can be used at will and corresponding values have to be passed in as a parameter when instantiating the FunctionPulseTemplate:

In [2]:
param_template = FunctionPT('exp(-t/tau)*sin(phi*t)', 'duration')

_ = plot(param_template, {'tau': 4, 'phi': 8, 'duration': 4*3.1415}, sample_rate=100)