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

qibo.transpilation does not seem to allow user to define some native gates #1304

Open
mho291 opened this issue Apr 25, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@mho291
Copy link

mho291 commented Apr 25, 2024

Describe the bug
Transpilation is a crucial step to map (and potentially optimise) the user's quantum circuit to the qubit topology on the chip. While I was trying to run Qibo circuits on AWS backend devices, each with different native gates (IonQ's, Oxford Quantum Circuits, Rigetti), I found that there might be gates that are disallowed to be native gates in the transpiler.

To Reproduce
Following the example given here: https://qibo.science/qibo/stable/code-examples/advancedexamples.html#how-to-modify-the-transpiler, there are two important areas of transpilation to fulfil:

  1. Qubit topology -- I created a new function called custom_connectivity(coupling_map) that takes in a custom coupling_map. This implementation is successful.
  2. Native gates -- Customise a set of native gates. Let's follow the native gate set of Oxford Quantum Circuits, which are custom_native_gates = [gates.I, gates.RZ, gates.SX, gates.X, gates.ECR]. ('v' is also known as the sqrt-x gate). This implementation is not successful.

I encounter problems with Step 2 when trying to define gates.SX as gates that cannot be used as native. There are other gates such as gates.H, gates.X, gates.Y, gates.T, gates.CNOT, gates.ECR that cannot be used as native also.

Code to reproduce the error

# Qibo transpiler
import networkx as nx

from qibo import gates
from qibo.models import Circuit
from qibo.transpiler.pipeline import Passes, assert_transpiling
from qibo.transpiler.optimizer import Preprocessing
from qibo.transpiler.router import ShortestPaths
from qibo.transpiler.unroller import Unroller, NativeGates
from qibo.transpiler.placer import Random

# Define custom connectivity 
def custom_connectivity(coupling_map):
    graph = nx.Graph()
    for connection in coupling_map:
        q1, q2 = connection
        graph.add_edge(q1, q2)
    return graph

# Define the circuit
circuit = Circuit(2)
circuit.add(gates.H(0))
circuit.add(gates.CZ(0, 1))

# Define qubit topology and native gates
custom_coupling_map = [[0, 1], [0, 7], [1, 2], [2, 3], [4, 3], [4, 5], [6, 5], [7, 6]]
custom_native_gates = [gates.I, gates.RZ, gates.SX, gates.X, gates.ECR]

# Define custom passes as a list
custom_passes = []
# Preprocessing adds qubits in the original circuit to match the number of qubits in the chip
custom_passes.append(Preprocessing(connectivity=custom_connectivity(custom_coupling_map)))
# Placement step
custom_passes.append(Random(connectivity=custom_connectivity(custom_coupling_map)))
# Routing step
custom_passes.append(ShortestPaths(connectivity=custom_connectivity(custom_coupling_map)))
# Gate decomposition step
custom_passes.append(Unroller(native_gates=NativeGates.from_gatelist(custom_native_gates)))

# Define the general pipeline
custom_pipeline = Passes(custom_passes,
                         connectivity=custom_connectivity(custom_coupling_map),
                         native_gates=NativeGates.from_gatelist(custom_native_gates))

# Call the transpiler pipeline on the circuit
transpiled_circ, final_layout = custom_pipeline(circuit)

The error message received from running the above code is:
ValueError: Gate <class 'qibo.gates.gates.SX'> cannot be used as native.

@mho291 mho291 added the bug Something isn't working label Apr 25, 2024
@Simone-Bordoni
Copy link
Contributor

For now the transpiler (unroller step) allows to define only GPI2 or U3 as single qubit native gates (plus RZ, Z and I). We are currently thinking of a more general unrolling procedure that would allow to define different sets of single qubit gates. However, the realization of a general unroller is non trivial, we will try to find a good solution in the next months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants