Skip to content

Commit

Permalink
Notebook documentation more organized
Browse files Browse the repository at this point in the history
  • Loading branch information
andresbar98 committed Oct 29, 2023
1 parent e5ab232 commit 4e8d855
Showing 1 changed file with 45 additions and 22 deletions.
67 changes: 45 additions & 22 deletions docs/source/Primitives.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@
"outputs": [],
"source": [
"# Initialize sampler\n",
"sampler = Sampler()\n",
"\n",
"# Submit job\n",
"# For the \"run\" method:\n",
"# The first argument is the circuit to simulate.\n",
"# Second argument contains the parameter values, if needed.\n",
"# The number of shots can be set as an additional argument. If not, the default value is 1024.\n",
"sampler = Sampler()"
]
},
{
"cell_type": "markdown",
"id": "b7578f41",
"metadata": {},
"source": [
"The first argument in the `run` method is the circuit to simulate. The second argument contains the parameter values, if needed. The number of shots can be set as an additional argument. If not, the default value is 1024."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed6c0970",
"metadata": {},
"outputs": [],
"source": [
"job = sampler.run(circ, np.pi, shots=int(1e4))\n",
"result = job.result()"
]
Expand Down Expand Up @@ -120,10 +131,24 @@
"# Create a second circuit\n",
"circ_2 = QuantumCircuit(1)\n",
"circ_2.measure_all()\n",
"\n",
"# Initialize sampler\n",
"# Introduce the circuits and parameter values for each circuit as a sequence\n",
"\n",
"circ_2.draw(\"mpl\")"
]
},
{
"cell_type": "markdown",
"id": "fc067206",
"metadata": {},
"source": [
"In this case, both the circuits and the parameter values must be entered as a `Sequence`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f0b78a6",
"metadata": {},
"outputs": [],
"source": [
"job = sampler.run((circ, circ_2), [[np.pi], []], shots=int(1e4))\n",
"result = job.result()\n",
"\n",
Expand Down Expand Up @@ -221,30 +246,28 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da2de10a",
"cell_type": "markdown",
"id": "b58fce88",
"metadata": {},
"outputs": [],
"source": [
"# Use the Sampler to get the probability distribution of the circuit\n",
"\n",
"dist = sampler.run(qc, shots=int(1e4)).result().quasi_dists[0]\n",
"plot_distribution(dist.binary_probabilities())"
"After having built the circuit, use the `Sampler` to get the probability distribution."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f22b51e2",
"id": "da2de10a",
"metadata": {},
"outputs": [],
"source": []
"source": [
"dist = sampler.run(qc, shots=int(1e4)).result().quasi_dists[0]\n",
"plot_distribution(dist.binary_probabilities())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "My Virtual Environment",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "venv"
},
Expand Down

0 comments on commit 4e8d855

Please sign in to comment.