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

Primitives (non runtime) changes for 1.0 #812

Merged
merged 63 commits into from
Apr 19, 2024
Merged

Conversation

beckykd
Copy link
Collaborator

@beckykd beckykd commented Feb 14, 2024

Closes #1072

Some helpful background: from Jessie: The goal of this document is for people to test their quantum program (that calls primitives) locally, before sending them to Qiskit Runtime to run on a real QPU.

Most of this page uses the statevector simulator, and there is an equivalent for V2, better named as StatevectorEstimator and StatevectorSampler.

docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
@beckykd
Copy link
Collaborator Author

beckykd commented Feb 15, 2024

I made an attempt at updating it from the Features migration guide, but it definitely needs a review by someone who understands the base primitives. Maybe @ElePT , @ihincks , or @jyu00 , if anyone has time. Much appreciated!

Copy link
Collaborator

@ElePT ElePT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started out trying to leave individual review comments but I think it's easier if I compile them into general feedback about the document. This doc is now a mix of a bunch of prior pages (I can recognize content from at least 3). There is the explanation of what primitives are (in general), particular implementation details of the reference primitives, how to define options, how to deal with parametrized circuits, how to translate everything to backend primitives, and on top of all, an introduction of the new V2 primitives and the need to show V1 and V2 paths for everything. I think that there is enough content that we can at least extract 2 decently sized independent pages, if not more. I suggest the following separation:

  1. Keeping this page as a "reference primitives" how-to, i.e. "Running locally with statevector simulators/exact simulation". This is what the title suggests. The page should show how to run, retrieve results and set the only available option (shots/precision) for local execution. We can show paths for both V1 and V2 so this guide will also act a bit as a migration guide/introduction to StatevectorSampler and StatevectorSimulator but only for the most basic use case, no explanation of, for example, broadcasting rules.
  2. A guide for the backend primitives, it might make sense to leave this one for when the V2 version is out, or try to document the alternatives that exist now, or keep it V1, but in a separate location.
  3. A guide for the new V2 statevector primitives that shows detailed edge cases and how to deal with broadcasting. I think that this guide is crucial, I tried to cover some examples in the 1.0 feature migration guide but I think that it can be super valuable to have an inpendent, easily accessible page for this.
  4. Probably better to leave for the future, but a clear guide on setting options in the primitives in general (and only talk about shots/precision in this one).

I have tried to single out the content I believe should be in this page and made a draft in a new branch (EPT/reference-primitives) https://github.com/Qiskit/documentation/blob/EPT/reference-primitives/docs/verify/simulate-with-qiskit-primitives.mdx. The code examples are not correct, a great deal of the document has been commented out and some content is missing, but the build hopefully shows better what I mean. Feel free to use that branch, I didn't want to push anything or overstep, but I wanted to do it to visualize what I wanted to express, and I thought it might be useful to share.

docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
docs/verify/simulate-with-qiskit-primitives.mdx Outdated Show resolved Hide resolved
@ElePT
Copy link
Collaborator

ElePT commented Feb 16, 2024

Here are some screenshots of the content I propose in https://github.com/Qiskit/documentation/blob/EPT/reference-primitives/docs/verify/simulate-with-qiskit-primitives.mdx in case the comments make the raw text not very readable:
Screenshot 2024-02-16 at 14 54 39

Screenshot 2024-02-16 at 14 54 50

Screenshot 2024-02-16 at 14 55 04

Screenshot 2024-02-16 at 14 55 12

@beckykd
Copy link
Collaborator Author

beckykd commented Feb 16, 2024

@ElePT thanks so much for taking this on!

@beckykd
Copy link
Collaborator Author

beckykd commented Feb 16, 2024

