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 of the constant segments.
- values (np.ndarray or Tensor) – The values 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 piecewise-constant tensors of shape , provide this values parameter as an object of shape .
- 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 batch dimensions, then time_dimension is also . Defaults to 0, which corresponds to no batch. Note that you can pass a negative value to refer to the time dimension.
- name (str or None , optional) – The name of the node.
Returns
The piecewise-constant function of time , satisfying for , where and . If you provide a batch of values, the returned Pwc represents a corresponding batch of functions , each of shape .
Return type
SEE ALSO
Graph.pwc_operator
: Create Pwc operators.
Graph.pwc_signal
: Create Pwc signals from (possibly complex) values.
Graph.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 = 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.