Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

State preparation operations for common ansatz #578

Open
cgranade opened this issue Apr 25, 2022 · 2 comments
Open

State preparation operations for common ansatz #578

cgranade opened this issue Apr 25, 2022 · 2 comments
Labels
Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. Kind-Enhancement New feature or request Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package.

Comments

@cgranade
Copy link
Contributor

Is your feature request related to a problem? Please describe.
It would be helpful in targeting some variational applications to have state preparation operations for common variational ansatz such as RyRz.

Additional context
At the moment, these ansatz can be implemented by users using existing features (see example below), but it would be nice to have "pre-canned" versions with a common signature (e.g.: (Double[], Qubit[]) => Unit is Adj + Ctl) so that it's easier to test out and compare various ansatz.

Example using current features

function Pairs<'T>(elements : 'T[]) : ('T, 'T)[] {
    mutable allPairs = [];
    for idxFirst in 0..Length(elements) - 2 {
        for idxSecond in idxFirst + 1..Length(elements) - 1 {
            set allPairs += [(elements[idxFirst], elements[idxSecond])];
        }
    }
    return allPairs;
}

operation ApplyRotationLayer(parameters : Double[], targets : Qubit[]) : Unit is Adj + Ctl {
    let yParams = parameters[...Length(parameters) / 2 - 1];
    let zParams = parameters[Length(parameters) / 2...];
    ApplyToEachCA(Ry, Zipped(yParams, targets));
    ApplyToEachCA(Rz, Zipped(zParams, targets));
}

operation ApplyEntanglingLayer(targets : Qubit[]) : Unit is Adj + Ctl {
    ApplyToEachCA(CNOT, Pairs(targets));
}

operation ApplyRyRz(parameters : Double[], targets : Qubit[]) : Unit is Adj + Ctl {
    let layers = Chunks(2 * Length(targets), parameters);
    ApplyRotationLayer(layers[0], targets);
    for layer in layers {
        ApplyEntanglingLayer(targets);
        ApplyRotationLayer(layer, targets);
    }
}
@cgranade cgranade added the Kind-Enhancement New feature or request label Apr 25, 2022
@msoeken msoeken added Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package. Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. labels Apr 26, 2022
@msoeken
Copy link
Member

msoeken commented Apr 26, 2022

Thanks for the proposal. I have a few questions:

  1. Should there be (2 + 1) * Length(targets) parameters? Currently, the first set of parameters layers[0] is passed to the first and second rotation layer.
  2. Is it the only or a common choice for the entangling layer? I have also seen ansatz implementations that use a CNOT staircase as the entangling layer.
  3. Is there a reference that explains these constructions to point to in the documentation?

@cgranade
Copy link
Contributor Author

Thanks for taking a look, @msoeken!

I think you're right about the duplicated first layer, sorry, that's what I get for writing up a quick proof of concept.

For the choice of entangling layer and rotation gates, I agree, those are often replaced by cyclic, nearest-neighbor, or other kinds of patterns, or CNOT may be replaced by CZ in some cases. It may be good to see what we can consolidate with the QML library, QAOA ansatz, or other places where parameterized families of state preparations are used to identify what the right kinds of configuration options might be.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-API Issue concerns the API design of a library, such as style guide or design principles adherence. Kind-Enhancement New feature or request Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package.
Projects
None yet
Development

No branches or pull requests

2 participants