Graph.discretize_stf(stf, duration, segment_count, sample_count_per_segment=1, *, name=None)

Create a piecewise-constant function by discretizing a sampleable function.

Use this function to create a piecewise-constant approximation to a sampleable function (obtained, for example, by filtering an initial piecewise-constant function).


  • stf (Stf) – The sampleable function v(t)v(t)
  • duration (float) – The duration τ\tau
  • segment_count (int) – The number of segments NN
  • sample_count_per_segment (int , optional) – The number of samples MM
  • name (str or None , optional) – The name of the node.


The piecewise-constant function w(t)w(t)

Return type



Graph.convolve_pwc : Create an Stf by convolving a Pwc with a kernel.

Graph.filter_and_resample_pwc : Filter a Pwc with a sinc filter and resample it.

Graph.identity_stf : Create an Stf representing the identity function.

Graph.sample_stf : Sample an Stf at given times.


The resulting function w(t)w(t) is piecewise-constant with NN segments, meaning it has segment values {wn}\{w_n\} such that w(t)=wnw(t)=w_n for tn1ttnt_{n-1}\leq t\leq t_n, where tn=nτ/Nt_n= n \tau/N

Each segment value wnw_n is the average of samples of v(t)v(t) at the midpoints of MM equally sized subsegments between tn1t_{n-1} and tnt_n

wn=1Mm=1Mv(tn1+(m12)τMN). w_n = \frac{1}{M} \sum_{m=1}^M v\left(t_{n-1} + \left(m-\tfrac{1}{2}\right) \frac{\tau}{MN} \right).

For more information on Stf nodes see the Working with time-dependent functions in Boulder Opal topic.


Create discretized Gaussian signal.

>>> times = graph.identity_stf()
>>> gaussian_signal = graph.exp(- (times - 5e-6) ** 2 / 2e-6 ** 2) / 2e-6
>>> discretized_gamma_signal = graph.discretize_stf(
...     stf=gaussian_signal, duration=10e-6, segment_count=256, name="gamma"
... )
>>> discretized_gamma_signal
<Pwc: name="gamma", operation_name="discretize_stf", value_shape=(), batch_shape=()>

Refer to the How to create dephasing and amplitude robust single-qubit gates user guide to find the example in context.

Was this useful?