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
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
f52fe7e
draft changes
beckykd Feb 14, 2024
49d73ac
Update docs/verify/simulate-with-qiskit-primitives.mdx
beckykd Feb 14, 2024
aea5053
Update docs/verify/simulate-with-qiskit-primitives.mdx
beckykd Feb 14, 2024
89fab90
further edits
beckykd Feb 15, 2024
31c48ad
Merge branch 'primitives-updates-for-1.0' of https://github.com/Qiski…
beckykd Feb 15, 2024
c155618
Further edits
beckykd Feb 15, 2024
a19b05a
pull out backend primitives
beckykd Feb 19, 2024
9affb6c
Merge branch 'main' into primitives-updates-for-1.0
abbycross Apr 1, 2024
68bef1d
clean up after merge conflict
abbycross Apr 1, 2024
d7c0f74
Add Elena's suggestion for simulate with primitives topic (starting p…
ElePT Apr 4, 2024
b0592ef
Clean up commented-out sections of the document
ElePT Apr 4, 2024
f21db70
Address previous review comments
ElePT Apr 4, 2024
19f384d
no longer need tm for Qiskit
abbycross Apr 4, 2024
6d63ad6
simplify
abbycross Apr 4, 2024
129a71e
simplify
abbycross Apr 4, 2024
8425dd7
new guidance: no need to tm Qiskit
abbycross Apr 4, 2024
be01d9c
tweaks
abbycross Apr 4, 2024
158f0be
avoid "below"
abbycross Apr 4, 2024
f99c45c
typo and tweak
abbycross Apr 4, 2024
d8cfb0e
rmv sentence fragment
abbycross Apr 4, 2024
9bd026d
Update docs/verify/simulate-with-qiskit-primitives.mdx
abbycross Apr 4, 2024
339eb2c
simplify
abbycross Apr 4, 2024
84f9e48
tweaks
abbycross Apr 4, 2024
e2da48a
missing period
abbycross Apr 4, 2024
83da606
wordsmith
abbycross Apr 4, 2024
58bf43c
PUB rather than pub
abbycross Apr 4, 2024
82e806a
fix broken internal link
abbycross Apr 4, 2024
9417967
convert to notebook
abbycross Apr 5, 2024
b5dd11d
tox
abbycross Apr 5, 2024
d41ebcd
missing header
abbycross Apr 5, 2024
89f1cd1
Delete DELETE-simulate-with-qiskit-primitives.mdx
abbycross Apr 5, 2024
46144a6
add in one more output
abbycross Apr 5, 2024
6284bef
Update simulate-with-qiskit-primitives.ipynb
abbycross Apr 5, 2024
f7e836f
tox
abbycross Apr 5, 2024
cf6122f
convert to mdx
abbycross Apr 9, 2024
0181482
links to aer topic, runtime primitives intro topic
abbycross Apr 10, 2024
8dae5ac
should be sampler in a sampler example
abbycross Apr 10, 2024
50101bb
add transpilation instructions to sampler section
abbycross Apr 10, 2024
ae566fb
add in isa transpilation for estimator section
abbycross Apr 10, 2024
98f4956
add output
abbycross Apr 10, 2024
b2a9bbd
rmv ipynb
abbycross Apr 10, 2024
9d30078
Update docs/verify/simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
5317503
Update docs/verify/simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
625a60e
Update docs/verify/simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
cb6c8c7
code review
abbycross Apr 11, 2024
034971b
Merge branch 'primitives-updates-for-1.0' of https://github.com/Qiski…
abbycross Apr 11, 2024
596a5d8
add ISA message
abbycross Apr 11, 2024
bd05d07
Update simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
2bcc8af
Update simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
7440557
rest of code review
abbycross Apr 11, 2024
e331fa0
add result
abbycross Apr 11, 2024
6e9bd9a
testing out print statement
abbycross Apr 11, 2024
3a90933
Update .gitignore
abbycross Apr 11, 2024
5d0ceb7
Update docs/verify/simulate-with-qiskit-primitives.mdx
abbycross Apr 11, 2024
20a3869
Becky's review
abbycross Apr 11, 2024
d7c2fa6
Becky's review
abbycross Apr 11, 2024
c9b9785
Becky's review
abbycross Apr 11, 2024
4116f77
Becky's review
abbycross Apr 11, 2024
1c1281a
Becky's review
abbycross Apr 11, 2024
38e5c31
Becky's review
abbycross Apr 11, 2024
0b51021
Becky review
abbycross Apr 11, 2024
5c77ba3
Becky's review
abbycross Apr 11, 2024
9ae0238
becky's review
abbycross Apr 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions docs/verify/simulate-with-qiskit-primitives.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `Estimator` primitive can compute an expectation value, and the `Sampler` pr
Follow these instructions to get the expected value of an observable for a given quantum circuit with the [`qiskit.primitives.Estimator`](../api/qiskit/qiskit.primitives.Estimator) primitive.
beckykd marked this conversation as resolved.
Show resolved Hide resolved

