Skip to content

Commit

Permalink
feat: add properties in QibolabBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
changsookim authored and alecandido committed Oct 18, 2024
1 parent 15dce6a commit 62af6c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/qibolab/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ def __init__(self, platform):
}
self.compiler = Compiler.default()

@property
def qubits(self) -> list[str | int]:
return list(self.platform.qubits.keys())

@property
def connectivity(self) -> list[tuple[str | int, str | int]]:
return list(self.platform.pairs)

@property
def natives(self) -> list[str]:
native_gates = set()
for _, q in self.platform.qubits.items():
native_gates |= {k for k, v in q.native_gates.__dict__.items() if v is not None}

for _, p in self.platform.pairs.items():
native_gates |= {k for k, v in p.native_gates.__dict__.items() if v is not None}

return list(native_gates)

def apply_gate(self, gate, state, nqubits): # pragma: no cover
raise_error(NotImplementedError, "Qibolab cannot apply gates directly.")

Expand Down
14 changes: 14 additions & 0 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ def generate_circuit_with_gate(nqubits, gate, **kwargs):
def connected_backend(connected_platform):
yield QibolabBackend(connected_platform)

def test_qubits():
backend = QibolabBackend("dummy")
assert isinstance(backend.qubits, list)
assert set(backend.qubits) == set([0, 1, 2, 3, 4])

def test_connectivity():
backend = QibolabBackend("dummy")
assert isinstance(backend.connectivity, list)
assert set(backend.connectivity) == set([(0, 2), (2, 0), (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2)])

def test_natives():
backend = QibolabBackend("dummy")
assert isinstance(backend.natives, list)
assert set(backend.natives) == set(['RX12', 'RX', 'CZ', 'iSWAP', 'MZ', 'CNOT'])

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

0 comments on commit 62af6c4

Please sign in to comment.