1

Problem

Apply a global phase -1 to all qubits x : Qubit[].

My solution

ApplyToEach(R, PauliI, 2.0 * PI(), x)

However this yields a syntax error.

From the ApplyToEach doc, it works if the operation has no parameters:

using (register = Qubit[3]) {
    ApplyToEach(H, register);
}

Thank you for your expertise. Happy qubitting!

peizhao
  • 113
  • 4

1 Answers1

1

You need to use partial application to specify the rest of the parameters passed to the R gate. The result of partial application will be a gate that takes a single qubit as an argument, and ApplyToEach will be able to apply it to each element of the array:

using (register = Qubit[3]) {
    let globalPhaseGate = R(PauliI, 2.0 * PI(), _);
    ApplyToEach(globalPhaseGate, qs);
}

You can also write this shorter, without using an extra constant to name the gate that is the result of partial application:

using (register = Qubit[3]) {
    ApplyToEach(R(PauliI, 2.0 * PI(), _), register);
}
Mariia Mykhailova
  • 9,010
  • 1
  • 12
  • 39