diff --git a/qiskit_braket_provider/providers/adapter.py b/qiskit_braket_provider/providers/adapter.py index c24ed383..6706574d 100644 --- a/qiskit_braket_provider/providers/adapter.py +++ b/qiskit_braket_provider/providers/adapter.py @@ -8,6 +8,7 @@ Instruction, gates, result_types, + observables, ) from braket.device_schema import ( DeviceActionType, @@ -364,11 +365,13 @@ def convert_qiskit_to_braket_circuit(circuit: QuantumCircuit) -> Circuit: # TODO: change Probability result type for Sample for proper functioning # pylint:disable=fixme # Getting the index from the bit mapping quantum_circuit.add_result_type( - result_types.Probability( + # pylint:disable=fixme + result_types.Sample( + observable=observables.Z(), target=[ circuit.find_bit(qiskit_gates[1][0]).index, circuit.find_bit(qiskit_gates[2][0]).index, - ] + ], ) ) elif name == "barrier": diff --git a/tests/providers/test_adapter.py b/tests/providers/test_adapter.py index 2f7aebf2..5d34108d 100644 --- a/tests/providers/test_adapter.py +++ b/tests/providers/test_adapter.py @@ -1,7 +1,7 @@ """Tests for Qiskti to Braket adapter.""" from unittest import TestCase -from braket.circuits import Circuit, FreeParameter +from braket.circuits import Circuit, FreeParameter, observables import numpy as np from qiskit import QuantumCircuit from qiskit.circuit import Parameter @@ -59,6 +59,24 @@ def test_convert_parametric_qiskit_to_braket_circuit(self): self.assertEqual(braket_circuit, braket_circuit_ans) + def test_sample_result_type(self): + """Tests sample result type with observables Z""" + + qiskit_circuit = QuantumCircuit(2, 2) + qiskit_circuit.h(0) + qiskit_circuit.cnot(0, 1) + qiskit_circuit.measure(0, 0) + braket_circuit = convert_qiskit_to_braket_circuit(qiskit_circuit) + + circuits = ( + Circuit() # pylint: disable=no-member + .h(0) + .cnot(0, 1) + .sample(observable=observables.Z(), target=0) + ) + + self.assertEqual(braket_circuit, circuits) + class TestVerbatimBoxWrapper(TestCase): """Test wrapping in Verbatim box."""