Skip to content

Commit

Permalink
Merge branch 'main' into fix/qr-typos
Browse files Browse the repository at this point in the history
  • Loading branch information
beckykd authored Jun 29, 2023
2 parents afe34e2 + 76a2a0e commit dd57407
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ There are several different options you can specify when calling the primitives.

### Sampler

This is a primitive that takes a list of user circuits as an input and generates an error-mitigated readout of quasi-probabilities. This provides users a way to better evaluate shot results using error mitigation and enables them to more efficiently evaluate the possibility of multiple relevant data points in the context of destructive interference.
This is a primitive that takes a list of user circuits as an input and generates an error-mitigated readout of quasi-probability distribution. This provides users a way to better evaluate shot results using error mitigation and enables them to more efficiently evaluate the possibility of multiple relevant data points in the context of destructive interference.

To invoke the `Sampler` primitive within a session:

Expand Down
28 changes: 15 additions & 13 deletions docs/primitives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ With Qiskit Runtime, we are introducing a new set of interfaces, in the form of

The existing Qiskit interface to backends (`backend.run()`) was originally designed to accept a list of circuits and return counts for every job. Over time, it became clear that users have diverse purposes for quantum computing, and therefore the ways in which they define the requirements for their computing jobs are expanding. Therefore, their results also look different.

For example, an algorithm researcher and developer cares about information beyond counts; they are more focused on efficiently calculating quasiprobabilities and expectation values of observables.
For example, an algorithm researcher and developer cares about information beyond counts; they are more focused on efficiently calculating quasi-probability distribution and expectation values of observables.

Our primitives provide methods that make it easier to build modular algorithms and other higher-order programs. Rather than simply returning counts, they return more immediately meaningful information. Additionally, they provide a seamless way to access the latest optimizations in IBM Quantum hardware and software.

Expand Down Expand Up @@ -40,18 +40,20 @@ The following primitives are available:
| | near-term quantum | |
| | algorithms. | |
+-----------------------+-----------------------+------------------------------------+
| Sampler | Generates | |
| | quasiprobability | |
| | distributions from | |
| | input circuits. | |
| | This enables the | |
| | return of error | |
| | mitigated samples, | |
| | enhancing the output | |
| | for sampling | |
| | algorithms | |
| | such as amplitude | |
| | amplification. | |
| Sampler | Allows a user to | .. image:: images/sampler.png |
| | input a circuit and | |
| | then generate | |
| | quasi-probability | |
| | distribution. | |
| | This generation | |
| | enables users to more | |
| | efficiently evaluate | |
| | the possibility of | |
| | multiple relevant | |
| | data points in the | |
| | context of | |
| | destructive | |
| | interference. | |
+-----------------------+-----------------------+------------------------------------+


