pwc

Graph.pwc(durations, values, time_dimension=0, *, name=None)

Create a piecewise-constant function of time.

Parameters
  • durations (np.ndarray (1D, real)) – The durations \(\{\delta t_n\}\) of the \(N\) constant segments.

  • values (np.ndarray or Tensor) – The values \(\{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 \(B_1 \times \ldots \times B_n\) piecewise-constant tensors of shape \(D_1 \times \ldots \times D_m\), provide this values parameter as an object of shape \(B_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 \(n\) batch dimensions, then time_dimension is also \(n\). Defaults to 0, which corresponds to no batch. Note that you can pass a negative value to refer to the time dimension.

  • name (str, optional) – The name of the node.

Returns

The piecewise-constant function of time \(v(t)\), satisfying \(v(t)=v_n\) for \(t_{n-1}\leq t\leq t_n\), where \(t_0=0\) and \(t_n=t_{n-1}+\delta t_n\). If you provide a batch of values, the returned Pwc represents a corresponding batch of \(B_1 \times \ldots \times B_n\) functions \(v(t)\), each of shape \(D_1 \times \ldots \times D_m\).

Return type

Pwc

See also

pwc_operator

Create Pwc operators.

pwc_signal

Create Pwc signals from (possibly complex) values.

pwc_sum

Sum multiple Pwcs.

Notes

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

Examples

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

>>> omega = graph.pwc(
...     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.name = "hamiltonian"
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["hamiltonian"])
>>> result.output["hamiltonian"]
[
    {"value": array([[1.0, 0.0], [0.0, -1.0]]), "duration": 0.1},
    {"value": array([[2.0, 0.0], [0.0, -2.0]]), "duration": 0.2},
    {"value": array([[3.0, 0.0], [0.0, -3.0]]), "duration": 0.3},
]

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