Skip to content

Commit

Permalink
created IQM_SCHEMA (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-qc authored Jul 5, 2024
1 parent 7eead9f commit 107c4da
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
66 changes: 56 additions & 10 deletions pytket/extensions/braket/backends/braket.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
"name": "braket.device_schema.oqc.oqc_provider_properties",
"version": "1",
}
IQM_SCHEMA = {
"name": "braket.device_schema.iqm.iqm_provider_properties",
"version": "1",
}

_gate_types = {
"amplitude_damping": None,
Expand Down Expand Up @@ -495,18 +499,34 @@ def _get_arch_info(
if connectivity["fullyConnected"]:
all_qubits: List = list(range(n_qubits))
else:
schema = device_properties["provider"]["braketSchemaHeader"]
connectivity_graph = connectivity["connectivityGraph"]
# Convert strings to ints
connectivity_graph = dict(
(int(k), [int(v) for v in l]) for k, l in connectivity_graph.items()
)
# each connectivity graph key will be an int
# connectivity_graph values will be lists
all_qubits_set = set()
for k, v in connectivity_graph.items():
all_qubits_set.add(k)
all_qubits_set.update(v)
all_qubits = list(all_qubits_set)
if schema == IQM_SCHEMA:
connectivity_graph = dict(
(int(k) - 1, [int(v) - 1 for v in l])
for k, l in connectivity_graph.items()
)
# each connectivity graph key will be an int
# connectivity_graph values will be lists
all_qubits_set = set()
for k, v in connectivity_graph.items():
all_qubits_set.add(k - 1)
for l in v:
all_qubits_set.add(l - 1)
all_qubits = list(all_qubits_set)
else:
connectivity_graph = dict(
(int(k), [int(v) for v in l])
for k, l in connectivity_graph.items()
)
# each connectivity graph key will be an int
# connectivity_graph values will be lists
all_qubits_set = set()
for k, v in connectivity_graph.items():
all_qubits_set.add(k)
all_qubits_set.update(v)
all_qubits = list(all_qubits_set)
else:
all_qubits = list(range(n_qubits))

Expand Down Expand Up @@ -566,6 +586,32 @@ def _get_backend_info(
get_link_error = lambda n0, n1: 1.0 - cast(
float, props2q[f"{n0.index[0]}-{n1.index[0]}"]["fCX"]
)
elif schema == IQM_SCHEMA:
properties = characteristics["properties"]
props1q = {}
for key in properties["one_qubit"].keys():
node1q = str(int(key) - 1)
props1q[node1q] = properties["one_qubit"][key]
props2q = {}
for key in properties["two_qubit"].keys():
ind = key.index("-")
node2q1, node2q2 = str(int(key[:ind]) - 1), str(
int(key[ind + 1 :]) - 1
)
props2q[node2q1 + "-" + node2q2] = properties["two_qubit"][key]
get_node_error = lambda n: 1.0 - cast(
float, props1q[f"{n.index[0]}"]["f1Q_simultaneous_RB"]
)
get_readout_error = lambda n: 1.0 - cast(
float, props1q[f"{n.index[0]}"]["fRO"]
)
get_link_error = lambda n0, n1: 1.0 - cast(
float,
props2q[
f"{min(n0.index[0],n1.index[0])}-{max(n0.index[0],n1.index[0])}"
]["fCZ"],
)

# readout error as symmetric 2x2 matrix
to_sym_mat: Callable[[float], List[List[float]]] = lambda x: [
[1.0 - x, x],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
install_requires=[
"pytket ~= 1.27",
"amazon-braket-sdk ~= 1.53",
"amazon-braket-schemas ~= 1.19",
"amazon-braket-schemas ~= 1.22",
"amazon-braket-default-simulator ~= 1.20",
"boto3-stubs",
],
Expand Down
45 changes: 45 additions & 0 deletions tests/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,51 @@ def test_oqc(authenticated_braket_backend: BraketBackend) -> None:
b.cancel(h)


@pytest.mark.skipif(skip_remote_tests, reason=REASON)
@pytest.mark.parametrize(
"authenticated_braket_backend",
[
{
"device_type": "qpu",
"provider": "iqm",
"device": "Garnet",
"region": "eu-north-1",
}
],
indirect=True,
)
def test_iqm(authenticated_braket_backend: BraketBackend) -> None:
b = authenticated_braket_backend
skip_if_device_is_not_available(b)
assert b.persistent_handles
assert b.supports_shots
assert not b.supports_state

chars = b.characterisation
assert chars is not None
assert all(s in chars for s in ["NodeErrors", "EdgeErrors", "ReadoutErrors"])

c = (
Circuit(3)
.add_gate(OpType.CCX, [0, 1, 2])
.add_gate(OpType.U1, 0.5, [1])
.add_gate(OpType.ISWAP, 0.5, [0, 2])
.add_gate(OpType.XXPhase, 0.5, [1, 2])
)
assert not b.valid_circuit(c)
c = b.get_compiled_circuit(c)
assert b.valid_circuit(c)
h = b.process_circuit(c, 10)
_ = b.circuit_status(h)
b.cancel(h)

# Circuit with unused qubits
c = Circuit(20).H(5).CX(5, 6)
c = b.get_compiled_circuit(c)
h = b.process_circuit(c, 10)
b.cancel(h)


def test_local_simulator() -> None:
b = BraketBackend(local=True)
assert b.supports_shots
Expand Down

0 comments on commit 107c4da

Please sign in to comment.