Expand Down
16 changes: 9 additions & 7 deletions docs/tutorials/how-to-getting-started-with-estimator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"source": [
"The initial release of Qiskit Runtime includes two primitives:\n",
"\n",
"**Sampler:** Generates quasi-probabilities from input circuits.\n",
"**Sampler:** Generates quasi-probability distribution from input circuits.\n",
"\n",
"**Estimator:** Calculates expectation values from input circuits and observables."
]
Expand Down Expand Up @@ -1221,7 +1221,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {2: 0.50125, 0: 0.49875}\n",
">>> Quasi-probability distribution from the sampler job: {2: 0.50125, 0: 0.49875}\n",
">>> Expectation value from the estimator job: 0.8525\n"
]
}
Expand All @@ -1234,7 +1234,9 @@
" estimator = Estimator()\n",
"\n",
" result = sampler.run(sampler_circuit).result()\n",
" print(f\">>> Quasi Distribution from the sampler job: {result.quasi_dists[0]}\")\n",
" print(\n",
" f\">>> Quasi-probability distribution from the sampler job: {result.quasi_dists[0]}\"\n",
" )\n",
"\n",
" result = estimator.run(circuit, observable).result()\n",
" print(f\">>> Expectation value from the estimator job: {result.values[0]}\")"
Expand Down Expand Up @@ -1266,7 +1268,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {2: 0.49025, 0: 0.50975}\n",
">>> Quasi-probability distribution from the sampler job: {2: 0.49025, 0: 0.50975}\n",
">>> Expectation value from the estimator job: 0.8475\n"
]
}
Expand All @@ -1282,7 +1284,7 @@
" estimator_job = estimator.run(circuit, observable)\n",
"\n",
" print(\n",
" f\">>> Quasi Distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" f\">>> Quasi-probability distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" )\n",
" print(\n",
" f\">>> Expectation value from the estimator job: {estimator_job.result().values[0]}\"\n",
Expand Down Expand Up @@ -1327,7 +1329,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {0: 0.49575, 2: 0.50425}\n",
">>> Quasi-probability distribution from the sampler job: {0: 0.49575, 2: 0.50425}\n",
">>> Expectation value from the estimator job: 0.8315\n"
]
}
Expand Down Expand Up @@ -1362,7 +1364,7 @@
"\n",
" # 7. Get results\n",
" print(\n",
" f\">>> Quasi Distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" f\">>> Quasi-probability distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" )\n",
" print(\n",
" f\">>> Expectation value from the estimator job: {estimator_job.result().values[0]}\"\n",
Expand Down
55 changes: 31 additions & 24 deletions docs/tutorials/how-to-getting-started-with-sampler.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"source": [
"The initial release of Qiskit Runtime includes two primitives:\n",
"\n",
"**Sampler:** Generates quasi-probabilities from input circuits.\n",
"**Sampler:** Generates quasi-probability distribution from input circuits.\n",
"\n",
"**Estimator:** Calculates expectation values from input circuits and observables."
]
Expand Down Expand Up @@ -252,6 +252,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "1ce3cb48",
"metadata": {
Expand All @@ -260,7 +261,7 @@
}
},
"source": [
"The `result()` method of the job will return the `SamplerResult`, which includes both the quasi-distribution and job metadata. "
"The `result()` method of the job will return the `SamplerResult`, which includes both the quasi-probability distribution and job metadata. "
]
},
{
Expand All @@ -278,14 +279,14 @@
"output_type": "stream",
"text": [
">>> SamplerResult(quasi_dists=[{0: 0.4999999999999999, 1: 0.0, 2: 0.4999999999999998, 3: 0.0}], metadata=[{}])\n",
" > Quasi-distribution: {0: 0.4999999999999999, 1: 0.0, 2: 0.4999999999999998, 3: 0.0}\n"
" > Quasi-probability distribution: {0: 0.4999999999999999, 1: 0.0, 2: 0.4999999999999998, 3: 0.0}\n"
]
}
],
"source": [
"result = job.result()\n",
"print(f\">>> {result}\")\n",
"print(f\" > Quasi-distribution: {result.quasi_dists[0]}\")"
"print(f\" > Quasi-probability distribution: {result.quasi_dists[0]}\")"
]
},
{
Expand Down Expand Up @@ -324,7 +325,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi-distribution: {0: 0.9999999999999991, 1: 6.580329297619248e-33, 2: 0.0, 3: 0.0}\n"
">>> Quasi-probability distribution: {0: 0.9999999999999991, 1: 6.580329297619248e-33, 2: 0.0, 3: 0.0}\n"
]
}
],
Expand All @@ -335,7 +336,7 @@
"result = job.result()\n",
"\n",
"display(circuit.draw(\"mpl\"))\n",
"print(f\">>> Quasi-distribution: {result.quasi_dists[0]}\")"
"print(f\">>> Quasi-probability distribution: {result.quasi_dists[0]}\")"
]
},
{
Expand Down Expand Up @@ -384,7 +385,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi-distribution: [{0: 0.4999999999999999, 1: 0.0, 2: 0.4999999999999998, 3: 0.0}, {0: 0.9999999999999991, 1: 6.580329297619248e-33, 2: 0.0, 3: 0.0}]\n"
">>> Quasi-probability distribution: [{0: 0.4999999999999999, 1: 0.0, 2: 0.4999999999999998, 3: 0.0}, {0: 0.9999999999999991, 1: 6.580329297619248e-33, 2: 0.0, 3: 0.0}]\n"
]
}
],
Expand All @@ -398,7 +399,7 @@
"result = job.result()\n",
"\n",
"[display(cir.draw(\"mpl\")) for cir in circuits]\n",
"print(f\">>> Quasi-distribution: {result.quasi_dists}\")"
"print(f\">>> Quasi-probability distribution: {result.quasi_dists}\")"
]
},
{
Expand Down Expand Up @@ -438,7 +439,7 @@
"output_type": "stream",
"text": [
">>> Parameter values: [0, 1, 2, 3, 4, 5]\n",
">>> Quasi-distribution: {0: 0.17158451004815306, 1: 0.0041370682135240654, 2: 0.20402129418492707, 3: 0.6202571275533961}\n"
">>> Quasi-probability distribution: {0: 0.17158451004815306, 1: 0.0041370682135240654, 2: 0.20402129418492707, 3: 0.6202571275533961}\n"
]
}
],
Expand All @@ -454,7 +455,7 @@
"\n",
"display(circuit.draw(\"mpl\"))\n",
"print(f\">>> Parameter values: {parameter_values}\")\n",
"print(f\">>> Quasi-distribution: {result.quasi_dists[0]}\")"
"print(f\">>> Quasi-probability distribution: {result.quasi_dists[0]}\")"
]
},
{
Expand Down Expand Up @@ -683,15 +684,15 @@
"output_type": "stream",
"text": [
">>> SamplerResult(quasi_dists=[{2: 0.49275, 0: 0.50725}], metadata=[{'header_metadata': {}, 'shots': 4000}])\n",
" > Quasi-distribution: {2: 0.49275, 0: 0.50725}\n",
" > Quasi-probability distribution: {2: 0.49275, 0: 0.50725}\n",
" > Metadata: {'header_metadata': {}, 'shots': 4000}\n"
]
}
],
"source": [
"result = job.result()\n",
"print(f\">>> {result}\")\n",
"print(f\" > Quasi-distribution: {result.quasi_dists[0]}\")\n",
"print(f\" > Quasi-probability distribution: {result.quasi_dists[0]}\")\n",
"print(f\" > Metadata: {result.metadata[0]}\")"
]
},
Expand Down Expand Up @@ -924,15 +925,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi-distribution: {0: 0.50175, 2: 0.49825}\n",
">>> Quasi-probability distribution: {0: 0.50175, 2: 0.49825}\n",
">>> Metadata: {'header_metadata': {}, 'shots': 4000, 'readout_mitigation_overhead': 1.0, 'readout_mitigation_time': 0.04642554186284542}\n"
]
}
],
"source": [
"sampler = Sampler(backend=backend, options=options)\n",
"result = sampler.run(circuit).result()\n",
"print(f\">>> Quasi-distribution: {result.quasi_dists[0]}\")\n",
"print(f\">>> Quasi-probability distribution: {result.quasi_dists[0]}\")\n",
"print(f\">>> Metadata: {result.metadata[0]}\")"
]
},
Expand Down Expand Up @@ -1041,8 +1042,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi-distribution from the first run: {0: 0.498, 2: 0.502}\n",
">>> Quasi-distribution from the second run: {0: 0.498, 2: 0.502}\n"
">>> Quasi-probability distribution from the first run: {0: 0.498, 2: 0.502}\n",
">>> Quasi-probability distribution from the second run: {0: 0.498, 2: 0.502}\n"
]
}
],
Expand All @@ -1053,10 +1054,14 @@
" sampler = Sampler()\n",
"\n",
" result = sampler.run(circuit).result()\n",
" print(f\">>> Quasi-distribution from the first run: {result.quasi_dists[0]}\")\n",
" print(\n",
" f\">>> Quasi-probability distribution from the first run: {result.quasi_dists[0]}\"\n",
" )\n",
"\n",
" result = sampler.run(circuit).result()\n",
" print(f\">>> Quasi-distribution from the second run: {result.quasi_dists[0]}\")"
" print(\n",
" f\">>> Quasi-probability distribution from the second run: {result.quasi_dists[0]}\"\n",
" )"
]
},
{
Expand Down Expand Up @@ -1160,7 +1165,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {2: 0.50025, 0: 0.49975}\n",
">>> Quasi-probability distribution from the sampler job: {2: 0.50025, 0: 0.49975}\n",
">>> Expectation value from the estimator job: 0.848\n"
]
}
Expand All @@ -1173,7 +1178,9 @@
" estimator = Estimator()\n",
"\n",
" result = sampler.run(circuit).result()\n",
" print(f\">>> Quasi Distribution from the sampler job: {result.quasi_dists[0]}\")\n",
" print(\n",
" f\">>> Quasi-probability distribution from the sampler job: {result.quasi_dists[0]}\"\n",
" )\n",
"\n",
" result = estimator.run(estimator_circuit, observable).result()\n",
" print(f\">>> Expectation value from the estimator job: {result.values[0]}\")"
Expand Down Expand Up @@ -1205,7 +1212,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {2: 0.508, 0: 0.492}\n",
">>> Quasi-probability distribution from the sampler job: {2: 0.508, 0: 0.492}\n",
">>> Expectation value from the estimator job: 0.8495\n"
]
}
Expand All @@ -1221,7 +1228,7 @@
" estimator_job = estimator.run(estimator_circuit, observable)\n",
"\n",
" print(\n",
" f\">>> Quasi Distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" f\">>> Quasi-probability distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" )\n",
" print(\n",
" f\">>> Expectation value from the estimator job: {estimator_job.result().values[0]}\"\n",
Expand Down Expand Up @@ -1266,7 +1273,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
">>> Quasi Distribution from the sampler job: {0: 0.50125, 2: 0.49875}\n",
">>> Quasi-probability distribution from the sampler job: {0: 0.50125, 2: 0.49875}\n",
">>> Expectation value from the estimator job: 0.8475\n"
]
}
Expand Down Expand Up @@ -1301,7 +1308,7 @@
"\n",
" # 7. Get results\n",
" print(\n",
" f\">>> Quasi Distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" f\">>> Quasi-probability distribution from the sampler job: {sampler_job.result().quasi_dists[0]}\"\n",
" )\n",
" print(\n",
" f\">>> Expectation value from the estimator job: {estimator_job.result().values[0]}\"\n",
Expand Down
2 changes: 1 addition & 1 deletion qiskit_ibm_runtime/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
class Sampler(BasePrimitive, BaseSampler):
"""Class for interacting with Qiskit Runtime Sampler primitive service.
Qiskit Runtime Sampler primitive service calculates probabilities or quasi-probabilities
Qiskit Runtime Sampler primitive service calculates quasi-probability distribution
of bitstrings from quantum circuits.
The :meth:`run` method can be used to submit circuits and parameters to the Sampler primitive.
Expand Down
8 changes: 5 additions & 3 deletions qiskit_ibm_runtime/utils/runner_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def get_quasiprobabilities(
"""Get quasiprobabilites associated with one or more experiments.
Parameters:
experiment: Indices of experiments to grab quasiprobabilities from.
experiment: Indices of experiments to grab quasi-probability distribution from.
Returns:
A single distribution or a list of distributions.
Raises:
QiskitError: If experiment result doesn't contain quasiprobabilities.
QiskitError: If experiment result doesn't contain quasi-probability distribution.
"""
if experiment is None:
exp_keys = range(len(self.results))
Expand All @@ -64,7 +64,9 @@ def get_quasiprobabilities(
dict_list.append(out)
else:
raise QiskitError(
'No quasiprobabilities for experiment "{}"'.format(repr(key))
'No quasi-probability distribution for experiment "{}"'.format(
repr(key)
)
)

# Return first item of dict_list if size is 1
Expand Down

0 comments on commit dd57407

Please sign in to comment.