qiboteam / qibo

A framework for quantum computing
https://qibo.science
Apache License 2.0
288 stars 60 forks source link

Align is not supported by OpenQASM #1478

Open Rumoa opened 1 week ago

Rumoa commented 1 week ago

Implementation of Align matrix is not supported by OpenQASM I am trying to implement a delay gate, equivalent to the one from qiskit. Since in the documentation there is no delay gate, I thought Align could be used as it allows to add a delay as parameter function.

When trying to run a simple circuit with this gate:

from qibo import gates
from qibo.models import Circuit

from qiboconnection import API

api = API.login(username="insert_your_user_id", api_key="insert_your_api_key")

c = Circuit(1)
c.add(gates.X(0))
c.add(gates.Align(0, delay=int(1)))
c.add(gates.M(0))

job_id = api.execute(circuit=c, device_id=1)

result = api.get_job(job_id).result

the following errors appears:

[Qibo 0.2.8|ERROR|2024-10-08 12:35:57]: Align is not supported by OpenQASM

Is there any other way to implement the delay gate?

Thank you in advance

alecandido commented 1 week ago

Align is the Delay, so it's not missing. And Delay would have been even a better name for the Qibo one, since we have a lower level Align instruction which is doing something slightly different (and Delay as well, which is what the Align gate is translated to on hardware).

However, here the problem is in the QASM translation, which is not turning Align into Delay, because it's mainly matching by name. But it could be patched. @BrunoLiegiBastonLiegi can estimate how much it may take to do that.

Btw, your example is incomplete, since you're using api without defining or importing it - please, try to provide a self-consistent reproduction.

Rumoa commented 1 week ago

Thank you for the clarification. I did not include the api part in the example bc of personal info, but now it has been fixed so it can be reproduced with an actual hardware credentials.

BrunoLiegiBastonLiegi commented 1 week ago

If it's just a matter of renaming the Align in the to_qasm I can take care of that immediately.

BrunoLiegiBastonLiegi commented 1 week ago

Qiskit apparently dumps the delay as a custom operation re-defined everytime:

OPENQASM 2.0;
include "qelib1.inc";
opaque delay(param0) q0;
qreg q[1];
delay(1.0) q[0];

thus, supporting the Delay in qibo's qasm is easy, but generating a qasm string that will be accepted by qiskit is slightly trickier. @Rumoa which one is the intended use here? Do you plan to export the qasm to qiskit or is it just for sending information to another qibo driven client?

Rumoa commented 1 week ago

In my case, I plan to use it in a hardware backend that uses qibo, not qiskit compatible.

alecandido commented 1 week ago

In my case, I plan to use it in a hardware backend that uses qibo, not qiskit compatible.

Qibo does not require QASM for execution, so you can safely use Align() as it is.

The issue may be still relevant, but in principle you should be able to work with qibo-client even without that (there is a native Qibo serialization involved).

Rumoa commented 1 week ago

In that case, I guess that I should not use the api interface and use the functions from qibo client instead of using the API to connect to the device. Also, I should get the token that somehow must be related to the username and the api_key, right? Is it preferable to work with the api instead of qibo client?

Thank you for fixing the issue.

BrunoLiegiBastonLiegi commented 1 week ago

I am not sure which endpoint you are trying to connect to, but now we have the qibo-cloud-backends that automatically take care (through qibo-client) of remote circuit execution.

Rumoa commented 1 week ago

The endpoint is a quantum computer hosted at qilimanjaro, and the instructions they provide only use the api framework. I guess that I will have to ask them to see if there are other ways to connect to it via a token to use the different solutions you just pointed out.