From 107c4daa02f66741adbfca9976f424b7f0c3756e Mon Sep 17 00:00:00 2001 From: yoshi-qc <95134786+yoshi-qc@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:16:37 +0900 Subject: [PATCH] created IQM_SCHEMA (#153) --- pytket/extensions/braket/backends/braket.py | 66 +++++++++++++++++---- setup.py | 2 +- tests/backend_test.py | 45 ++++++++++++++ 3 files changed, 102 insertions(+), 11 deletions(-) diff --git a/pytket/extensions/braket/backends/braket.py b/pytket/extensions/braket/backends/braket.py index 6f8f70d..fcf1edf 100644 --- a/pytket/extensions/braket/backends/braket.py +++ b/pytket/extensions/braket/backends/braket.py @@ -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, @@ -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)) @@ -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], diff --git a/setup.py b/setup.py index 9f3028c..2f2dbbc 100644 --- a/setup.py +++ b/setup.py @@ -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", ], diff --git a/tests/backend_test.py b/tests/backend_test.py index bd07844..10737ea 100644 --- a/tests/backend_test.py +++ b/tests/backend_test.py @@ -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