Skip to content

Commit

Permalink
Merge pull request #449 from rawkintrevo/2213
Browse files Browse the repository at this point in the history
MAHOUT-2213 Implement Amazon Bracket backend
  • Loading branch information
josep2 authored Jul 27, 2024
2 parents d5f5768 + f12268e commit 6b6305c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 64 additions & 0 deletions qumat/amazon_braket_backend.py
Original file line number Diff line number Diff line change
@@ -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.")

0 comments on commit 6b6305c

Please sign in to comment.