My thoughts on the suggested breakup: (FYI @javabster )

  1. Keeping this page as a "reference primitives" how-to, i.e. "Running locally with statevector simulators/exact simulation". This is what the title suggests. ... (BD: Makes sense to me)

  2. A guide for the backend primitives, it might make sense to leave this one for when the V2 version is out, or try to document the alternatives that exist now, or keep it V1, but in a separate location. (BD: We've been putting V1 and V2 together, so I'd recommend doing that. Weren't the V2 backend primitives released already? I don't totally understand what would be in this, compared to topic 1.)

  3. A guide for the new V2 statevector primitives that shows detailed edge cases and how to deal with broadcasting. I think that this guide is crucial, ... (BD: I'm fine with this)

  4. Future: A clear guide on setting options in the primitives in general. (BD: would this be for the base primitives only? We have a section on this in the existing doc, although it's focused on Runtime)

I'm willing to start making issues for whatever new topics we decide on.

The only problem with doing the work on a separate fork is that we don't get the preview, but I don't mind working on your fork.

@ElePT
Copy link
Collaborator

ElePT commented Feb 19, 2024

We've been putting V1 and V2 together, so I'd recommend doing that. Weren't the V2 backend primitives released already? I don't totally understand what would be in this, compared to topic 1.

There are currently no V2 backend primitives, this is what Jessie's comment and that general thread refers to. For a bit of context, the backend primitives are different from the runtime or reference (statevector) primitives. Runtime primitives run on the runtime provider (IBM backends), reference primitives run on a local statevector simulator. This third type allows to "hook in" primitive implementations to any backend (IBM or non-IBM), and I think that we should document them separately because they do not fit into the "Exact simulation with Qiskit primitives" topic. Until now, the only references to the backend primitives on this page were the two notes about BackendSampler and BackendEstimator:

Screenshot 2024-02-19 at 13 51 11

Screenshot 2024-02-19 at 13 51 31

They were added when the page was a general introduction to the primitives. Now that the topic is under "Verify", they don't really make sense there. However, it is a bit hard to find a place for them in this start-build-transpile-verify-run paradigm. I would personally put them under "run", because they are an alternative to the runtime primtives., however, it's important to understand that they are not linked to any IBM provider/offering. The use-case for the backend primitives is a third-party provider that wants an out-of-the-box implementation of primitives to interface with their own backends that have a backend.run() method.

@ElePT
Copy link
Collaborator

ElePT commented Feb 19, 2024

  1. Future: A clear guide on setting options in the primitives in general. (BD: would this be for the base primitives only? We have a section on this in the existing doc, although it's focused on Runtime)

As far as I understand, there is a plan to implement a new primitive options type that affects all primitives, as explained in this RFC. I have not followed the progress on this item but if it gets implemented, this is what I think should be documented clearly.

@ElePT
Copy link
Collaborator

ElePT commented Feb 19, 2024

The only problem with doing the work on a separate fork is that we don't get the preview, but I don't mind working on your fork.

@beckykd I can just push my proposal into your branch if that makes it easier for you. It's not in a separate fork, but we would have to open an independent PR to use it directly and we might lose track of the discussion in this PR, which I think is pretty valuable.

@beckykd
Copy link
Collaborator Author

beckykd commented Feb 19, 2024

Until now, the only references to the backend primitives on this page were the two notes about BackendSampler and BackendEstimator

@javabster suggested that I pull this information into Get started with primitives, since there's currently not enough to put in its own topic. I pulled it out in the latest commit.

@beckykd
Copy link
Collaborator Author

beckykd commented Feb 19, 2024

I suggest the following separation

I created new issues for 2. and 3., because I think they are reasonably separate topics. I'm not sure about 4 (a guide to setting options). That might be better handled within the individual topics.

@kevinsung
Copy link
Collaborator

@beckykd What's the status of this PR? In order to work on #1072 I'd like to convert docs/verify/simulate-with-qiskit-primitives.mdx to a Jupyter notebook, but this PR blocks that because it changes this file.

Comment on lines +391 to +392
bitstrings = data_pub.meas.get_bitstrings()
print(f"The number of bitstrings is: {len(bitstrings)}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to update this code because of an error found here:
image

@abbycross
Copy link
Collaborator

@ElePT @beckykd is this one ready to merge?

@abbycross abbycross added this pull request to the merge queue Apr 19, 2024
Merged via the queue into main with commit 731d7a7 Apr 19, 2024
4 checks passed
@abbycross abbycross deleted the primitives-updates-for-1.0 branch April 19, 2024 17:39
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
Closes Qiskit#1072 

Some helpful background: from Jessie: The goal of this document is for
people to test their quantum program (that calls primitives) locally,
before sending them to Qiskit Runtime to run on a real QPU.

Most of this page uses the statevector simulator, and there is an
equivalent for V2, better named as
[StatevectorEstimator](https://github.com/Qiskit/qiskit/blob/main/qiskit/primitives/statevector_estimator.py#L31)
and
[StatevectorSampler](https://github.com/Qiskit/qiskit/blob/main/qiskit/primitives/statevector_sampler.py#L52).

---------

Co-authored-by: Ian Hincks <ian.hincks@gmail.com>
Co-authored-by: abbycross <across@us.ibm.com>
Co-authored-by: Elena Peña Tapia <epenatap@gmail.com>
Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Update "Exact simulation with Qiskit primitives" to use V2 Primitives
7 participants