qiskit-community / qiskit-braket-provider

Qiskit-Braket provider to execute Qiskit programs on quantum computing hardware devices through Amazon Braket.
https://qiskit-community.github.io/qiskit-braket-provider/
Apache License 2.0
57 stars 45 forks source link

feature: add support for braket measure instruction #169

Closed ashlhans closed 3 months ago

ashlhans commented 3 months ago

Summary

Add support for Braket's measure instruction.

This solves the bug detailed in Issue #130 where translating a circuit in qiskit to braket returned all the measurements instead of the requested measured qubit.

Details and comments

Now, users can measure a subset of qubits on local simulators or any device that supports partial measurement.

Example:

sim = BraketLocalBackend()
qc = QuantumCircuit(2, 1)
qc.h(0)
qc.cx(0, 1)
qc.measure(0, 0)
task = transpile(qc, sim)
task = sim.run(task)
result = task.result()
counts = result.get_counts()
print(counts)

{'1': 518, '0': 506}

To keep the current functionality of the bug and measure all the qubits, simply change measure(0, 0) to measure_all()

sim = BraketLocalBackend()
qc = QuantumCircuit(2, 1)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
task = transpile(qc, sim)
task = sim.run(task)
result = task.result()
counts = result.get_counts()
print(counts)

{'00': 503, '11': 521}

List of changes

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.