This is an automated email from the ASF dual-hosted git repository.

rawkintrevo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git


The following commit(s) were added to refs/heads/main by this push:
     new 40602c755 Add Amazon Braket backend test (#582)
40602c755 is described below

commit 40602c75590faf40992daab878ee77375773f081
Author: Guan Ming(Wesley) Chiu <[email protected]>
AuthorDate: Sat Oct 11 04:35:48 2025 +0800

    Add Amazon Braket backend test (#582)
    
    * Add Amazon Braket backend test
    
    * Fix amazon_braket_helpers format
---
 qumat/amazon_braket_backend.py   | 13 ++++---
 testing/amazon_braket_helpers.py | 74 ++++++++++++++++++++++++++++++++++++++++
 testing/conftest.py              |  2 +-
 3 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/qumat/amazon_braket_backend.py b/qumat/amazon_braket_backend.py
index 3378a46ce..0690dc18d 100644
--- a/qumat/amazon_braket_backend.py
+++ b/qumat/amazon_braket_backend.py
@@ -15,13 +15,16 @@
 # limitations under the License.
 #
 from braket.aws import AwsDevice
+from braket.devices import LocalSimulator
 from braket.circuits import Circuit, FreeParameter
 
 
 def initialize_backend(backend_config):
     backend_options = backend_config["backend_options"]
     simulator_type = backend_options.get("simulator_type", "default")
-    if simulator_type == "default":
+    if simulator_type == "local":
+        return LocalSimulator()
+    elif simulator_type == "default":
         return 
AwsDevice("arn:aws:braket:::device/quantum-simulator/amazon/sv1")
     else:
         print(
@@ -77,9 +80,11 @@ def execute_circuit(circuit, backend, backend_config):
 
 # 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."
-    )
+    circuit.state_vector()
+    result = backend.run(circuit, shots=0).result()
+    state_vector = result.values[0]
+
+    return state_vector
 
 
 def draw_circuit(circuit):
diff --git a/testing/amazon_braket_helpers.py b/testing/amazon_braket_helpers.py
new file mode 100644
index 000000000..06f43296c
--- /dev/null
+++ b/testing/amazon_braket_helpers.py
@@ -0,0 +1,74 @@
+#
+# 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.devices import LocalSimulator
+from braket.circuits import Circuit
+import numpy as np
+
+
+def get_qumat_backend_config(test_type: str = "get_final_state_vector"):
+    if test_type == "get_final_state_vector":
+        qumat_backend_config = {
+            "backend_name": "amazon_braket",
+            "backend_options": {"simulator_type": "local", "shots": 1},
+        }
+    else:
+        pass
+
+    return qumat_backend_config
+
+
+def get_native_example_final_state_vector(
+    initial_state_ket_str: str = "000",
+) -> np.ndarray:
+    n_qubits = len(initial_state_ket_str)
+    assert n_qubits == 3, (
+        "The current braket native testing example is strictly 3 qubits"
+    )
+
+    # Use LocalSimulator for state vector simulation
+    device = LocalSimulator()
+
+    circuit = Circuit()
+
+    # Initialize to desired state
+    for i, bit in enumerate(initial_state_ket_str):
+        if bit == "1":
+            circuit.x(i)
+
+    # Create entanglement between qubits 1 and 2
+    circuit.h(1)
+    circuit.cnot(1, 2)
+
+    # Prepare the state to be teleported on qubit 0
+    circuit.h(0)
+    circuit.z(0)
+
+    # Perform Bell measurement on qubits 0 and 1
+    circuit.cnot(0, 1)
+    circuit.h(0)
+
+    # Add state_vector result type to get the final state
+    circuit.state_vector()
+
+    # Run the circuit
+    result = device.run(circuit, shots=0).result()
+
+    # Get the state vector (values is a complex numpy array)
+    state_vector = result.values[0]
+
+    return state_vector
diff --git a/testing/conftest.py b/testing/conftest.py
index 01f088f2f..5f203a2af 100644
--- a/testing/conftest.py
+++ b/testing/conftest.py
@@ -24,7 +24,7 @@ project_root = Path(__file__).parent.parent
 sys.path.insert(0, str(project_root))
 
 # Define backends to test - used by both parametrize and fixture
-TESTING_BACKENDS = ["qiskit", "cirq"]  # Can be expanded to include "braket" 
when ready
+TESTING_BACKENDS = ["qiskit", "cirq", "amazon_braket"]
 
 
 @pytest.fixture(scope="session")

Reply via email to