Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running on qw11q (with/without transpiler) #209

Open
mho291 opened this issue Dec 24, 2024 · 3 comments
Open

Running on qw11q (with/without transpiler) #209

mho291 opened this issue Dec 24, 2024 · 3 comments

Comments

@mho291
Copy link

mho291 commented Dec 24, 2024

Hi! I have been trying to run GST on qw11q. This is the code I'm using to run:

    from qibo.transpiler.optimizer import Preprocessing
    from qibo.transpiler.pipeline import Passes
    from qibo.transpiler.placer import Random
    from qibo.transpiler.router import Sabre
    from qibo.transpiler.unroller import NativeGates, Unroller
    
    # Define gate set
    target_gates = [gates.X(0)]
    # target_gates = [gates.H(0)]
    gate_set = [g.__class__ for g in target_gates]

    # define transpiler
    connectivity = ???
    transpiler = Passes(
        connectivity=connectivity,
        passes=[
            Preprocessing(),
            Random(),
            Sabre(),
            Unroller(NativeGates.default(), backend=backend),
        ],
    )

    # transpiled GST
    T_empty_1q, T_empty_2q, *T_approx_gates = GST(
        gate_set=gate_set,
        nshots=int(1e4),
        include_empty=True,
        pauli_liouville=False,
        backend=backend,
        transpiler=transpiler,
    )

An error message pops up: ValueError: invalid literal for int() with base 10: 'A1' .
Within GST, all circuits are constructed with q0 for single qubit GST and q0 + q1 for two qubit GST.
I think the error pops up because qw11q is expecting a transpiled circuit.

I have two question:

  1. Is there some way to obtain the qubit connectivity in B-line of qw11q to enable transpiler? This goes into the variable connectivity
  2. I'm using qibo.set_backend("qibolab", platform="qw11q") to set the backend. But is there a way to set the backend within backend to pass into GST?

Alternatively, if transpiler is turned off, is there a way to target specific qubits in the B-line? I'll be happy to use a modified version of the GST code that takes into account the native gates of qw11q and the connectivity. If there is an example on how to execute a Bell circuit on the B-line, I could follow that and modify the GST code myself.

Thank you so much. Wishing everyone a Merry Christmas!

@stavros11
Copy link
Member

stavros11 commented Dec 24, 2024

Thank you for reporting the issue. I have not tried to execute myself, but here is some quick feedback that could possibly help. Note that I am assuming you are using qibolab 0.1 (and the corresponding platforms) for these tests. In principle we could make it work with 0.2 as well, but is easier to focus on one version first.

  1. Is there some way to obtain the qubit connectivity in B-line of qw11q to enable transpiler? This goes into the variable connectivity

Looking at the chip schematic, it should be:

connectivity = nx.Graph([("B1", "B2"), ("B1", "B3"), ("B2", "B4"), ("B3", "B4"), ("B4", "B5")])

However, I would suggest checking with @hay-k or @HishamKazim before attempting to execute something, because the runcards on main/0.1 branch are certainly outdated and I am not sure what is the latest status regarding calibration (particularly of 2q gates).

  1. I'm using qibo.set_backend("qibolab", platform="qw11q") to set the backend. But is there a way to set the backend within backend to pass into GST?
from qibolab.backends import QibolabBackend

backend = QibolabBackend(platform="qw11q")

should work, if you prefer instantiating the backend object manually, instead of relying on qibo's GlobalBackend. I believe in that case you have to handle transpilation yourself, as there is no automatic transpiler in QibolabBackend.execute_circuit, as the automatic transpilation was only left for the GlobalBackend in the latest refactoring.

By "handle transpilation", I mean make sure that the circuits passed to execute_circuit respect the connectivity and native gates. It does not really matter if you use Qibo transpilers to achieve that, or if you manually code the circuits using only native gates. In any case, if I understand correctly, in your case the GST function is doing transpilation internally, so it should work with the QibolabBackend (non-global one).

Alternatively, if transpiler is turned off, is there a way to target specific qubits in the B-line?

Not tested by myself, but following https://qibo.science/qibo/latest/code-examples/advancedexamples.html#how-to-select-specific-hardware-qubits-for-circuit-execution it should be sufficient to do

circuit = Circuit(2, qubits=["B1", "B2"])

or setting circuit.wire_names after the circuit definition. Looking at your example, it seems that the circuits are defined and executed by Qibo internally, within the GST function, so I am afraid there is no way to do this externally as a user. You probably need to change the code within Qibo and reinstall it or use development mode.

I'll be happy to use a modified version of the GST code that takes into account the native gates of qw11q and the connectivity. If there is an example on how to execute a Bell circuit on the B-line, I could follow that and modify the GST code myself.

Since you mention the Bell experiement, we are typically running this through Qibocal, using the circuits defined in https://github.com/qiboteam/qibocal/blob/main/src/qibocal/protocols/two_qubit_interaction/chsh/circuits.py. However, in Qibocal there are some transpiler related utilities (https://github.com/qiboteam/qibocal/blob/main/src/qibocal/auto/transpile.py) which allow to deploy these circuits to the proper qubits of each platform. However, if you are not familiar with Qibocal it may actually be harder to go to that direction.

I believe for your example, it should be sufficient to specify the wire_names with the qubits you are planning to use and either

  1. Use only native gates (GPI, GPI2, RZ, CZ) when defining the circuit and don't do any transpilation, or
  2. Use any gates when defining the circuit and transpile using the Unroller only (the part that converts to native gates).

If you are interested only in single or two-qubit circuits, you should not have any connectivity constraints, as long as you select two qubits that are connected (one of the pairs mentioned above), so you could even simplify and skip the connectivity related transpilers (as a first step).

@alecandido
Copy link
Member

Thanks, @stavros11, for the detailed answer.

In general, I believe it would help to limit the amount of hypotheses if you could post the entire stack trace, instead of just the error.
Of course, we could obtain it from the script that you posted. But that's also partially incomplete (it is clearly missing at least an import and the value you used for connectivity).

To your first question, the answer is that all backends have a .connectivity attribute, which exactly contain the information about the connectivity of the whole circuit (if you want a subset, you should filter it by yourself, but I'd not recommend it).

Expanding on @stavros11's answer to your second question, you can even avoid any extra knowledge beyond that you need for set_backend() (i.e. the existence of the QibolabBackend class), and just use construct_backend() with the same parameters you would use for set_backend().

@mho291
Copy link
Author

mho291 commented Jan 3, 2025

Thank you @stavros11 and @alecandido for the information and the detailed guidance. Let me try to run a simple Bell circuit without transpilation, i.e. I manually transpile the standard H + CNOT circuit into GPI, GPI2, RZ, CZ gates and execute them. Let me give it a try and come back again.

The goal is to do gate set tomography on qw11q with its native gates eventually, so we'll go step by step. :)

Sorry for the late reply, I was clearing the year-end leave and am back now. Wishing you a fantastic 2025 ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants