constant_pwc
- Graph.constant_pwc(constant, duration, batch_dimension_count=0, *, name=None)
Create a piecewise-constant function of time that is constant over a specified duration.
- Parameters
constant (number or np.ndarray or Tensor) – The value \(c\) of the function on the constant segment. To create a batch of \(B_1 \times \ldots \times B_n\) piecewise-constant functions of shape \(D_1 \times \ldots \times D_m\), provide this constant parameter as an object of shape \(B_1\times\ldots\times B_n\times D_1\times\ldots\times D_m\).
duration (float) – The duration \(\tau\) for the resulting piecewise-constant function.
batch_dimension_count (int, optional) – The number of batch dimensions, \(n\) in constant. If provided, the first \(n\) dimensions of constant are considered batch dimensions. Defaults to 0, which corresponds to no batch.
name (str, optional) – The name of the node.
- Returns
The constant function \(f(t) = c\) (for \(0\leq t\leq\tau\)) (or a batch of constant functions, if you provide batch_dimension_count).
- Return type
See also
constant_pwc_operator
Create constant Pwc operators.
constant_stf
Corresponding operation for Stfs.
pwc
Create piecewise-constant functions.
Notes
For more information on Pwc nodes see the Working with time-dependent functions in Boulder Opal topic.
Examples
Create a batched piecewise-constant function.
>>> constant = np.arange(12).reshape((2, 2, 3)) >>> graph.constant_pwc( ... constant=constant, duration=0.1, batch_dimension_count=1, name="constant" ... ) <Pwc: name="constant", operation_name="constant_pwc", value_shape=(2, 3), batch_shape=(2,)> >>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["constant"]) >>> result.output["constant"] [ [{"value": array([[0.0, 1.0, 2.0], [3.0, 4.0, 5.0]]), "duration": 0.1}], [{"value": array([[6.0, 7.0, 8.0], [9.0, 10.0, 11.0]]), "duration": 0.1}], ]
See more examples in the Simulate the dynamics of a single qubit using computational graphs tutorial.