Skip to content

Commit

Permalink
fix: Updates for Qiskit to Braket circuit conversion (#97)
Browse files Browse the repository at this point in the history
* Probability to Sample result type

* passes tox lint

* updates toxlint

* fixes observable z error but not passses elint

* unit test added

* final commit with tests
  • Loading branch information
urihan authored Jun 5, 2023
1 parent 6c3cc1f commit 5fef143
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions qiskit_braket_provider/providers/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Instruction,
gates,
result_types,
observables,
)
from braket.device_schema import (
DeviceActionType,
Expand Down Expand Up @@ -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":
Expand Down
20 changes: 19 additions & 1 deletion tests/providers/test_adapter.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 5fef143

Please sign in to comment.