qdyn.analytical_pulse module

Describing pulses by an analytical formula

Summary

Classes:

AnalyticalPulse

Representation of a pulse determined 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.

  • t0 (float or str or callable) – Start time of the pulse

  • 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’})

parameters

Dictionary of values for the pulse formula

Type

dict

time_unit

Value of the time_unit arg

Type

str or None

ampl_unit

Value of the ampl_unit arg

Type

str

freq_unit

Value of the freq_unit arg

Type

str

config_attribs

dictionary with the items from the config_attribs arg

Type

collections.abc.MutableMapping

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 entire AnalyticalPulse 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 from t0 + dt/2 to T - dt/2, matching the requirements for the tgrid argument of Pulse.

See also

states_tgrid is the time grid of length nt from t0 to T

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 from t0 to T (inclusive).

See also

attr:tgrid is the time grid for the numerical pulse values of length nt-1, extending from t0 + dt/2 to T - 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 and T, as an integer.

None if nt missing in initialization.

Note that this is the length of states_tgrid, not of tgrid.

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?

__eq__(other)[source]

Compare two pulses, within a precision of 1e-12

copy()[source]

Return a copy of the analytical pulse

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.

to_json(pretty=True)[source]

Return a json representation of the pulse

__str__()[source]

Return string representation (JSON)

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

classmethod read(filename)[source]

Read in a json data structure and return a new AnalyticalPulse

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.

  • time_unit (str or None) – Unit of tgrid

  • ampl_unit (str or None) – Unit of pulse amplitude

  • freq_unit (str or None) – Unit of pulse frequencies

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)