Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for Qiskit to Braket circuit conversion #97

Merged
merged 7 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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