1
$\begingroup$

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!

$\endgroup$

1 Answer 1

1
$\begingroup$

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);
}
$\endgroup$
1
  • $\begingroup$ Nice! I think that's exactly what I'm looking for. $\endgroup$
    – peizhao
    Apr 16, 2020 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.