1
$\begingroup$

I wrote following code in QASM editor on IBM Q web interface (note ccu1 is controlled-controlled U1 gate):

OPENQASM 2.0;
include "qelib1.inc";

gate ccu1 ( p ) c1, c2, t  {
  cu1 ( p / 2 ) c1, c2;
  cx c2, t;
  cu1 ( - p / 2 ) c1, t;
  cx c2, t;
  cu1 ( p / 2 ) c1, t;
}

qreg q[4];
creg c[4];

h q[0];
h q[1];
h q[2];
h q[3];

ccu1(pi) q[0],q[1],q[2];

id q[3];
measure q[3] -> c[3];

When I look to visualization of a state vector, everything is fine. However, when I tried to run the code on simulator I got error ERROR_RUNNING_JOB. There is also a status message Error in transpilation process. [1003] on results page.

I suspect that the issue is caused by subroutine (a gate statement at the beginning of the code).

Could anyone please help me solve the issue?

Note, I know that it is possible to use subroutine in Qiskit, but I am interested in QASM.

$\endgroup$
2
$\begingroup$

I don't know if this will help. I have tried the code and it worked:

I created a new file named ccu1_circuit.qasm with the instruction written in the question. Then in a separate Python file, I have written:

from qiskit import *

circuit = QuantumCircuit.from_qasm_file('/...The path.../ccu1_circuit.qasm')

backend = BasicAer.get_backend('qasm_simulator')
print(execute(circuit, backend=backend, shots=1024).result().get_counts())

Here is the output:

{'1000': 524, '0000': 500}

Also, I noticed that when I tried to run print(circuit.qasm()) I have found ccu1 in the instructions (not its decomposition written in the .qasm file).

$\endgroup$
3
  • 1
    $\begingroup$ Thanks Davit, I know that it is not a problem in Qiskit. However, I would like to run the code in IBM Q web interface as it is more suitable for presentations etc. $\endgroup$ Apr 20 '20 at 9:50
  • $\begingroup$ Sorry, I didn't understand correctly. I tried with the web interface (Circuit Composer) and there was an ERROR_TRANSPILING_JOB (don't know why we have different errors). I tried also with different gate definitions, still, the same error. $\endgroup$ Apr 20 '20 at 10:49
  • 1
    $\begingroup$ Just solved! See below. $\endgroup$ Aug 12 '20 at 13:09
1
$\begingroup$

I have just realized that web interface of IBM Q was updated and custom gates, i.e.

gate ccu1 ( p ) c1, c2, t  {
  cu1 ( p / 2 ) c1, c2;
  cx c2, t;
  cu1 ( - p / 2 ) c1, t;
  cx c2, t;
  cu1 ( p / 2 ) c1, t;
},

is correctly transpiled to gates used in the custom gate and subsequently to basic gate set used on IBM Q.

Overall, custom gate functionality is now available in QASM.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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