3.2.5. qupulse.hardware.util¶
Functions
|
Find indices of the first occurrence of the elements of to_find in data. |
|
Calculates the sample times required for the longest waveform in waveforms and returns it together with an array of the lengths. |
|
Calculates the number of samples in a waveform |
|
|
|
Calculate lookup table from sparse to non sparse indices and the total number of not None elements |
|
Convert values of the range |
|
Potentially (if numba is installed) faster version of zhinst.utils.convert_awg_waveform |
- get_sample_times(waveforms: Collection[Waveform] | Waveform, sample_rate_in_GHz: TimeType, tolerance: float = 1e-10) Tuple[array, array][source]¶
Calculates the sample times required for the longest waveform in waveforms and returns it together with an array of the lengths.
If only one waveform is given, the number of samples has shape ()
Raises a ValueError if any waveform has a length that is zero or not a multiple of the inverse sample rate.
- Parameters:
waveforms – A waveform or a sequence of waveforms
sample_rate_in_GHz – The sample rate in GHz
tolerance – Allowed deviation from an integer sample count
- Returns:
Array of sample times sufficient for the longest waveform Number of samples of each waveform
- traced(*args, **keywords)[source]¶
Add call and return tracing to an unbound function or to the methods of a class.
The arguments to
traceddiffer depending on whether it is being used to trace an unbound function or the methods of a class:Trace an unbound function using the default logger
- Parameters:
func – the unbound function to be traced
By default, a logger named for the function’s module is used:
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced ... def func(x, y): ... return x + y ... >>> func(7, 9) TRACE:autologging:func:CALL *(7, 9) **{} TRACE:autologging:func:RETURN 16 16
Trace an unbound function using a named logger
- Parameters:
logger (logging.Logger) – the parent logger used to trace the unbound function
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced(logging.getLogger("my.channel")) ... def func(x, y): ... return x + y ... >>> func(7, 9) TRACE:my.channel:func:CALL *(7, 9) **{} TRACE:my.channel:func:RETURN 16 16
Trace default methods using the default logger
- Parameters:
class – the class whose methods will be traced
By default, all “public”, “_nonpublic”, and “__internal” methods, as well as the special “__init__” and “__call__” methods, will be traced. Tracing log entries will be written to a logger named for the module and class:
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced ... class Class: ... def __init__(self, x): ... self._x = x ... def public(self, y): ... return self._x + y ... def _nonpublic(self, y): ... return self._x - y ... def __internal(self, y=2): ... return self._x ** y ... def __repr__(self): ... return "Class(%r)" % self._x ... def __call__(self): ... return self._x ... >>> obj = Class(7) TRACE:autologging.Class:__init__:CALL *(7,) **{} >>> obj.public(9) TRACE:autologging.Class:public:CALL *(9,) **{} TRACE:autologging.Class:public:RETURN 16 16 >>> obj._nonpublic(5) TRACE:autologging.Class:_nonpublic:CALL *(5,) **{} TRACE:autologging.Class:_nonpublic:RETURN 2 2 >>> obj._Class__internal(y=3) TRACE:autologging.Class:__internal:CALL *() **{'y': 3} TRACE:autologging.Class:__internal:RETURN 343 343 >>> repr(obj) # not traced by default 'Class(7)' >>> obj() TRACE:autologging.Class:__call__:CALL *() **{} TRACE:autologging.Class:__call__:RETURN 7 7
Note
When the runtime Python version is >= 3.3, the qualified class name will be used to name the tracing logger (i.e. a nested class will write tracing log entries to a logger named “module.Parent.Nested”).
Trace default methods using a named logger
- Parameters:
logger (logging.Logger) – the parent logger used to trace the methods of the class
By default, all “public”, “_nonpublic”, and “__internal” methods, as well as the special “__init__” method, will be traced. Tracing log entries will be written to the specified logger:
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced(logging.getLogger("my.channel")) ... class Class: ... def __init__(self, x): ... self._x = x ... def public(self, y): ... return self._x + y ... def _nonpublic(self, y): ... return self._x - y ... def __internal(self, y=2): ... return self._x ** y ... def __repr__(self): ... return "Class(%r)" % self._x ... def __call__(self): ... return self._x ... >>> obj = Class(7) TRACE:my.channel.Class:__init__:CALL *(7,) **{} >>> obj.public(9) TRACE:my.channel.Class:public:CALL *(9,) **{} TRACE:my.channel.Class:public:RETURN 16 16 >>> obj._nonpublic(5) TRACE:my.channel.Class:_nonpublic:CALL *(5,) **{} TRACE:my.channel.Class:_nonpublic:RETURN 2 2 >>> obj._Class__internal(y=3) TRACE:my.channel.Class:__internal:CALL *() **{'y': 3} TRACE:my.channel.Class:__internal:RETURN 343 343 >>> repr(obj) # not traced by default 'Class(7)' >>> obj() TRACE:my.channel.Class:__call__:CALL *() **{} TRACE:my.channel.Class:__call__:RETURN 7 7
Trace specified methods using the default logger
- Parameters:
method_names (tuple) – the names of the methods that will be traced
Tracing log entries will be written to a logger named for the module and class:
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced("public", "__internal") ... class Class: ... def __init__(self, x): ... self._x = x ... def public(self, y): ... return self._x + y ... def _nonpublic(self, y): ... return self._x - y ... def __internal(self, y=2): ... return self._x ** y ... def __repr__(self): ... return "Class(%r)" % self._x ... def __call__(self): ... return self._x ... >>> obj = Class(7) >>> obj.public(9) TRACE:autologging.Class:public:CALL *(9,) **{} TRACE:autologging.Class:public:RETURN 16 16 >>> obj._nonpublic(5) 2 >>> obj._Class__internal(y=3) TRACE:autologging.Class:__internal:CALL *() **{'y': 3} TRACE:autologging.Class:__internal:RETURN 343 343 >>> repr(obj) 'Class(7)' >>> obj() 7
Warning
When method names are specified explicitly via args, Autologging ensures that each method is actually defined in the body of the class being traced. (This means that inherited methods that are not overridden are never traced, even if they are named explicitly in args.)
If a defintion for any named method is not found in the class body, either because the method is inherited or because the name is misspelled, Autologging will issue a
UserWarning.If you wish to trace a method from a super class, you have two options:
Use
tracedto decorate the super class.Override the method and trace it in the subclass.
Note
When the runtime Python version is >= 3.3, the qualified class name will be used to name the tracing logger (i.e. a nested class will write tracing log entries to a logger named “module.Parent.Nested”).
Trace specified methods using a named logger
- Parameters:
logger (logging.Logger) – the parent logger used to trace the methods of the class
method_names (tuple) – the names of the methods that will be traced
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced(logging.getLogger("my.channel"), "public", "__internal") ... class Class: ... def __init__(self, x): ... self._x = x ... def public(self, y): ... return self._x + y ... def _nonpublic(self, y): ... return self._x - y ... def __internal(self, y=2): ... return self._x ** y ... def __repr__(self): ... return "Class(%r)" % self._x ... def __call__(self): ... return self._x ... >>> obj = Class(7) >>> obj.public(9) TRACE:my.channel.Class:public:CALL *(9,) **{} TRACE:my.channel.Class:public:RETURN 16 16 >>> obj._nonpublic(5) 2 >>> obj._Class__internal(y=3) TRACE:my.channel.Class:__internal:CALL *() **{'y': 3} TRACE:my.channel.Class:__internal:RETURN 343 343 >>> repr(obj) # not traced by default 'Class(7)' >>> obj() 7
Warning
When method names are specified explicitly via args, Autologging ensures that each method is actually defined in the body of the class being traced. (This means that inherited methods that are not overridden are never traced, even if they are named explicitly in args.)
If a defintion for any named method is not found in the class body, either because the method is inherited or because the name is misspelled, Autologging will issue a
UserWarning.If you wish to trace a method from a super class, you have two options:
Use
tracedto decorate the super class.Override the method and trace it in the subclass.
Exclude specified methods from tracing
Added in version 1.3.0.
- Parameters:
method_names (tuple) – the names of the methods that will be excluded from tracing
- Keyword Arguments:
exclude (bool) –
Trueto cause the method names list to be interpreted as an exclusion list (Falseis the default, and causes the named methods to be included as described above)
The example below demonstrates exclusions using the default logger.
>>> import sys >>> logging.basicConfig( ... level=TRACE, stream=sys.stdout, ... format="%(levelname)s:%(name)s:%(funcName)s:%(message)s") >>> @traced("_nonpublic", "__internal", exclude=True) ... class Class: ... def __init__(self, x): ... self._x = x ... def public(self, y): ... return self._x + y ... def _nonpublic(self, y): ... return self._x - y ... def __internal(self, y=2): ... return self._x ** y ... def __repr__(self): ... return "Class(%r)" % self._x ... def __call__(self): ... return self._x ... >>> obj = Class(7) >>> obj.public(9) TRACE:autologging.Class:public:CALL *(9,) **{} TRACE:autologging.Class:public:RETURN 16 16 >>> obj._nonpublic(5) 2 >>> obj._Class__internal(y=3) 343 >>> repr(obj) 'Class(7)' >>> obj() TRACE:autologging.Class:__call__:CALL *() **{} TRACE:autologging.Class:__call__:RETURN 7 7
When method names are excluded via args and the exclude keyword, Autologging ignores methods that are not actually defined in the body of the class being traced.
Warning
If an exclusion list causes the list of traceable methods to resolve empty, then Autologging will issue a
UserWarning.Note
When the runtime Python version is >= 3.3, the qualified class name will be used to name the tracing logger (i.e. a nested class will write tracing log entries to a logger named “module.Parent.Nested”).
Note
When tracing a class, if the default (class-named) logger is used and the runtime Python version is >= 3.3, then the qualified class name will be used to name the tracing logger (i.e. a nested class will write tracing log entries to a logger named “module.Parent.Nested”).
Note
If method names are specified when decorating a function, a
UserWarningis issued, but the methods names are ignored and the function is traced as though the method names had not been specified.Note
Both Jython and IronPython report an “internal” class name using its mangled form, which will be reflected in the default tracing logger name.
For example, in the sample code below, both Jython and IronPython will use the default tracing logger name “autologging._Outer__Nested” (whereas CPython/PyPy/Stackless would use “autologging.__Nested” under Python 2 or “autologging.Outer.__Nested” under Python 3.3+):
class Outer: @traced class __Nested: pass
Warning
Neither Jython nor IronPython currently implement the
function.__code__.co_lnotabattribute, so the last line number of a function cannot be determined by Autologging.Changed in version 1.3.1: Due to unavoidable inconsistencies in line number tracking across Python variants (see issues/6, as of version 1.3.1 and until further notice Autologging will only record the first line number of the function being traced in all tracing CALL and RETURN records. (Note that YIELD tracing records for generator iterators will continue to record the correct line number on variants other than IronPython.)
- voltage_to_uint16(voltage: ndarray, output_amplitude: float, output_offset: float, resolution: int) ndarray[source]¶
- Convert values of the range
[output_offset - output_amplitude, output_offset + output_amplitude)
- to uint16 in the range
[0, 2**resolution)
output_offset - output_amplitude -> 0 output_offset -> 2**(resolution - 1) output_offset + output_amplitude -> 2**resolution - 1
- Parameters:
voltage – input voltage. read-only
output_amplitude – input divided by this
output_offset – is subtracted from input
resolution – Target resolution in bits (determines the output range)
- Raises:
ValueError if the voltage is out of range or the resolution is not an integer –
- Returns:
(voltage - output_offset + output_amplitude) * (2**resolution - 1) / (2*output_amplitude) as uint16
- zhinst_voltage_to_uint16(ch1: ndarray | None, ch2: ndarray | None, markers: Tuple[ndarray | None, ndarray | None, ndarray | None, ndarray | None]) ndarray[source]¶
Potentially (if numba is installed) faster version of zhinst.utils.convert_awg_waveform
- Parameters:
ch1 – Sampled data of channel 1 [-1, 1]
ch2 – Sampled data of channel 1 [-1, 1]
markers – Marker data of (ch1_front, ch1_back, ch2_front, ch2_back)
- Returns:
Interleaved data in the correct format (u16). The first bit is the sign bit so the data needs to be interpreted as i16.