<Admonition type="note">
While this guide uses Qiskit’s reference implementation, the `Estimator` primitive can be run with any provider using [`qiskit.primitives.BackendEstimator`](../api/qiskit/qiskit.primitives.BackendEstimator).
While this guide uses the Qiskit reference implementation, the `Estimator` primitive can be run with any provider using [`qiskit.primitives.BackendEstimator`](../api/qiskit/qiskit.primitives.BackendEstimator).
ElePT marked this conversation as resolved.
Show resolved Hide resolved

```python
from qiskit.primitives import BackendEstimator
ElePT marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -71,36 +71,70 @@ estimator = Estimator()
### Run and get results
beckykd marked this conversation as resolved.
Show resolved Hide resolved

Now that you have defined your `estimator`, you can run your estimation by calling the [`qiskit.primitives.Estimator.run`](../api/qiskit/qiskit.primitives.Estimator#run) method,
beckykd marked this conversation as resolved.
Show resolved Hide resolved
which returns an instance of [`qiskit.providers.JobV1`](../api/qiskit/qiskit.providers.JobV1). You can get the results from the job (as a [`qiskit.primitives.EstimatorResult`](../api/qiskit/qiskit.primitives.EstimatorResult) object)
which returns an instance of [`qiskit.providers.JobV1`](../api/qiskit/qiskit.providers.JobV1).
beckykd marked this conversation as resolved.
Show resolved Hide resolved

The V2 primitives take one or more primitive unified blocs (PUBs) as the inputs. Each PUB is a tuple that contains a single circuit and data broadcasted to that circuit.
beckykd marked this conversation as resolved.
Show resolved Hide resolved

<Tabs>
<TabItem value="EstimatorV2" label="EstimatorV2">
```python
job = estimator.run([(qc, observable)])
result = job.result()
print(result)
```

You can get the results from the job (as a [`qiskit.primitives.EstimatorResult`](../api/qiskit/qiskit.primitives.EstimatorResult) object)
with the [`qiskit.providers.JobV1.result`](../api/qiskit/qiskit.providers.JobV1#result) method.
ElePT marked this conversation as resolved.
Show resolved Hide resolved

```python
ElePT marked this conversation as resolved.
Show resolved Hide resolved
print(f" > Metadata: {result[0].metadata}")
```
</TabItem>
<TabItem value="EstimatorV1" label="Estimator (V1)">
```python
job = estimator.run(qc, observable)
result = job.result()
print(result)
```
You can get the results from the job (as a [`qiskit.primitives.EstimatorResult`](../api/qiskit/qiskit.primitives.EstimatorResult) object)
with the [`qiskit.providers.JobV1.result`](../api/qiskit/qiskit.providers.JobV1#result) method.

```python
EstimatorResult(values=array([4.]), metadata=[{}])
```
</TabItem>
</Tabs>



This example only uses one [`qiskit.circuit.QuantumCircuit`](../api/qiskit/qiskit.circuit.QuantumCircuit) and one observable. If you want to get expectation values for multiple circuits and observables, you can pass a `list` of [`qiskit.circuit.QuantumCircuit`](../api/qiskit/qiskit.circuit.QuantumCircuit)s and a list of `BaseOperator`s to the [`qiskit.primitives.Estimator.run`](../api/qiskit/qiskit.primitives.Estimator#run) method. Both `list`s must have the same length.

#### Get the expected value

From these results you can extract the expected values with the attribute [`qiskit.primitives.EstimatorResult.values`](../api/qiskit/qiskit.primitives.EstimatorResult#values).

<Tabs>
<TabItem value="EstimatorV2" label="EstimatorV2">
```python
print(f" > Expectation value: {result[0].data.evs}")
print(f" > Metadata: {result[0].metadata}")
```
</TabItem>
<TabItem value="EstimatorV1" label="Estimator (V1)">
From these results you can extract the expected values with the attribute [`qiskit.primitives.EstimatorResult.values`](../api/qiskit/qiskit.primitives.EstimatorResult#values).

[`qiskit.primitives.EstimatorResult.values`](../api/qiskit/qiskit.primitives.EstimatorResult#values) returns a `numpy.ndarray`
whose `i`<sup>th</sup> element is the expectation value corresponding to the `i`<sup>th</sup> circuit and `i`<sup>th</sup> observable.
ElePT marked this conversation as resolved.
Show resolved Hide resolved

```python
```python
exp_value = result.values[0]
print(exp_value)
```

```python
3.999999999999999
```
</TabItem>
</Tabs>

### Parameterized circuit with `Estimator`

Expand Down
Loading