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

hcr 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 e0eea46a9 Fix KeyError when shots not specified in Qiskit backend 
(#899)
e0eea46a9 is described below

commit e0eea46a9c700a10ea500ca051e3d3ee17bb244c
Author: Ryan Huang <[email protected]>
AuthorDate: Wed Jan 21 23:28:08 2026 +0800

    Fix KeyError when shots not specified in Qiskit backend (#899)
    
    * Add default value for shots in backend configuration
    
    * Add regression test for default shots parameter in backend configurations
---
 qumat/qiskit_backend.py              |  6 +++---
 testing/qumat/test_create_circuit.py | 38 ++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/qumat/qiskit_backend.py b/qumat/qiskit_backend.py
index e4c771870..25f6bb97a 100644
--- a/qumat/qiskit_backend.py
+++ b/qumat/qiskit_backend.py
@@ -21,7 +21,7 @@ from qiskit_aer import AerSimulator
 def initialize_backend(backend_config):
     backend_options = backend_config["backend_options"]
     simulator_type = backend_options["simulator_type"]
-    shots = backend_options["shots"]
+    shots = backend_options.get("shots", 1)
 
     # Map legacy simulator types to AerSimulator methods
     simulator_methods = {
@@ -125,14 +125,14 @@ def execute_circuit(circuit, backend, backend_config):
         transpiled_circuit = qiskit.transpile(working_circuit, backend)
         bound_circuit = 
transpiled_circuit.assign_parameters(parameter_bindings)
         job = backend.run(
-            bound_circuit, shots=backend_config["backend_options"]["shots"]
+            bound_circuit, 
shots=backend_config["backend_options"].get("shots", 1)
         )
         result = job.result()
         return result.get_counts()
     else:
         transpiled_circuit = qiskit.transpile(working_circuit, backend)
         job = backend.run(
-            transpiled_circuit, 
shots=backend_config["backend_options"]["shots"]
+            transpiled_circuit, 
shots=backend_config["backend_options"].get("shots", 1)
         )
         result = job.result()
         return result.get_counts()
diff --git a/testing/qumat/test_create_circuit.py 
b/testing/qumat/test_create_circuit.py
index 69f741a72..869f5bcab 100644
--- a/testing/qumat/test_create_circuit.py
+++ b/testing/qumat/test_create_circuit.py
@@ -65,6 +65,44 @@ class TestCreateCircuit:
         )
 
 
[email protected]("backend_name", TESTING_BACKENDS)
+class TestDefaultShotsParameter:
+    """Test that backends work without explicitly specifying shots 
parameter."""
+
+    def test_execute_circuit_without_shots_parameter(self, backend_name):
+        """Test that circuits can be executed without specifying shots.
+
+        This is a regression test to ensure all backends have a default
+        value for the shots parameter, matching the README quick start example.
+        """
+        # Config without shots - should use default
+        configs = {
+            "qiskit": {
+                "backend_name": "qiskit",
+                "backend_options": {"simulator_type": "aer_simulator"},
+            },
+            "cirq": {
+                "backend_name": "cirq",
+                "backend_options": {"simulator_type": "default"},
+            },
+            "amazon_braket": {
+                "backend_name": "amazon_braket",
+                "backend_options": {"simulator_type": "local"},
+            },
+        }
+
+        backend_config = configs[backend_name]
+        qumat = QuMat(backend_config)
+        qumat.create_empty_circuit(num_qubits=2)
+        qumat.apply_hadamard_gate(0)
+        qumat.apply_cnot_gate(0, 1)
+
+        # Should not raise KeyError for missing 'shots'
+        result = qumat.execute_circuit()
+
+        assert result is not None
+
+
 class TestBackendConfigValidation:
     """Test class for backend configuration validation."""
 

Reply via email to