4
$\begingroup$

I know how to create controlled versions of gates like X, Y, Z. For example, a controlled X gate would be implemented by writing

(Controlled X)([control],target);

However, I've tried numerous times to create a controlled R1 gate with no success, and there are no examples available on the Q# documentation or elsewhere on the web from what I've seen. As an example of what I've attempted, I've tried

(Controlled R1)([control],theta,target);

and get the following error:

The shape of the given tuple does not match the argument type.

From what I gather the issue is that an X gate does not require any additional parameters, whereas an angle needs to be specified for the R1 gate to be well defined.

To see the relevant documentation, please visit R1 Operation, Q# Docs, and Operations and Functions, Q# Docs.

$\endgroup$

1 Answer 1

3
$\begingroup$

If the base operation takes several arguments, you need to enclose the corresponding arguments of the controlled version of the operation in parentheses to convert them into a single tuple. In your case, you need to call it as (Controlled R1)([control], (theta, target));.

This is covered in the "Controlled" section of Q# type model documentation with Rz gate used as an example. I wonder how to make this information more discoverable...

$\endgroup$
1
  • $\begingroup$ I was looking through the Operations and Functions section of the docs which is probably why I overlooked this. Just as a suggestion, it would probably be easier if they included examples of how to use these functors on the Microsoft.Quantum.Primitive gate pages. In any event, thanks for the help. $\endgroup$
    – Alex S
    Jan 31, 2019 at 7:11

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.