Skip to content

Result Stream

ResultStream

qm.qua._dsl.stream_processing.stream_processing.ResultStream

add

add(
    other: Union[ResultStream, OneOrMore[Number]],
) -> BinaryOperation

Allows addition between streams. The addition is done element-wise. Can also be performed on buffers and other operators, but they must have the same dimensions.

PARAMETER DESCRIPTION
other

the stream, scalar or vector to add to this stream.

TYPE: Union[ResultStream, OneOrMore[Number]]

RETURNS DESCRIPTION
BinaryOperation

A new stream object emitting the element-wise sum.

Example
i = declare(int)
j = declare(int)
k = declare(int, value=5)
stream = declare_output_stream()
stream2 = declare_output_stream()
stream3 = declare_output_stream()
with for_(j, 0, j < 30, j + 1):
    with for_(i, 0, i < 10, i + 1):
        save(i, stream)
        save(j, stream2)
        save(k, stream3)

with stream_processing():
    (stream1 + stream2 + stream3).save_all("example1")
    (stream1.buffer(10) + stream2.buffer(10) + stream3.buffer(10)).save_all("example2")
    (stream1 + stream2 + stream3).buffer(10).average().save("example3")

average

average() -> UnaryMathOperation

Perform a running average on a stream item. The Output of this operation is the running average of the values in the stream starting from the beginning of the QUA program.

RETURNS DESCRIPTION
UnaryMathOperation

A new stream object emitting the running average of the input stream.

boolean_to_int

boolean_to_int() -> MapOfStream

converts boolean to an integer number - 1 for true and 0 for false

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting integers (1 for true, 0 for false).

buffer

buffer(*args: int) -> BufferOfStream

Gather items into vectors - creates an array of input stream items and outputs the array as one item. only outputs full buffers.

Note

The order of resulting dimensions is different when using a buffer with multiple inputs compared to using multiple buffers. The following two lines are equivalent:

stream.buffer(n, l, k)
stream.buffer(k).buffer(l).buffer(n)

PARAMETER DESCRIPTION
*args

number of items to gather, can either be a single number, which gives the results as a 1d array or multiple numbers for a multidimensional array.

TYPE: int DEFAULT: ()

RETURNS DESCRIPTION
BufferOfStream

A new stream object emitting the gathered items as buffers.

buffer_and_skip

buffer_and_skip(
    length: Number, skip: Number
) -> SkippedBufferOfStream

Gather items into vectors - creates an array of input stream items and outputs the array as one item. Skips the number of given elements. Note that length and skip start from the same index, so the buffer(n) command is equivalent to buffer_and_skip(n, n).

Only outputs full buffers.

Example
# The stream input is [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
with stream_processing():
    stream.buffer(3).save_all("example1")
    stream.buffer_and_skip(3, 3).save_all("example2")
    stream.buffer_and_skip(3, 2).save_all("example3")
    stream.buffer_and_skip(3, 5).save_all("example4")
# example1 -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# example2 -> [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# example3 -> [[1, 2, 3], [3, 4, 5], [5, 6, 7], [7, 8, 9]]
# example4 -> [[1, 2, 3], [6, 7, 8]]
PARAMETER DESCRIPTION
length

number of items to gather

TYPE: Number

skip

number of items to skip for each buffer, starting from the same index as length

TYPE: Number

RETURNS DESCRIPTION
SkippedBufferOfStream

A new stream object emitting the gathered buffers with the given skip.

convolution

convolution(
    constant_vector: Sequence[Number],
    mode: Optional[ConvolutionMode] = "",
) -> MapOfStream

Computes discrete, linear convolution of one-dimensional constant vector and one-dimensional vector item of the input stream.

PARAMETER DESCRIPTION
constant_vector

vector of numbers

TYPE: Sequence[Number]

mode

"full", "same" or "valid"

TYPE: Optional[ConvolutionMode] DEFAULT: ''

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the convolution of each item with the constant vector.

divide

divide(
    other: Union[ResultStream, OneOrMore[Number]],
) -> BinaryOperation

Allows division between streams. The division is done element-wise. Can also be performed on buffers and other operators, but they must have the same dimensions.

PARAMETER DESCRIPTION
other

the stream, scalar or vector to divide this stream by.

TYPE: Union[ResultStream, OneOrMore[Number]]

RETURNS DESCRIPTION
BinaryOperation

A new stream object emitting the element-wise quotient.

Example
i = declare(int)
j = declare(int)
k = declare(int, value=5)
stream = declare_output_stream()
stream2 = declare_output_stream()
stream3 = declare_output_stream()
with for_(j, 0, j < 30, j + 1):
    with for_(i, 0, i < 10, i + 1):
        save(i, stream)
        save(j, stream2)
        save(k, stream3)

