{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b37d5d91-e578-47fe-a8f3-e197ab2cec27",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from math import pi #Imports the mathematical constant pi.\n",
    "from qiskit import QuantumCircuit #Imports the class necessary to create a quantum circuit.\n",
    "theta = 0.75 #A constant representing some angle value, here set to 0.7."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b22c30c-ed62-4d39-9ef5-9ecc9f97e7f2",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc = QuantumCircuit(3, 2) #The variable that holds the quantum circuit object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c639600-6e61-4d26-9bd2-10ec72de9b5d",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc.x(2) #Applies an X gate (bit-flip) to the third qubit (index 2).\n",
    "qc.barrier() #Inserts a barrier to visually separate parts of the circuit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f87d53a8-8d28-4e10-8611-beb621feea95",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc.h(0) #Applies a Hadamard gate to the first qubit (index 0).\n",
    "qc.h(1) #Applies a Hadamard gate to the second qubit (index 1).\n",
    "qc.barrier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "494d8358-88f3-4afc-b039-9a6295cd8756",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc.cp(2 * pi * theta, 0, 2) #Applies a controlled-phase gate with angle 2 * pi * theta between qubit 0 and qubit 2.\n",
    "qc.cp(2 * pi * (2 * theta), 1, 2) #Applies a controlled-phase gate with angle 2 * pi * (2 * theta) between qubit 1 and qubit 2.\n",
    "qc.barrier()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4285f553-2b0f-4873-b8c6-a50f65719d5b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc.swap(0, 1) #Swaps qubit 0 with qubit 1.\n",
    "qc.h(0) #Applies a Hadamard gate to qubit 0.\n",
    "qc.cp(-pi / 2, 0, 1) #Applies a controlled-phase gate with angle -pi / 2 between qubit 0 and qubit 1.\n",
    "qc.h(1) #Applies a Hadamard gate to qubit 1.\n",
    "qc.barrier() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c4dbf3e-2215-4c1b-a326-e65ebc160531",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "qc.measure([0, 1], [0, 1]) #Measures qubits 0 and 1 and stores the results in classical bits 0 and 1."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6bb5073-6d15-40a8-96cd-7748bfc1e3bd",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "display(qc.draw(output='mpl', style='iqp')) # Draws the quantum circuit for visualization."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ec12810-7e7c-4ad2-b7f7-85b55ac47c17",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Import the necessary function to plot histograms\n",
    "from qiskit.visualization import plot_histogram\n",
    "from qiskit.primitives import Sampler\n",
    "\n",
    "# Execute the quantum circuit and obtain the results\n",
    "result = Sampler().run(qc).result()\n",
    "\n",
    "# Visualize the histogram of the quasi-probability distributions\n",
    "# Note: 'quasi_dists' might represent quasi-probability distributions obtained from the quantum circuit execution.\n",
    "display(plot_histogram(result.quasi_dists))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3febe91f-04fa-4bd0-bf38-93b324d675bb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Qiskit v1.0.2 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
