Adjust DynamicsBackend level 2 result formatting to match BackendSamplerV2's expectations #373
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Qiskit Experiments 0.8.0 uses
qiskit_ibm_runtime.SamplerV2
to execute circuits by default and that passes the execution toqiskit.primitives.BackendSamplerV2
forDynamicsBackend
.When
BackendSamplerV2
converts the results fromDynamicsBackend
into thePubResult
format, it uses the resultmemory
in an if statement to check if it is empty. For a list that works but for a numpy array an exception is raised about needing to useall()
to check the truth value of an array. Here the memory data is converted from numpy array into a list usingtolist()
before being passed into the result object. (Note: the function generating this numpy array has a type annotation stating that it returns a list, so this could be changed at that level of the stack instead but that might require changing other things expecting a numpy array).After checking that the result memory is not empty,
BackendSamplerV2
packs the state results into aBitArray
and to do this it assumes that the memory results are formatted as hex strings butDynamicsBackend
was returning binary strings with the format"10101"
. Here the strings are converted to hex. It is not clear to me if Qiskit specifies that one format is required or the other or if both should be valid (andBackendSamplerV2
really has the problem by not accepting the binary format). There could be downstream disruption if some code assumesDynamicsBackend
returns the binary format. Additionally, does Dynamics support returning shots for higher levels up to 9? That would work the "binary" (really "decimal" at that point) format but forcing the casting to hex breaks it.