-
Notifications
You must be signed in to change notification settings - Fork 45
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
feature: add support for braket measure instruction #169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great!
@@ -128,6 +129,7 @@ | |||
"zz": lambda angle: [braket_gates.ZZ(2 * pi * angle)], | |||
# Global phase | |||
_GPHASE_GATE_NAME: lambda phase: [braket_gates.GPhase(phase)], | |||
"measure": lambda: [measure.Measure()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? This dict is only used for gates.
"measure": lambda: [measure.Measure()], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to match the qiskit measure
to the Braket Measure
so without it, the Braket measure isn't added to the Circuit.
I do agree that this might not work well in this particular dict. Maybe there can be a _ADDITIONAL_INSTRUCTION_NAME_TO_BRAKET_NAME
dict for things like measure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be handled here:
qiskit-braket-provider/qiskit_braket_provider/providers/adapter.py
Lines 434 to 437 in 0751b4c
if gate_name == "measure": | |
qubit = qubits[0] # qubit count = 1 for measure | |
qubit_index = circuit.find_bit(qubit).index | |
braket_circuit.measure(qubit_index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, that does work for the Qiskit to Braket conversion but the Braket to Qiskit conversion here checks for gates in the _GATE_NAME_TO_QISKIT_GATE dict.
Is there a better way to implement the Braket to Qiskit conversion for measure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's fine to leave it in the Braket->Qiskit direction; you could do a special check for measure operators, but that's not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the measure
instruction from _GATE_NAME_TO_BRAKET_GATE
but left it in _GATE_NAME_TO_QISKIT_GATE
Co-authored-by: Cody Wang <speller26@gmail.com>
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:
{'1': 518, '0': 506}
To keep the current functionality of the bug and measure all the qubits, simply change
measure(0, 0)
tomeasure_all()
{'00': 503, '11': 521}
List of changes
measure
to the Braket gatesmeasure