From f12268ee3952ae40f74a44ef0bf17e8e9d416549 Mon Sep 17 00:00:00 2001 From: Trevor Grant Date: Fri, 26 Jul 2024 21:15:22 -0500 Subject: [PATCH] Closes #2213 Implement Amazon Bracket backend --- pyproject.toml | 1 + qumat/amazon_braket_backend.py | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 qumat/amazon_braket_backend.py diff --git a/pyproject.toml b/pyproject.toml index 929cab925..20f24b2eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,6 +11,7 @@ python = "^3.9" qiskit = "^0.45.1" qiskit-aer = "^0.13.2" cirq = "^1.3.0" +amazon-braket-sdk = "^1.10.0" [tool.poetry.dev-dependencies] pytest = "^8.1.1" diff --git a/qumat/amazon_braket_backend.py b/qumat/amazon_braket_backend.py new file mode 100644 index 000000000..ad1b04a75 --- /dev/null +++ b/qumat/amazon_braket_backend.py @@ -0,0 +1,64 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +from braket.aws import AwsQuantumSimulator, AwsDevice +from braket.circuits import Circuit + +def initialize_backend(backend_config): + backend_options = backend_config['backend_options'] + simulator_type = backend_options.get('simulator_type', 'default') + if simulator_type == 'default': + return AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1") + else: + print(f"Simulator type '{simulator_type}' is not supported in Amazon Braket. Using default.") + return AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1") + +def create_empty_circuit(num_qubits): + return Circuit() + +def apply_not_gate(circuit, qubit_index): + circuit.x(qubit_index) + +def apply_hadamard_gate(circuit, qubit_index): + circuit.h(qubit_index) + +def apply_cnot_gate(circuit, control_qubit_index, target_qubit_index): + circuit.cnot(control_qubit_index, target_qubit_index) + +def apply_toffoli_gate(circuit, control_qubit_index1, control_qubit_index2, target_qubit_index): + circuit.ccnot(control_qubit_index1, control_qubit_index2, target_qubit_index) + +def apply_swap_gate(circuit, qubit_index1, qubit_index2): + circuit.swap(qubit_index1, qubit_index2) + +def apply_pauli_x_gate(circuit, qubit_index): + circuit.x(qubit_index) + +def apply_pauli_y_gate(circuit, qubit_index): + circuit.y(qubit_index) + +def apply_pauli_z_gate(circuit, qubit_index): + circuit.z(qubit_index) + +def execute_circuit(circuit, backend, backend_config): + shots = backend_config['backend_options'].get('shots', 1) + task = backend.run(circuit, shots=shots) + result = task.result() + return result.measurement_counts + +# placeholder method for use in the testing suite +def get_final_state_vector(circuit, backend, backend_config): + raise NotImplementedError("Final state vector calculation is not currently supported with Amazon Braket.") \ No newline at end of file