-
Notifications
You must be signed in to change notification settings - Fork 179
Windowed unitary application #602
Description
Proposal title
Windowed Unitary application
Conceptual overview
Addition of a function to apply unitary operations windowed. Windowed operations occur in many quantum algorithms and operations. This proposal proposes a wrapper that will allow windowing of operations with dedicated target qubits to make code more semantic and to provide new users easier ways to implement such operations.
Current status
Currently there is support for creating windows on Arrays, i.e., diving them into chunks of a specific size but no support for windowing operations. So to window an operation requires manually splitting an array and applying the operation over it.
User feedback
N/A
Child issues
N/A
Proposal
New and modified functions, operations, and UDTs
In namespace Microsoft.Quantum.Arrays:
/// # Summary
/// Applies an operation windowing over input but with constant target qubits.
///
/// # Input
/// ## windowLen
/// The size of each window
/// ## op
/// An operation with three arguments, one index, controls, and target. When applied it will be supplied with a windowed component of the `qubits` parameter, the `target` qubits (constant) and an index of the window
/// ## qubits
/// The qubits the operation windows over
/// ## target
/// The target provided to each windowed operation
operation ApplyWindowed(windowLen : Int, op : (Int, Qubit[], Qubit[]) => Unit, qubits : Qubit[], target : Qubit[]) : UnitModifications to style guide
N/A
Impact of breaking changes
N/A
Examples
Current status
Currently the most efficient solution is to inline op in the following:
let windows = Windows(windowLen, qubits); // Create windows of non-target qubits
for (i, window) in Enumerated(windows) { op(argumentTransform(i), window, target);
}Using proposed changes
Given this function is mainly a convivence wrapper it would merely involve the single function call.
Relationship to Q# language feature proposals
N/A
Alternatives considered
An alternative would be to include an explicit transformation of the index, however this can be encapsulated in op
/// # Summary
/// Applies an operation windowing over input but with constant target qubits.
///
/// # Input
/// ## windowLen
/// The size of each window
/// ## op
/// An operation with three arguments, one arbitrary, controls, and target. When applied it will be supplied with a windowed component of the `qubits` parameter, the `target` qubits (constant) and an arbitary parameter stemming from the `argumentTransform` mapping supplied.
/// ## argumentTransform
/// Transforms an integer into the arbitary argument for op. This function will be provide with the indices of the windows. This means the function need to work correctly for $[0, n[$, where $n$ is the number of windows.
/// ## qubits
/// The qubits the operation windows over
/// ## target
/// The targer provided to each windowed operation
/// # Type Parameters
/// ## 'T
/// Any type that the operation can use as parametrization
operation ApplyWindowed<'T>(windowLen : Int, op : ('T, Qubit[], Qubit[]) => Unit, argumentTransform : Int -> 'T, qubits : Qubit[], target : Qubit[]) : UnitOpen design questions and considerations
N/A