amazon-braket / amazon-braket-examples

Example notebooks that show how to apply quantum computing with Amazon Braket.
https://aws.amazon.com/braket/
Apache License 2.0
461 stars 224 forks source link

get list of measured bistrings from Aquila #369

Open balewski opened 11 months ago

balewski commented 11 months ago

For some analysis, say evaluation of stability of the HW, one needs to see the bistrings from all shots, presented as a list. Currently you provide only the summary in the form of dictionary of all unique bistrings and the number of occurences. It is done by get_counts(): https://amazon-braket-sdk-python.readthedocs.io/en/latest/_modules/braket/tasks/analog_hamiltonian_simulation_quantum_task_result.html#AnalogHamiltonianSimulationQuantumTaskResult.get_counts Can you provide also new function get_shots(), which would differ very little from get_counts(), namely instead of accumulating the dictionary:

state_counts = Counter()
 for shot in self.measurements:
 ...
      state_counts.update((state,))
return dict(state_counts)

it would append a list:

state_list = []
 for shot in self.measurements:
 ...
      state_list.append(state)
return state_list

I can hack it for now, but this type of functionality is of general use. E.g. it is available in Qiskit or TKet. Thanks, Jan

kshitijc commented 11 months ago

Thank you for raising this issue @balewski! We would be glad to include this functionality. Since you have already hacked it together, would you like to contribute it to the SDK?

balewski commented 11 months ago

I'm not that skilled with code commit. Here is my hacked version - use it as you like Jan

...!...!..................

def hacked_get_shots(measurements): state_list=[] states = ["e", "r", "g"] for shot in measurements: if shot.status == AnalogHamiltonianSimulationShotStatus.SUCCESS: pre = shot.pre_sequence post = shot.post_sequence

converting presequence and postsequence measurements to state_idx

        state_idx = [
            0 if pre_i == 0 else 1 if post_i == 0 else 2 for pre_i, post_i in zip(pre, post)
        ]
        state = "".join(map(lambda s_idx: states[s_idx], state_idx))
        state_list.append(state)

return state_list

On Sep 29, 2023, at 2:32 PM, Kshitij Chhabra @.***> wrote:

Thank you for raising this issue @balewski https://github.com/balewski! We would be glad to include this functionality. Since you have already hacked it together, would you like to contribute it to the SDK?

— Reply to this email directly, view it on GitHub https://github.com/amazon-braket/amazon-braket-examples/issues/369#issuecomment-1741511472, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMOFCKRFX4FOS3OCIDJBLX4445RANCNFSM6AAAAAA5M6QZDM. You are receiving this because you were mentioned.

kshitijc commented 11 months ago

Thanks a lot Jan! This is super helpful. Since this doesn't block you, I'll keep this open if someone else would like to contribute this to the SDK.