pwc, values, time_dimension=0, *, name=None)

Create a piecewise-constant function of time.


  • durations (np.ndarray ( 1D , real )) – The durations {δtn}\{\delta t_n\} of the NN
  • values (np.ndarray or Tensor) – The values {vn}\{v_n\} of the function on the constant segments. The dimension corresponding to time_dimension must be the same length as durations. To create a batch of B1××BnB_1 \times \ldots \times B_n piecewise-constant tensors of shape D1××DmD_1 \times \ldots \times D_m, provide this values parameter as an object of shape B1××Bn×N×D1××DmB_1\times\ldots\times B_n\times N\times D_1\times\ldots\times D_m
  • time_dimension (int , optional) – The axis along values corresponding to time. All dimensions that come before the time_dimension are batch dimensions: if there are nn batch dimensions, then time_dimension is also nn
  • name (str or None , optional) – The name of the node.


The piecewise-constant function of time v(t)v(t), satisfying v(t)=vnv(t)=v_n for tn1ttnt_{n-1}\leq t\leq t_n, where t0=0t_0=0 and tn=tn1+δtnt_n=t_{n-1}+\delta t_n. If you provide a batch of values, the returned Pwc represents a corresponding batch of B1××BnB_1 \times \ldots \times B_n functions v(t)v(t), each of shape D1××DmD_1 \times \ldots \times D_m

Return type



Graph.pwc_operator : Create Pwc operators.

Graph.pwc_signal : Create Pwc signals from (possibly complex) values.

Graph.pwc_sum : Sum multiple Pwcs.


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


Create a Hamiltonian from a piecewise-constant signal with non-uniform segment durations.

>>> omega =
...     values=np.array([1, 2, 3]), durations=np.array([0.1, 0.2, 0.3]), name="omega"
... )
>>> omega
<Pwc: name="omega", operation_name="pwc", value_shape=(), batch_shape=()>
>>> sigma_z = np.array([[1, 0], [0, -1]])
>>> hamiltonian = omega * sigma_z
>>> = "hamiltonian"
>>> result = bo.execute_graph(graph=graph, output_node_names="hamiltonian")
>>> result["output"]["hamiltonian"]
    'durations': array([0.1, 0.2, 0.3]),
    'values': array([
        [[ 1.,  0.], [ 0., -1.]],
        [[ 2.,  0.], [ 0., -2.]],
        [[ 3.,  0.], [ 0., -3.]]
    'time_dimension': 0

See more examples in the How to simulate quantum dynamics subject to noise with graphs user guide.

Was this useful?