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 {δtn} of the N constant segments.
- values (np.ndarray or Tensor) – The values {vn} 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×…×Bn piecewise-constant tensors of shape D1×…×Dm, provide this values parameter as an object of shape B1×…×Bn×N×D1×…×Dm.
- 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 or None , optional) – The name of the node.
Returns
The piecewise-constant function of time v(t), satisfying v(t)=vn for tn−1≤t≤tn, where t0=0 and tn=tn−1+δtn. If you provide a batch of values, the returned Pwc represents a corresponding batch of B1×…×Bn functions v(t), each of shape D1×…×Dm.
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.