with stream_processing():
    (stream1 / stream2 / stream3).save_all("example1")
    (stream1.buffer(10) / stream2.buffer(10) / stream3.buffer(10)).save_all("example2")
    (stream1 / stream2 / stream3).buffer(10).average().save("example3")

dot_product

dot_product(vector: Sequence[Number]) -> MapOfStream

Computes dot product of the given vector and each item of the input stream

PARAMETER DESCRIPTION
vector

constant vector of numbers

TYPE: Sequence[Number]

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the dot product of each item with the vector.

fft

fft(output: Optional[str] = None) -> MapOfStream

Computes one-dimensional discrete fourier transform for every item in the stream. Item can be a vector of numbers, in this case fft will assume all imaginary numbers are 0. Item can also be a vector of number pairs - in this case for each pair - the first will be real and second imaginary.

PARAMETER DESCRIPTION
output

supported from QOP 1.30 and QOP 2.0, options are "normal", "abs" and "angle":

  • "normal" - Same as default (none), returns a 2d array of size Nx2, where N is the length of the original vector. The first item in each pair is the real part, and the 2nd is the imaginary part.
  • "abs" - Returns a 1d array of size N with the abs of the fft.
  • "angle" - Returns the angle between the imaginary and real parts in radians.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
MapOfStream

stream object

flatten

flatten() -> UnaryMathOperation

Deconstruct an array item - and send its elements one by one as items

RETURNS DESCRIPTION
UnaryMathOperation

A new stream object emitting the deconstructed array elements one by one.

histogram

histogram(bins: List[List[Number]]) -> HistogramStream

Compute the histogram of all items in stream

PARAMETER DESCRIPTION
bins

vector or pairs. each pair indicates the edge of each bin. example: [[1,10],[11,20]] - two bins, one between 1 and 10, second between 11 and 20

TYPE: List[List[Number]]

RETURNS DESCRIPTION
HistogramStream

A new stream object emitting the histogram of all items.

map

map(function: FunctionBase) -> MapOfStream

Transform the item by applying a function to it

PARAMETER DESCRIPTION
function

a function to transform each item to a different item. For example, to compute an average between elements in a buffer you should write ".buffer(len).map(FUNCTIONS.average())"

TYPE: FunctionBase

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the transformed items.

multiply

multiply(
    other: Union[ResultStream, OneOrMore[Number]],
) -> BinaryOperation

Allows multiplication between streams. The multiplication is done element-wise. Can also be performed on buffers and other operators, but they must have the same dimensions.

PARAMETER DESCRIPTION
other

the stream, scalar or vector to multiply this stream by.

TYPE: Union[ResultStream, OneOrMore[Number]]

RETURNS DESCRIPTION
BinaryOperation

A new stream object emitting the element-wise product.

Example
i = declare(int)
j = declare(int)
k = declare(int, value=5)
stream = declare_output_stream()
stream2 = declare_output_stream()
stream3 = declare_output_stream()
with for_(j, 0, j < 30, j + 1):
    with for_(i, 0, i < 10, i + 1):
        save(i, stream)
        save(j, stream2)
        save(k, stream3)

with stream_processing():
    (stream1 * stream2 * stream3).save_all("example1")
    (stream1.buffer(10) * stream2.buffer(10) * stream3.buffer(10)).save_all("example2")
    (stream1 * stream2 * stream3).buffer(10).average().save("example3")

multiply_by

multiply_by(
    scalar_or_vector: OneOrMore[Number],
) -> MapOfStream

Multiply the input stream item by a constant scalar or vector. The input item can be either scalar or vector.

PARAMETER DESCRIPTION
scalar_or_vector

either a scalar number, or a vector of scalars.

TYPE: OneOrMore[Number]

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting each item multiplied by the scalar or vector.

save

save(tag: str) -> None

Save only the last item received in stream

PARAMETER DESCRIPTION
tag

result name

TYPE: str

save_all

save_all(tag: str) -> None

Save all items received in stream.

PARAMETER DESCRIPTION
tag

result name

TYPE: str

skip

skip(length: Number) -> DiscardedStream

Suppress the first n items of the stream

PARAMETER DESCRIPTION
length

number of items to skip

TYPE: Number

RETURNS DESCRIPTION
DiscardedStream

A new stream object with the first n items suppressed.

skip_last

skip_last(length: Number) -> DiscardedStream

Suppress the last n items of the stream

PARAMETER DESCRIPTION
length

number of items to skip

TYPE: Number

RETURNS DESCRIPTION
DiscardedStream

A new stream object with the last n items suppressed.

subtract

subtract(
    other: Union[ResultStream, OneOrMore[Number]],
) -> BinaryOperation

Allows subtraction between streams. The subtraction is done element-wise. Can also be performed on buffers and other operators, but they must have the same dimensions.

