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

V1 to V2 Migration Guide Improvement Suggestion #2128

Open
1 of 5 tasks
acastellane opened this issue Oct 14, 2024 · 2 comments · May be fixed by #2384
Open
1 of 5 tasks

V1 to V2 Migration Guide Improvement Suggestion #2128

acastellane opened this issue Oct 14, 2024 · 2 comments · May be fixed by #2384

Comments

@acastellane
Copy link
Contributor

URL to the relevant documentation

https://docs.quantum.ibm.com/migration-guides/v2-primitives#sampler-examples--input-and-output

Select all that apply

  • typo
  • code bug
  • out-of-date content
  • broken link
  • other

Describe the fix.

When a user used to have in V1:
dists = job.result().quasi_dists
Could we provide an example of conversion of his code (including a circuit example) to V2 using:
counts = job.result()[0].data.meas.get_counts()
?
Thanks

@beckykd
Copy link
Collaborator

beckykd commented Nov 6, 2024

From @jyu00 "the quasi probabilities is just counts / shots... but I don't remember the v1 syntax so I'll need to play with it. "

@jyu00
Copy link
Collaborator

jyu00 commented Nov 22, 2024

The old output format was a dictionary of with bitstring (in int) as the key and quasi-probabilities as the value for each circuit, e.g. [{0: 0.4589879389380925, 1: 0.5410120610619075}]. The new format has the same key (but as string) and counts as the value. To convert the new format to the old, one can do:

v2_result = sampler_v2_job.result()
v1_format = []
for pub_result in v2_result:
    counts = pub_result.data.meas.get_counts()
    v1_format.append( {int(key, 2): val/shots for key, val in counts.items()} )

And v1_format here is the same result in the v1 format. Note that shots is the number of shots selected per this rule.

@beckykd beckykd linked a pull request Nov 25, 2024 that will close this issue
@beckykd beckykd moved this to In Review in Docs Planning Nov 25, 2024
@beckykd beckykd removed the needs triage 🤔 this issue needs to be prioritized by the docs team label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
Development

Successfully merging a pull request may close this issue.

5 participants