CQCL / pytket-qiskit

pytket-qiskit, extensions for pytket quantum SDK
Apache License 2.0
17 stars 13 forks source link

`PlacementPass` on `SquareGrid` architecture causes RunTime Error when running on AerBackend #374

Open IlanIwumbwe opened 3 months ago

IlanIwumbwe commented 3 months ago

Benny and I found this by running a randomly generated circuit through the compiler.

Recreate with:

from pytket import Circuit
from pytket.architecture import SquareGrid
from pytket.passes import NaivePlacementPass
from pytket.extensions.qiskit import AerBackend

backend = AerBackend()

subcirc_4 = Circuit(2, "subcirc_4")

a = SquareGrid(subcirc_4.n_qubits, 1)
NaivePlacementPass(a).apply(subcirc_4)

no_pass_circ = backend.get_compiled_circuit(subcirc_4, optimisation_level=0)
counts_no_pass = backend.run_circuit(no_pass_circ, 1).get_counts()

Results in:

[q[0], q[1]]
[gridNode[0, 0, 0], gridNode[1, 0, 0]]
NotImplementedError: Qiskit registers must use a single index

This is because routing on square grid creates indices with 3 dimensions, which won't work and throw a NotImplementedError as shown here.

This also limits users from using the feature where you can define qubit indices more than one dimension.

from pytket import Circuit, Qubit
from pytket.architecture import SquareGrid
from pytket.passes import NaivePlacementPass
from pytket.extensions.qiskit import AerBackend

backend = AerBackend()

subcirc_4 = Circuit(2, "subcirc_4")

subcirc_4.add_qubit(Qubit("qw", [0, 1]))
print(subcirc_4.qubits)

no_pass_circ = backend.get_compiled_circuit(subcirc_4, optimisation_level=0)
counts_no_pass = backend.run_circuit(no_pass_circ, 1).get_counts()

Although this isn't really a RunTime error, this limitation isn't stated in documentation as far as we can tell.