PARAMETER DESCRIPTION
other

the stream, scalar or vector to subtract from this stream.

TYPE: Union[ResultStream, OneOrMore[Number]]

RETURNS DESCRIPTION
BinaryOperation

A new stream object emitting the element-wise difference.

Example
i = declare(int)
j = declare(int)
k = declare(int, value=5)
stream = declare_output_stream()
stream2 = declare_output_stream()
stream3 = declare_output_stream()
with for_(j, 0, j < 30, j + 1):
    with for_(i, 0, i < 10, i + 1):
        save(i, stream)
        save(j, stream2)
        save(k, stream3)

with stream_processing():
    (stream1 - stream2 - stream3).save_all("example1")
    (stream1.buffer(10) - stream2.buffer(10) - stream3.buffer(10)).save_all("example2")
    (stream1 - stream2 - stream3).buffer(10).average().save("example3")

take

take(length: Number) -> DiscardedStream

Outputs only the first n items of the stream

PARAMETER DESCRIPTION
length

number of items to take

TYPE: Number

RETURNS DESCRIPTION
DiscardedStream

A new stream object emitting only the first n items.

tuple_convolution

tuple_convolution(
    mode: Optional[ConvolutionMode] = "",
) -> MapOfStream

Computes discrete, linear convolution of two one-dimensional vectors that received as the one item from the input stream

PARAMETER DESCRIPTION
mode

"full", "same" or "valid"

TYPE: Optional[ConvolutionMode] DEFAULT: ''

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the convolution of the two vectors in each item.

tuple_dot_product

tuple_dot_product() -> MapOfStream

Computes dot product of the given item of the input stream - that should include two vectors

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the dot product of the two vectors in each item.

tuple_multiply

tuple_multiply() -> MapOfStream

Computes multiplication of the given item of the input stream - that can be any combination of scalar and vectors.

RETURNS DESCRIPTION
MapOfStream

A new stream object emitting the multiplication of the items in each tuple.

zip

zip(other: ResultStream) -> BinaryOperation

Combine the emissions of two streams to one item that is a tuple of items of input streams

PARAMETER DESCRIPTION
other

second stream to combine with self

TYPE: ResultStream

RETURNS DESCRIPTION
BinaryOperation

A new stream object emitting tuples of the items of both streams.

MapFunctions

qm.qua._dsl.stream_processing.map_functions.map_functions.MapFunctions

average staticmethod

average(
    axis: Optional[OneOrMore[Number]] = None,
) -> Average

Perform a running average on a stream item. The Output of this operation is the running average of the values in the stream starting from the beginning of the QUA program.

PARAMETER DESCRIPTION
axis

optional Axis or axes along which to average.

TYPE: Optional[OneOrMore[Number]] DEFAULT: None

RETURNS DESCRIPTION
Average

stream object

boolean_to_int staticmethod

boolean_to_int() -> BooleanToInt

Converts boolean to integer number - 1 for true and 0 for false

RETURNS DESCRIPTION
BooleanToInt

stream object

convolution staticmethod

convolution(
    constant_vector: Sequence[Number],
    mode: Optional[ConvolutionMode] = "",
) -> Convolution

Computes discrete, linear convolution of one-dimensional constant vector and one-dimensional vector item of the input stream.

PARAMETER DESCRIPTION
constant_vector

vector of numbers

TYPE: Sequence[Number]

mode

"full", "same" or "valid"

TYPE: Optional[ConvolutionMode] DEFAULT: ''

RETURNS DESCRIPTION
Convolution

stream object

demod staticmethod

demod(
    frequency: Number,
    iw_cos: OneOrMore[Number],
    iw_sin: OneOrMore[Number],
    *,
    integrate: Optional[bool] = None
) -> Demod

Demodulates the acquired data from the indicated stream at the given frequency and integration weights. If operating on a stream of tuples, assumes that the 2nd item is the timestamps and uses them for the demodulation, reproducing the demodulation performed in real time. If operated on a single stream, assumes that the first item is at time zero and that the elements are separated by 1ns.

PARAMETER DESCRIPTION
frequency

frequency for demodulation calculation

TYPE: Number

iw_cos

cosine integration weight. Integration weight can be either a scalar for constant integration weight, or a python iterable for arbitrary integration weights.

TYPE: OneOrMore[Number]

iw_sin

sine integration weight. Integration weight can be either a scalar for constant integration weight, or a python iterable for arbitrary integration weights.

TYPE: OneOrMore[Number]

integrate

sum the demodulation result and returns a scalar if True (default), else the demodulated stream without summation is returned

TYPE: Optional[bool] DEFAULT: None

RETURNS DESCRIPTION
Demod

stream object

Example
with stream_processing():
    adc_stream.input1().with_timestamps().map(FUNCTIONS.demod(freq, 1.0, 0.0, integrate=False)).average().save('cos_env')
    adc_stream.input1().with_timestamps().map(FUNCTIONS.demod(freq, 1.0, 0.0)).average().save('cos_result')  # Default is integrate=True
Note

The demodulation in the stream processing does not take in consideration any real-time modifications to the frame, phase or frequency of the element. If the program has any QUA command that changes them, the result of the stream processing demodulation will be invalid.

dot_product staticmethod

dot_product(vector: Sequence[Number]) -> DotProduct

Computes dot product of the given vector and an item of the input stream

PARAMETER DESCRIPTION
vector

constant vector of numbers

TYPE: Sequence[Number]

RETURNS DESCRIPTION
DotProduct

stream object

fft staticmethod

fft(output: Optional[str] = None) -> FFT

Computes one-dimensional discrete fourier transform for every item in the stream. Item can be a vector of numbers, in this case fft will assume all imaginary numbers are 0. Item can also be a vector of number pairs - in this case for each pair - the first will be real and second imaginary.

PARAMETER DESCRIPTION
output

supported from QOP 1.30 and QOP 2.0, options are "normal", "abs" and "angle":

  • "normal" - Same as default (none), returns a 2d array of size Nx2, where N is the length of the original vector. The first item in each pair is the real part, and the 2nd is the imaginary part.
  • "abs" - Returns a 1d array of size N with the abs of the fft.
  • "angle" - Returns the angle between the imaginary and real parts in radians.

TYPE: Optional[str] DEFAULT: None

RETURNS DESCRIPTION
FFT

stream object

multiply_by staticmethod

multiply_by(
    scalar_or_vector: OneOrMore[Number],
) -> Union[MultiplyByVector, MultiplyByScalar]

Multiply the input stream item by a constant scalar or vector. the input item can be either scalar or vector.

PARAMETER DESCRIPTION
scalar_or_vector

either a scalar number, or a vector of scalars.

TYPE: OneOrMore[Number]

RETURNS DESCRIPTION
Union[MultiplyByVector, MultiplyByScalar]

stream object

tuple_convolution staticmethod

tuple_convolution(
    mode: Optional[ConvolutionMode] = "",
) -> TupleConvolution

Computes discrete, linear convolution of two one-dimensional vectors of the input stream

PARAMETER DESCRIPTION
mode

"full", "same" or "valid"

TYPE: Optional[ConvolutionMode] DEFAULT: ''

RETURNS DESCRIPTION
TupleConvolution

stream object

tuple_dot_product staticmethod

tuple_dot_product() -> TupleDotProduct

Computes dot product between the two vectors of the input stream

RETURNS DESCRIPTION
TupleDotProduct

stream object

tuple_multiply staticmethod

tuple_multiply() -> TupleMultiply

Computes multiplication between the two elements of the input stream. Can be any combination of scalar and vectors.

RETURNS DESCRIPTION
TupleMultiply

stream object

ResultStreamSource

qm.qua.type_hints.ResultStreamSource

ResultStreamSource(configuration: _Configuration)

A python object representing a source of values that can be processed in a stream_processing() pipeline

This interface is chainable, which means that calling most methods on this object will create a new streaming source

See the base class ResultStream for operations

auto_reshape

auto_reshape() -> ResultStreamSource

Creates a buffer with dimensions according to the program structure in QUA.

For example, when running the following program the result "reshaped" will have shape of (30,10):

RETURNS DESCRIPTION
ResultStreamSource

A new stream source buffered according to the QUA program structure.

Example
i = declare(int)
j = declare(int)
stream = declare_output_stream()
with for_(i, 0, i < 30, i + 1):
    with for_(j, 0, j < 10, j + 1):
        save(i, stream)

with stream_processing():
    stream.auto_reshape().save_all("reshaped")

input1

input1() -> ResultStreamSource

A stream of raw ADC data from input 1. Only relevant when saving data from measure statement.

RETURNS DESCRIPTION
ResultStreamSource

A new stream source emitting the raw ADC data from input 1.

input2

input2() -> ResultStreamSource

A stream of raw ADC data from input 2. Only relevant when saving data from measure statement.

RETURNS DESCRIPTION
ResultStreamSource

A new stream source emitting the raw ADC data from input 2.

timestamps

timestamps() -> ResultStreamSource

Get a stream with only the timestamps of the stream-items.

Deprecated since 1.2.3; will be removed in 2.0.0. Use with_timestamps() instead.

RETURNS DESCRIPTION
ResultStreamSource

A new stream source emitting only the timestamps of the stream-items.

with_timestamps

with_timestamps() -> ResultStreamSource

Get a stream with the relevant timestamp for each stream-item

RETURNS DESCRIPTION
ResultStreamSource

A new stream source emitting each value alongside its timestamp.