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?

  • 2
    Can you not use the PRNG from a different package in the same language that QASM is written in? – AHusain Oct 7 at 23:44
  • 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? – Niel de Beaudrap Oct 8 at 11:13
  • 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.... – Daniel Vainshtein Oct 8 at 17:02
  • 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... – Daniel Vainshtein Oct 8 at 17:07
  • 1
    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/… – cnada Oct 8 at 19:02
up vote 3 down vote accepted

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.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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