Skip to content

Commit

Permalink
fix: remove platform.wire_names
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim authored and alecandido committed Oct 28, 2024
1 parent 5945732 commit 06ece97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import deque
from typing import Union

import numpy as np
from qibo import __version__ as qibo_version
Expand All @@ -11,7 +12,6 @@
from qibolab.execution_parameters import ExecutionParameters
from qibolab.platform import Platform, create_platform
from qibolab.platform.load import available_platforms
from qibolab.qubits import QubitId, QubitPairId
from qibolab.version import __version__ as qibolab_version


Expand Down Expand Up @@ -52,12 +52,12 @@ def __init__(self, platform):
self.compiler = Compiler.default()

@property
def qubits(self) -> list[QubitId]:
def qubits(self) -> list[Union[str, int]]:
"""Returns the qubits in the platform."""
return list(self.platform.qubits)

@property
def connectivity(self) -> list[QubitPairId]:
def connectivity(self) -> list[tuple[Union[str, int], Union[str, int]]]:
"""Returns the list of connected qubits."""
return list(self.platform.pairs)

Expand Down Expand Up @@ -125,6 +125,16 @@ def execute_circuit(self, circuit, initial_state=None, nshots=1000):
"Hardware backend only supports circuits as initial states.",
)

if not all(q in circuit.wire_names for q in self.platform.qubits):
# This should be done in qibo side
# raise_error(
# ValueError,
# "Circuit qubits do not match the platform qubits.",
# )

# Temporary fix: overwrite the wire names
circuit._wire_names = self.qubits

sequence, measurement_map = self.compiler.compile(circuit, self.platform)

if not self.platform.is_connected:
Expand Down
11 changes: 4 additions & 7 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def test_natives():

def test_natives_no_cz_cnot():
platform = create_platform("dummy")
for p in platform.pairs:
platform.pairs[p].native_gates.CZ = None
platform.pairs[p].native_gates.CNOT = None

backend = QibolabBackend(platform)
assert set(backend.natives) == {
"I",
Expand All @@ -72,15 +76,8 @@ def test_natives_no_cz_cnot():
"GPI2",
"GPI",
"M",
"CZ",
"CNOT",
}

for gate in ["CZ", "CNOT"]:
for p in platform.pairs:
setattr(platform.pairs[p].native_gates, gate, None)
assert gate not in set(backend.natives)


def test_execute_circuit_initial_state():
backend = QibolabBackend("dummy")
Expand Down

0 comments on commit 06ece97

Please sign in to comment.