2
$\begingroup$

I want to make an operator:

$\mathrm{U3}(\arccos(\sqrt p),0,0)$, when $p$ is a random value between $0$ and $1$

How do I write code in QASM language of this "random $\mathrm{U3}$" operator?

$\endgroup$
5
  • 2
    $\begingroup$ Can you not use the PRNG from a different package in the same language that QASM is written in? $\endgroup$
    – AHusain
    Oct 7, 2018 at 23:44
  • $\begingroup$ Do you want to have a random and unknown gate of this sort for a uniformly distributed $p$, which amounts to a $Y$ rotation by a random angle between $0$ and $\pi/2$ with some particular non-uniform distribution? $\endgroup$ Oct 8, 2018 at 11:13
  • $\begingroup$ I want just that it will be U3, and p will be random as I write above. I know how to write this one in qiskit language but I have problem in writing this random U3 in Qasm. I want to run some code that include this random operator and a algorithm that I know how to program only in Qasm language.... $\endgroup$ Oct 8, 2018 at 17:02
  • $\begingroup$ for example I use the random operation in qiskit, the random is coming from the python language as the qiskit is just an extantion of python basic gates and operations... $\endgroup$ Oct 8, 2018 at 17:07
  • 1
    $\begingroup$ QASM is a very low level language and it is not possible to do so (instructions are determined when submitted). Your only way is just to generate QASM files and use another tool with a random generator. You finally just write your QASM file with the random p generated. You can look also at this code for a random QASM generator : github.com/Qiskit/qiskit-terra/blob/master/tools/… $\endgroup$
    – cnada
    Oct 8, 2018 at 19:02

1 Answer 1

3
$\begingroup$

There are many forms of QASM, so I'll answer for OpenQASM 2.0, as is currently used by IBM.

Declaring a gate to be random means that it would be randomly generated at compile time. Since QASM is used as an expression of a compiled circuit, such randomness must be resolved by the time the QASM is created.

It is true that are transpilation processes in the IBM stack, which convert a user generated QASM into one optimized for the needs of a given device. This could allow for the functionality your desire to be built into future versions. But I doubt that will be the case. It is much easier just to use randomness when generating the QASM, such as with Pythons random number generation when creating circuits with Qiskit.

Disclaimer: I work for IBM.

$\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.