qdyn.analytical_pulse module¶
Describing pulses by an analytical formula
Reference¶
-
class
qdyn.analytical_pulse.
AnalyticalPulse
(formula, parameters=None, time_unit=None, ampl_unit=None, t0=0.0, T=None, nt=None, freq_unit=None, config_attribs=None)[source]¶ Bases:
object
Representation of a pulse determined by an analytical formula
- Parameters
formula (str) – Name of a previously registered formula
parameters (dict) – Dictionary of values for the pulse formula
time_unit (str or None) – The unit of the tgrid input parameter of the formula (None is equivalent to ‘iu’)
ampl_unit (str or None) – Unit in which the amplitude is defined. It is assumed that the formula gives values in the correct unit.
T (float or str or callable or None) – End time of the pulse
nt (int or str or callable or None) – Number of grid points between t0 and T (inclusive)
freq_unit (str or None) – Preferred unit for pulse spectra. If None, unit will be chose automatically.
config_attribs (dict or None) – Additional config data, for when generating a QDYN config file section describing the pulse (e.g. {‘oct_shape’: ‘flattop’, ‘t_rise’: ‘10_ns’})
-
config_attribs
¶ dictionary with the items from the config_attribs arg
Notes
The t0, T, and nt may be given to specify a time grid that is used by default when converting to a numerical pulse (
to_num_pulse()
). They may be a numerical value, which will be used directly. Alternatively, they may be a string, which is a key in the parameters dict, and the value of the corresponding parameter will be used. Lastly, they may be a callable the receives the entireAnalyticalPulse
object as its argument and returns and appropriate numerical value.-
unit_convert
= <qdyn.units.UnitConvert object>¶
-
classmethod
register_formula
(name, formula)[source]¶ Register a new analytical formula
- Parameters
name (str) – Label for the formula
formula (callable) – callable that takes an tgrid numpy array and an arbitrary number of (keyword) arguments and returns a numpy array of amplitude values
-
property
t0
¶ Time at which the pulse begins (dt/2 before the first point in the pulse), as instance of
UnitFloat
.
-
property
T
¶ Time at which the pulse ends (dt/2 after the last point in the pulse), as an instance of
UnitFloat
.None if T was given as None in initialization.
-
property
tgrid
¶ Time grid points for the numerical pulse values, as numpy array in units of
time_unit
.None if missing T, nt in initialization.
The returned time grid has
nt - 1
values, and extends fromt0 + dt/2
toT - dt/2
, matching the requirements for the tgrid argument ofPulse
.See also
states_tgrid
is the time grid of lengthnt
fromt0
toT
-
property
states_tgrid
¶ Time grid values for the states propagated under the numerical pulse values, as numpy array in units of
time_unit
.None if missing T, nt in initialization.
The returned time grid has
nt
values, and extends fromt0
toT
(inclusive).See also
attr:tgrid is the time grid for the numerical pulse values of length
nt-1
, extending fromt0 + dt/2
toT - dt/2
.
-
property
dt
¶ Time grid step, as instance of
UnitFloat
None if time grid is not defined (missing T, nt in initialization).
-
property
nt
¶ Number of time steps in the time grid between
t0
andT
, as an integer.None if nt missing in initialization.
Note that this is the length of
states_tgrid
, not oftgrid
.
-
property
w_max
¶ Maximum frequency that can be represented with the current sampling rate.
None if time grid is not defined (missing T, nt in initialization).
-
property
dw
¶ Step width in the spectrum (i.e. the spectral resolution) based on the current pulse duration, as an instance of
UnitFloat
.None if time grid is not defined (missing T, nt in initialization).
-
classmethod
from_func
(func, parameters=None, time_unit=None, ampl_unit=None, t0=0.0, T=None, nt=None, freq_unit=None, config_attribs=None)[source]¶ Instantiate directly from a callable func, without the need to register the formula first
The callable func must fulfill the same requirements as formula in
register_formula()
-
property
is_complex
¶ Is the pulse amplitude of complex type?
-
array_to_parameters
(array, keys=None)[source]¶ Unpack the given array (numpy array or regular list) into the pulse parameters. This is especially useful for optimizing parameters with the
scipy.optimize.minimize()
routine.For each key, set the value of the parameters[key] attribute by popping values from the beginning of the array. If parameters[key] is an array, pop repeatedly to set every value.
If keys is not given, all parameter keys are used, in sorted order. The array must contain exactly enough parameters, otherwise an IndexError is raised.
-
parameters_to_array
(keys=None)[source]¶ Inverse method to array_to_parameters. Returns the “packed” parameter values for the given keys as a numpy array
-
property
formula_name
¶ Name of the analytical formula that is used
-
property
evaluate_formula
¶ The callable that numerically evaluates the used formula, for arbitrary parameters (keyword arguments)
-
as_func
(allow_args=False)[source]¶ Callable that evaluates the pulse for a given time value.
If allow_args is True, the resulting function takes two parameters, t and args where t is a float for the time value at which to evaluate the pulse (in units of
time_unit
), and args is a dictionary that allows to override attr:parameters.If allow_args is False, the resulting function will only take a single parameter t, and evaluate the function for fixed
parameters
.
-
write
(filename, pretty=True)[source]¶ Write the analytical pulse to the given filename as a json data structure
-
property
header
¶ Single line summarizing the pulse. Suitable as preamble for numerical pulse
-
to_num_pulse
(tgrid=None, time_unit=None, ampl_unit=None, freq_unit=None)[source]¶ Return a
Pulse
instance that contains the corresponding numerical pulse.- Parameters
tgrid (numpy.ndarray or None) – The time grid on which to evaluate the pulse. Use
pulse_tgrid()
to generate this.
For any missing argument (None value), the corresponding attribute is used.
Returns None if tgrid is not given explicitly and no time grid was defined on initialization (arguments T, nt)