0
$\begingroup$

How to retrieve the parameters of a Q# operation? Is it possible to do such a thing at all?

$\endgroup$
3
  • $\begingroup$ This question seems similar to stackoverflow.com/questions/59022076/… - does the answer to that one help you? (I haven't tried doing that kind of thing myself so can't be sure) $\endgroup$ Feb 17, 2020 at 19:20
  • $\begingroup$ @MariiaMykhailova That answer needs more explanation, what is IQ# been mentioned there? Does it help? $\endgroup$
    – Coder
    Feb 17, 2020 at 19:31
  • 1
    $\begingroup$ IQ# is the Jupyter kernel for Q#. You can look at the source at github.com/microsoft/iqsharp. The file src\Core\OperationInfo.cs builds a list of the parameter types using reflection on the Run method of the generated class. $\endgroup$ Feb 19, 2020 at 18:37

1 Answer 1

1
$\begingroup$

You are assuming a 1-1 mapping from a Q# operation with a C# operation but it doesn't work like that. A Q# operation can have a lot more functionality than a C# class, for example, Q# offers the ability to automatically create the adjoint and controlled versions of a the operation.

As Mariia pointed out, https://stackoverflow.com/questions/59022076/how-to-get-the-type-of-a-q-operation-parameter is a very similar question and the same answer applies:

Each Q# operations generations a C# class that extends the generic class Operation<I,O>, so to figure out what the input/output parameters you can take a look at the BaseType of the operation's Type, and look at the value of the GenericTypeArguments[0] to figure out the input type.

$\endgroup$

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.